"use strict";(self.webpackChunklernplattform_frontend=self.webpackChunklernplattform_frontend||[]).push([[52773],{85554:function(e,t,i){i.d(t,{B:function(){return y}});var n,s,o,r=i("aurelia-framework"),a=i("common/aurelia-components/x-icon/x-icon"),c=i(729769),u=i(218046),d=i(950496),l=i(795093),f=i.n(l),S=i("resources/elements/global-dialog/global-dialog"),p=i(660173),v=i(604901),h=i(720890),g=i(813735),m=function(e,t,i,n){return new(i||(i=Promise))((function(s,o){function r(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}c((n=n.apply(e,t||[])).next())}))};let y=class{constructor(e,t,i){this.coursePointsApiService=e,this.storeService=t,this.courseService=i,this.MAX_STREAK_IN_DAYS=5}updateRedeemablePoints(e){return m(this,void 0,void 0,(function*(){const t=yield this.coursePointsApiService.getUnredeemedPoints(e);yield this.openRedeemPointsDialog(t,e)}))}openRedeemPointsDialog(e,t){var i,n,s,o;return m(this,void 0,void 0,(function*(){const r=this.getLatestPointRecord(e);if(!r)return;const c=null!==(n=null===(i=r.streakInfo)||void 0===i?void 0:i.duration)&&void 0!==n?n:0,d=yield this.storeService.getState(),l=null===(s=d.courses)||void 0===s?void 0:s.find((e=>e.accessCodeId===t)),f=(null==l?void 0:l.ratingStatus)===u.RatingStatus.NotRated&&(null===(o=r.streakInfo)||void 0===o?void 0:o.duration)===this.MAX_STREAK_IN_DAYS,h=yield new Promise((e=>S.GlobalDialog.open(new v.SimpleDialog({header:{titleTk:"resources.services.redeemPointsService.redeemablePointsHeaderTitle",titleTkParams:{points:r.points},icon:{size:a.IconSize.unspecified,type:a.IconType.custom,name:"LectureQuiz/PartyCannon"}},title:{titleTk:"resources.services.redeemPointsService.redeemablePointsTitle",titleTkParams:{count:c}},descriptions:[{textTk:c>this.MAX_STREAK_IN_DAYS?"resources.services.redeemPointsService.redeemablePointsDescriptionMaxStreak":"resources.services.redeemPointsService.redeemablePointsDescription"},...f?[{textTk:"resources.elements.requestRatingDialog.rateCourseDescription"}]:[]],confirmCheckboxTk:f?"resources.elements.requestRatingDialog.stopRequesting":void 0,buttons:[...f?[{buttonTextTk:"resources.elements.requestRatingDialog.rateCourse",buttonCallback:({checkboxChecked:t})=>m(this,void 0,void 0,(function*(){S.GlobalDialog.close(),e({stopAsking:t,wantsToRate:!0})}))}]:[],{buttonTextTk:f?"general.continue":"general.confirm",buttonCallback:({checkboxChecked:t})=>m(this,void 0,void 0,(function*(){S.GlobalDialog.close(),e({stopAsking:t,wantsToRate:!1})}))}]}))));yield this.redeemPoints(e,t),l&&(h.stopAsking&&this.courseService.markCourseWontRate(l.id),h.wantsToRate&&p.RateCourseDialog.show({courseId:l.id}))}))}redeemPoints(e,t){return m(this,void 0,void 0,(function*(){for(const i of e)i.reason===d.PointAwardReason.ActivityStreak&&(yield this.coursePointsApiService.redeemPoints(t,i.id))}))}getLatestPointRecord(e){var t;return null!==(t=e.sort(((e,t)=>{var i,n;return f()().diff(null===(i=e.streakInfo)||void 0===i?void 0:i.endedAt)-f()().diff(null===(n=t.streakInfo)||void 0===n?void 0:n.endedAt)})).find((e=>e.reason===d.PointAwardReason.ActivityStreak)))&&void 0!==t?t:null}};y=function(e,t,i,n){var s,o=arguments.length,r=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(r=(o<3?s(r):o>3?s(t,i,r):s(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r}([r.autoinject,function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",["function"==typeof(n=void 0!==h.CoursePointsApiService&&h.CoursePointsApiService)?n:Object,"function"==typeof(s=void 0!==c.StoreService&&c.StoreService)?s:Object,"function"==typeof(o=void 0!==g.CourseService&&g.CourseService)?o:Object])],y)},123448:function(e,t,i){var n,s=this&&this.__decorate||function(e,t,i,n){var s,o=arguments.length,r=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(r=(o<3?s(r):o>3?s(t,i,r):s(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.RoadSignScannerService=void 0;const o=i("aurelia-framework"),r=i(227270),a=i(283616),c=i(331788);let u=n=class{async scan(){const e=window.scannervz;(0,a.assertNotNullOrUndefined)(e,"scanner is not available");const t=this.retrieveShowWarningDialogFlag();if(r.AppUtils.isMobileApp){const{permissions:e}=window.cordova.plugins;await new Promise((t=>{e.requestPermissions([e.CAMERA],t,t)}))}return r.AppUtils.isAndroidApp&&t&&await c.ScannerWarningDialog.prompt(),new Promise(((i,s)=>e.classify(n.THRESHOLD,n.SKIP_FRAMES,n.MIN_ITERATIONS,n.EXPIRATION,t,i,s)))}retrieveShowWarningDialogFlag(){const e=localStorage.getItem(n.SHOW_WARNING_DIALOG_STORAGE_KEY),t=null==e||"true"===e;return localStorage.setItem(n.SHOW_WARNING_DIALOG_STORAGE_KEY,"false"),t}};u.THRESHOLD=.97,u.SKIP_FRAMES=24,u.MIN_ITERATIONS=3,u.EXPIRATION=30,u.SHOW_WARNING_DIALOG_STORAGE_KEY="scannerShowWarningDialog",u=n=s([(0,o.autoinject)()],u),t.RoadSignScannerService=u},652921:function(e,t,i){var n,s,o,r=this&&this.__decorate||function(e,t,i,n){var s,o=arguments.length,r=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(s=e[a])&&(r=(o<3?s(r):o>3?s(t,i,r):s(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r},a=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.TrainingService=void 0;const u=i("aurelia-framework"),d=i("aurelia-store"),l=i(729769),f=i(556828),S=i(224554),p=i(341592),v=i(238006),h=i(74221),g=i(640156),m=i(283616),y=i(919477),A=c(i(795093)),T=i(13245),C=i(965631),I=i(53869),R=i(993718);let b=class{constructor(e,t,i){this.store=e,this.storeService=t,this.learnGoalService=i,this.state=null,this.accessCodeCourseForCurrentAccessCodeIdSelector=(0,C.accessCodeCourseForCurrentAccessCodeIdSelectorCreator)(),this.courseContentByAccessCodeIdSelector=(0,C.courseContentByAccessCodeIdSelectorCreator)(),this.storeService.subscribe(this,(e=>{this.state=e}))}async startTrainingSession(e,t,i,n,s=!0){var o;(0,m.assertNotNullOrUndefined)(this.state,"no state set");const r=this.accessCodeCourseForCurrentAccessCodeIdSelector(this.state,{});(0,m.assertNotNullOrUndefined)(r,"no current course set");const a=this.courseContentByAccessCodeIdSelector(this.state,{accessCodeId:r.accessCodeId});(0,m.assertNotNullOrUndefined)(a,"course not found");const c=n&&new Set(n),u=v.CourseUtils.getRootChapterIdsByPageId(a),d=a.questions.filter((e=>{var n;return!e.learningOnly&&(!s||null==e.parentQuestionId)&&(!t||e.pageId&&t.includes(u[e.pageId]))&&(!c||c.has(e.id))&&(!(null===(n=i.difficulties)||void 0===n?void 0:n.length)||i.difficulties.includes(e.points))}));if(s){const{subQuestionsByQuestionId:e}=h.QuestionUtils.getMainQuestionsAndSubQuestions(a.questions);d.push(...d.map((t=>e[t.id])).filter(y.isNotNullish))}const l=await this.getCompareFunctionForTrainingSession(e,d,r.accessCodeId),p=g.ShuffleUtils.getRandomSeed();await this.store.dispatch(I.newInternalTrainingSession,{accessCodeId:r.accessCodeId,type:e,questions:this.sortQuestions(d,l,p),chapters:t,lastSeenQuestionIndex:-1,secondsToTrain:f.MAX_TRAIN_TIME_IN_SECONDS,difficulties:i.difficulties,timeStarted:Date.now(),timeFinished:null,state:T.TrainingSessionState.Running,examType:null!==(o=a.examType)&&void 0!==o?o:S.ExamType.Default,baseSeed:p},!0)}async endTrainingSession(){const e=this.ensureCurrentTrainingSession();e.timeFinished&&e.state===T.TrainingSessionState.Finished||await this.store.dispatch(I.updateTrainingSession,e.id,{state:T.TrainingSessionState.Finished,timeFinished:Date.now()})}async destroyTrainingSession(){await this.store.dispatch(I.clearTrainingSession)}async answerQuestion(e,t){const i=this.ensureCurrentTrainingSession(),n=i.questions.find((t=>t.questionId===e));(0,m.assertNotNullOrUndefined)(n,"question not found");const s=h.QuestionUtils.getUpdatedAnswersFromSelectedAnswerArray(n,t),o=h.QuestionUtils.checkAnswers(s);await this.store.dispatch(I.updateTrainingQuestion,i.id,e,{isCorrect:o,isAnswered:!0,answers:s})}async markQuestionSeen(e){const t=this.ensureCurrentTrainingSession();await this.store.pipe(I.updateTrainingSession,t.id,{secondsToTrain:f.MAX_TRAIN_TIME_IN_SECONDS}).pipe(I.updateTrainingSessionLastSeenQuestion,t.id,e).dispatch()}async markQuestions(e,t){var i,n,s;const o=null!==(s=null===(n=null===(i=this.state)||void 0===i?void 0:i.markedQuestionsByAccessCodeId)||void 0===n?void 0:n[t])&&void 0!==s?s:{},r=e.filter((e=>!h.QuestionUtils.isQuestionMarked(o,e))).map((e=>{var t;return null!==(t=e.parentQuestionId)&&void 0!==t?t:e.questionId}));r.length&&await this.store.dispatch(I.setQuestionsMarked,t,r,!0)}ensureCurrentTrainingSession(){const e=this.state&&(0,I.getCurrentTrainingSession)(this.state);return(0,m.assertNotNullOrUndefined)(e,"no active training session"),e}sortQuestions(e,t,i){const{mainQuestions:n,subQuestionsByQuestionId:s}=h.QuestionUtils.getMainQuestionsAndSubQuestions(e),o=p.ArrayUtils.shuffle(n).sort(t),r=[];for(let e=0;e<o.length;e++){const t=o[e];r.push(t);const i=s[t.id];i&&r.push(i)}return r.map((e=>{const t=i?g.ShuffleUtils.getSeedFromBaseSeed(i,e.id):null;return h.QuestionUtils.quizQuestionFromQuestion(e,!0,t)}))}async getCompareFunctionForTrainingSession(e,t,i){const n=await this.learnGoalService.getSpacedRepetitionState(i);if(e===S.TrainingSessionType.SpacedRepetition){const e=p.ArrayUtils.toRecord(t,(e=>e.id),(e=>{var t;return(0,A.default)((null===(t=n[e.id])||void 0===t?void 0:t.nextDueDate)||0).endOf("day").valueOf()}));return(t,i)=>e[t.id]-e[i.id]}{const{mainQuestions:e,subQuestionsByQuestionId:i}=h.QuestionUtils.getMainQuestionsAndSubQuestions(t),s=p.ArrayUtils.toRecord(e,(e=>e.id),(e=>{const t=i[e.id],s=this.getCorrectAnswerCount(n,e.id);return t?Math.min(s,this.getCorrectAnswerCount(n,t.id)):s}));return(e,t)=>s[e.id]-s[t.id]}}getCorrectAnswerCount(e,t){var i,n;return null!==(n=null===(i=e[t])||void 0===i?void 0:i.answerHistory.filter((e=>e.correct)).length)&&void 0!==n?n:0}};b=r([(0,u.autoinject)(),a("design:paramtypes",["function"==typeof(n=void 0!==d.Store&&d.Store)?n:Object,"function"==typeof(s=void 0!==l.StoreService&&l.StoreService)?s:Object,"function"==typeof(o=void 0!==R.LearnGoalService&&R.LearnGoalService)?o:Object])],b),t.TrainingService=b}}]);