| 1 |
(()=>{var e={345(e,t,s){"use strict";s.d(t,{f:()=>p});var i=s(4223),n=s(2603),o=s(8465),a=s.n(o),r=s(246);const l="edit-question";let c,d,u,h;class p{static selectors={elEditQuestionWrap:".lp-edit-question-wrap",elQuestionEditMain:".lp-question-edit-main",elQuestionToggleAll:".lp-question-toggle-all",elEditListQuestions:".lp-edit-list-questions",elQuestionToggle:".lp-question-toggle",elBtnShowPopupItemsToSelect:".lp-btn-show-popup-items-to-select",elPopupItemsToSelectClone:".lp-popup-items-to-select.clone",elBtnAddQuestion:".lp-btn-add-question",elBtnRemoveQuestion:".lp-btn-remove-question",elBtnUpdateQuestionTitle:".lp-btn-update-question-title",elBtnUpdateQuestionDes:".lp-btn-update-question-des",elBtnUpdateQuestionHint:".lp-btn-update-question-hint",elBtnUpdateQuestionExplain:".lp-btn-update-question-explanation",elQuestionTitleNewInput:".lp-question-title-new-input",elQuestionTitleInput:".lp-question-title-input",elQuestionTypeLabel:".lp-question-type-label",elQuestionTypeNew:".lp-question-type-new",elAddNewQuestion:"add-new-question",elQuestionClone:".lp-question-item.clone",elAnswersConfig:".lp-answers-config",elBtnAddAnswer:".lp-btn-add-question-answer",elQuestionAnswerItemAddNew:".lp-question-answer-item-add-new",elQuestionAnswerTitleNewInput:".lp-question-answer-title-new-input",elQuestionAnswerTitleInput:".lp-question-answer-title-input",elBtnDeleteAnswer:".lp-btn-delete-question-answer",elQuestionByType:".lp-question-by-type",elInputAnswerSetTrue:".lp-input-answer-set-true",elQuestionAnswerItem:".lp-question-answer-item",elBtnUpdateQuestionAnswer:".lp-btn-update-question-answer",elBtnFibInsertBlank:".lp-btn-fib-insert-blank",elBtnFibDeleteAllBlanks:".lp-btn-fib-delete-all-blanks",elBtnFibSaveContent:".lp-btn-fib-save-content",elBtnFibClearAllContent:".lp-btn-fib-clear-all-content",elFibOptionTitleInput:".lp-question-fib-option-title-input",elFibBlankOptions:".lp-question-fib-blank-options",elFibBlankOptionItem:".lp-question-fib-blank-option-item",elFibBlankOptionItemClone:".lp-question-fib-blank-option-item.clone",elFibBlankOptionIndex:".lp-question-fib-option-index",elBtnFibOptionDelete:".lp-btn-fib-option-delete",elFibOptionMatchCaseWrap:".lp-question-fib-option-match-case-wrap",elFibOptionMatchCaseInput:".lp-question-fib-option-match-case-input",elQuestionFibOptionDetail:".lp-question-fib-option-detail",elFibOptionComparisonInput:".lp-question-fib-option-comparison-input",elAutoSaveFib:".lp-auto-save-fib",LPTarget:".lp-target",elCollapse:"lp-collapse",elSectionToggle:".lp-section-toggle",elTriggerToggle:".lp-trigger-toggle",elAutoSaveQuestion:".lp-auto-save-question",elAutoSaveAnswer:".lp-auto-save-question-answer",elQuestionFibInput:"lp-question-fib-input",elBtnQuestionCreateType:".lp-btn-question-create-type"};constructor(){}init(){this.events(),this.initTinyMCE().then()}events(){p._loadedEvents||(p._loadedEvents=!0,document.querySelectorAll(`${p.selectors.elQuestionEditMain}`).forEach(e=>{this.sortAbleQuestionAnswer(e)}),i.eventHandlers("click",[{selector:p.selectors.elBtnQuestionCreateType,callBack:this.createQuestionType.name,class:this},{selector:p.selectors.elBtnAddAnswer,callBack:this.addQuestionAnswer.name,class:this},{selector:p.selectors.elBtnDeleteAnswer,callBack:this.deleteQuestionAnswer.name,class:this},{selector:p.selectors.elBtnFibInsertBlank,callBack:this.fibInsertBlank.name,class:this},{selector:p.selectors.elBtnFibDeleteAllBlanks,callBack:this.fibDeleteAllBlanks.name,class:this},{selector:p.selectors.elBtnFibSaveContent,callBack:this.fibSaveContent.name,class:this},{selector:p.selectors.elBtnFibClearAllContent,callBack:this.fibClearContent.name,class:this},{selector:p.selectors.elBtnFibOptionDelete,callBack:this.fibDeleteBlank.name,class:this},{selector:p.selectors.elFibOptionMatchCaseInput,callBack:this.fibShowHideMatchCaseOption.name,class:this},{selector:p.selectors.elFibOptionComparisonInput,callBack:e=>{const{e:t,target:s}=e;s.closest(`${p.selectors.elQuestionEditMain}`).querySelector(`${p.selectors.elBtnFibSaveContent}`).click()}}]),document.addEventListener("click",e=>{const t=e.target;i.toggleCollapse(e,t,p.selectors.elTriggerToggle)}),i.eventHandlers("keyup",[{selector:p.selectors.elQuestionAnswerTitleNewInput,callBack:this.checkCanAddAnswer.name,class:this},{selector:p.selectors.elFibOptionTitleInput,callBack:this.fibOptionTitleInputChange.name,class:this},{selector:p.selectors.elAutoSaveQuestion,callBack:this.autoUpdateQuestion.name,class:this}]),i.eventHandlers("keydown",[{selector:p.selectors.elQuestionAnswerTitleNewInput,callBack:this.addQuestionAnswer.name,class:this,checkIsEventEnter:!0}]),i.eventHandlers("change",[{selector:p.selectors.elAutoSaveAnswer,callBack:this.autoUpdateAnswer.name,class:this}]),this.eventEditorTinymce())}async initTinyMCE(){document.querySelectorAll(".lp-editor-tinymce").forEach(e=>{const t=e.id;this.reInitTinymce(t)})}reInitTinymce(e){if(!window.tinymce||!e)return;const t=document.getElementById(e);if(!t)return;this.reInitQuicktags(e);const s=window.tinymce.get(e),i=s?.getContainer?.();s&&(s.targetElm===t||s.getElement?.()===t||i?.contains(t))||(window.tinymce.execCommand("mceRemoveEditor",!0,e),window.tinymce.execCommand("mceAddEditor",!0,e)),this.setDefaultEditorTab(e)}reInitQuicktags(e){const t=document.getElementById(`qt_${e}_toolbar`);if(!t||t.children.length||!window.quicktags)return;const s=window.tinyMCEPreInit?.qtInit?.[e]||{id:e};window.quicktags(s),window.QTags?._buttonsInit&&window.QTags._buttonsInit()}setDefaultEditorTab(e){const t=document.getElementById(`wp-${e}-wrap`);if(!t)return;t.classList.contains("html-active")&&window.switchEditors?.go&&window.switchEditors.go(e,"tmce"),t.classList.add("tmce-active"),t.classList.remove("html-active");const s=document.getElementById(`${e}-tmce`),i=document.getElementById(`${e}-html`);s?.setAttribute("aria-pressed","true"),i?.setAttribute("aria-pressed","false")}eventEditorTinymce(){window.tinymce.on("AddEditor",e=>{const t=e.editor.id,s=window.tinymce.get(t);if(!s)return;if("content"===t)return;this.setDefaultEditorTab(t);const n=document.getElementById(t);if(!n)return;const o=n.closest(`${p.selectors.elQuestionEditMain}`);o&&(o.dataset.questionId,s.settings.force_p_newlines=!1,s.settings.forced_root_block="",s.settings.force_br_newlines=!0,s.settings.relative_urls=!1,s.settings.remove_script_host=!1,s.settings.convert_urls=!0,s.settings.document_base_url=lpData.site_url,s.on("change keyup",e=>{n.value=s.getContent(),this.autoUpdateQuestion({e,target:n})}),s.on("blur",e=>{}),s.on("focusin",e=>{}),s.on("init",()=>{s.dom.addStyle(`\n\t\t\t\tbody {\n\t\t\t\t\tline-height: 2.2 !important;\n\t\t\t\t}\n\t\t\t\t.${p.selectors.elQuestionFibInput} {\n\t\t\t\t\tborder: 1px dashed rebeccapurple;\n\t\t\t\t\tpadding: 5px;\n\t\t\t\t}\n\t\t\t`)}),s.on("setcontent",e=>{const t=this.randomString(),i=s.dom.select(`.${p.selectors.elQuestionFibInput}[data-id="${t}"]`);i[0]&&i[0].focus(),s.dom.bind(i[0],"input",e=>{})}),s.on("selectionchange",e=>{if(c=s.selection,c.getNode().classList.contains(`${p.selectors.elQuestionFibInput}`)){const e=c.getNode().dataset.id,n=c.getNode().textContent.trim();if(0===n.length){const t=s.id.replace(`${p.selectors.elQuestionFibInput}-`,""),n=document.querySelector(`${p.selectors.elQuestionEditMain}[data-question-id="${t}"]`).querySelector(`${p.selectors.elFibBlankOptions}`).querySelector(`${p.selectors.elFibBlankOptionItem}[data-id="${e}"]`);n&&i.lpShowHideEl(n,0)}else{const s=document.getElementById(t).closest(`${p.selectors.elAnswersConfig}`).querySelector(`${p.selectors.elFibBlankOptionItem}[data-id="${e}"]`);if(s){const e=s.querySelector(`${p.selectors.elFibOptionTitleInput}`);e&&(e.value=n)}}}}),s.on("Undo",e=>{s.getContent();const t=s.selection.getNode();if(t.classList.contains(`${p.selectors.elQuestionFibInput}`)){const e=t.dataset.id,s=document.querySelector(`${p.selectors.elFibBlankOptionItem}[data-id="${e}"]`);s&&i.lpShowHideEl(s,1)}}),s.on("Redo",e=>{}))})}autoUpdateQuestion(e){let{e:t,target:s,key:i,value:o}=e;const a=s.closest(`${p.selectors.elAutoSaveQuestion}`);if(!a)return;const r=a.closest(`${p.selectors.elQuestionEditMain}`).dataset.questionId;clearTimeout(h),h=setTimeout(()=>{const e={success:e=>{const{message:t,status:s}=e;if("success"!==s)throw`Error: ${t}`;n.W(t,s)},error:e=>{n.W(e,"error")},completed:()=>{}},t={action:"update_question",question_id:r,args:{id_url:l}};if(void 0===i){if(i=a.dataset.keyAutoSave,!i){if(!a.classList.contains("lp-editor-tinymce"))return;const e=a.id;if(i=e.replace(/lp-/g,"").replace(`-${r}`,"").replace(/-/g,"_"),!i)return}o=a.value}t[i]=o,window.lpAJAXG.fetchAJAX(t,e)},700)}createQuestionType(e){const{e:t,target:s}=e,i=s.closest(`${p.selectors.elBtnQuestionCreateType}`);if(!i)return;const o=i.closest(`${p.selectors.elQuestionEditMain}`);if(!o)return;const a=o.dataset.questionId,r=o.querySelector(`${p.selectors.elQuestionTypeNew}`);if(!r)return;const c=r.value.trim();if(!c){const e=r.dataset.messEmptyType;return void n.W(e,"error")}const d={success:e=>{const{message:t,status:s,data:i}=e;if("success"!==s)throw`Error: ${t}`;{const{html_option_answers:e}=i;o.querySelector(`${p.selectors.elAnswersConfig}`).outerHTML=e,this.initTinyMCE(),this.sortAbleQuestionAnswer(o),n.W(t,s)}},error:e=>{n.W(e,"error")},completed:()=>{}},u={action:"update_question",question_id:a,question_type:c,args:{id_url:l}};window.lpAJAXG.fetchAJAX(u,d)}addQuestionAnswer(e){const{e:t,target:s}=e,o=s.closest(`${p.selectors.elQuestionAnswerItemAddNew}`);if(!o)return;t.preventDefault();const a=o.querySelector(`${p.selectors.elQuestionAnswerTitleNewInput}`);if(!a.value.trim()){const e=a.dataset.messEmptyTitle;return void n.W(e,"error")}const r=s.closest(`${p.selectors.elQuestionEditMain}`),c=r.querySelector(`${p.selectors.elQuestionAnswerItem}.clone`),d=c.cloneNode(!0),u=d.querySelector(`${p.selectors.elQuestionAnswerTitleInput}`);d.classList.remove("clone"),i.lpShowHideEl(d,1),i.lpSetLoadingEl(d,1),c.insertAdjacentElement("beforebegin",d);const h=a.value.trim();u.value=h,a.value="";const m={success:e=>{const{message:t,status:s,data:o}=e;if("success"!==s)throw`Error: ${t}`;{const{question_answer:e}=o;d.dataset.answerId=e.question_answer_id,i.lpSetLoadingEl(d,0);const t=this.getDataAnswersConfig(r);t.push(e),this.setDataAnswersConfig(r,t)}n.W(t,s)},error:e=>{d.remove(),n.W(e,"error")},completed:()=>{}},g={action:"add_question_answer",question_id:r.dataset.questionId,answer_title:h,args:{id_url:l}};window.lpAJAXG.fetchAJAX(g,m)}checkCanAddAnswer(e){const{e:t,target:s}=e,i=s.closest(p.selectors.elQuestionAnswerTitleNewInput);if(!i)return;const n=i.closest(`${p.selectors.elQuestionAnswerItemAddNew}`);if(!n)return;const o=n.querySelector(`${p.selectors.elBtnAddAnswer}`);o&&(i.value.trim()?o.classList.add("active"):o.classList.remove("active"))}autoUpdateAnswer(e){const{e:t,target:s}=e,o=s.closest(`${p.selectors.elAutoSaveAnswer}`);if(!o)return;const a=o.closest(`${p.selectors.elQuestionAnswerItem}`);clearTimeout(d),d=setTimeout(()=>{const e=o.closest(`${p.selectors.elQuestionEditMain}`),t=e.dataset.questionId,s=this.getDataAnswersConfig(e),r=e.querySelector(`${p.selectors.elAnswersConfig}`),c=structuredClone(s),d=r.querySelectorAll(`${p.selectors.elQuestionAnswerItem}:not(.clone)`),u={};d.forEach((e,t)=>{u[e.dataset.answerId]=t+1}),s.map((t,s)=>{const i=e.querySelector(`${p.selectors.elQuestionAnswerItem}[data-answer-id="${t.question_answer_id}"]`),n=i.querySelector(`${p.selectors.elInputAnswerSetTrue}`),o=i.querySelector(`${p.selectors.elQuestionAnswerTitleInput}`);return o&&(t.title=o.value.trim()),n&&(n.checked?t.is_true="yes":t.is_true=""),u[t.question_answer_id]&&(t.order=u[t.question_answer_id]),t}),i.lpSetLoadingEl(a,1);const h={success:e=>{const{message:t,status:s}=e;if("success"!==s)throw`Error: ${t}`;n.W(t,s)},error:t=>{c.forEach(t=>{const s=e.querySelector(`${p.selectors.elQuestionAnswerItem}[data-answer-id="${t.question_answer_id}"]`).querySelector(`${p.selectors.elInputAnswerSetTrue}`);return"yes"===t.is_true&&(s.checked=!0),t}),n.W(t,"error")},completed:()=>{i.lpSetLoadingEl(a,0)}},m={action:"update_question_answers_config",question_id:t,answers:s,args:{id_url:l}};window.lpAJAXG.fetchAJAX(m,h)},700)}sortAbleQuestionAnswer(e){let t,s=0;e.querySelectorAll(`${p.selectors.elAnswersConfig}`).forEach(e=>{new r.Ay(e,{handle:".drag",animation:150,onEnd:e=>{const i=e.item;s&&(clearTimeout(t),t=setTimeout(()=>{const e=i.querySelector(`${p.selectors.elAutoSaveAnswer}`);this.autoUpdateAnswer({e:null,target:e})},1e3))},onMove:e=>{clearTimeout(t)},onUpdate:e=>{s=1}})})}deleteQuestionAnswer(e){const{e:t,target:s}=e,o=s.closest(`${p.selectors.elBtnDeleteAnswer}`);if(!o)return;const r=o.closest(`${p.selectors.elQuestionAnswerItem}`);if(!r)return;const c=o.closest(`${p.selectors.elQuestionEditMain}`),d=c.dataset.questionId,u=r.dataset.answerId;d&&u&&a().fire({title:o.dataset.title||"Are you sure?",text:o.dataset.content||"Do you want to delete this answer?",icon:"warning",showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(e=>{if(e.isConfirmed){i.lpSetLoadingEl(r,1);const e={success:e=>{const{message:t,status:s}=e;if(n.W(t,s),"success"===s){const e=parseInt(r.dataset.answerId);r.remove();const t=this.getDataAnswersConfig(c);if(t){const s=t.filter(t=>parseInt(t.question_answer_id)!==e);this.setDataAnswersConfig(c,s)}}},error:e=>{n.W(e,"error")},completed:()=>{i.lpSetLoadingEl(r,0)}},t={action:"delete_question_answer",question_id:d,question_answer_id:u,args:{id_url:l}};window.lpAJAXG.fetchAJAX(t,e)}})}getDataAnswersConfig(e){const t=e.querySelector(`${p.selectors.elAnswersConfig}`);if(!t)return null;let s=t.dataset.answers||"[]";try{s=JSON.parse(s)}catch(e){s=[]}return s.meta_data||(s.meta_data={}),s}setDataAnswersConfig(e,t){const s=e.querySelector(`${p.selectors.elAnswersConfig}`);s&&(t&&"object"==typeof t||(t={}),s.dataset.answers=JSON.stringify(t))}fibInsertBlank=e=>{const{e:t,target:s}=e,o=s.closest(p.selectors.elBtnFibInsertBlank);if(!o)return;const a=o.dataset.defaultText,r=o.closest(p.selectors.elQuestionEditMain),l=r.dataset.questionId,d=o.dataset.messInserted,u=o.dataset.messRequireSelectText,h=`${p.selectors.elQuestionFibInput}-${l}`,m=this.randomString();let g;if(!c)return void n.W(u,"error");{const e=c.getNode();if(!e)return void n.W("Event insert blank has error, please try again","error");if(!e.closest(`body[data-id="${h}"]`))return void n.W(u,"error");if(e.classList.contains(`${p.selectors.elQuestionFibInput}`))return void n.W(d,"error");g=c.getContent(),0===g.length&&(g=a);const t=`<span class="${p.selectors.elQuestionFibInput}" data-id="${m}">${g}</span>`;c.setContent(t)}const f=this.getDataAnswersConfig(r);f.meta_data=f.meta_data||{},0===Object.keys(f.meta_data).length&&(f.meta_data={}),f.meta_data[m]={id:m,match_case:0,comparison:"equal",fill:g,index:1,open:!1},this.setDataAnswersConfig(r,f);const b=r.querySelector(`${p.selectors.elFibBlankOptions}`),v=r.querySelector(`${p.selectors.elFibBlankOptionItemClone}`),y=v.cloneNode(!0),w=b.querySelectorAll(`${p.selectors.elFibBlankOptionItem}:not(.clone)`).length,_=y.querySelector(`${p.selectors.elFibBlankOptionIndex}`),x=y.querySelector(`${p.selectors.elFibOptionTitleInput}`),S=y.querySelector(`${p.selectors.elFibOptionMatchCaseInput}`),C=y.querySelectorAll(`${p.selectors.elFibOptionComparisonInput}`);y.dataset.id=m,x.name=`${p.selectors.elFibOptionTitleInput}-${m}`,x.value=this.decodeHtml(g),_.textContent=w+1+".",S.name=`${p.selectors.elFibOptionMatchCaseInput}-${m}`.replace(/\./g,""),C.forEach(e=>{e.name=`${p.selectors.elFibOptionComparisonInput}-${m}`.replace(/\./g,""),"equal"===e.value&&(e.checked=!0)}),v.insertAdjacentElement("beforebegin",y),y.classList.remove("clone"),i.lpShowHideEl(y,1);const k=r.querySelector(`${p.selectors.elBtnFibSaveContent}`);i.lpSetLoadingEl(o,1),this.fibSaveContent({e:null,target:k,callBackCompleted:()=>{i.lpSetLoadingEl(o,0)}})};fibDeleteAllBlanks(e){const{e:t,target:s}=e,n=s.closest(`${p.selectors.elBtnFibDeleteAllBlanks}`);if(!n)return;const o=n.closest(`${p.selectors.elQuestionEditMain}`);if(!o)return;const r=o.dataset.questionId,l=this.getDataAnswersConfig(o);a().fire({title:n.dataset.title,text:n.dataset.content,icon:"warning",showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(e=>{if(e.isConfirmed){const e=window.tinymce.get(`${p.selectors.elQuestionFibInput}-${r}`);e.dom.select(`.${p.selectors.elQuestionFibInput}`).forEach(t=>{e.dom.remove(t,!0)}),l.meta_data={},this.setDataAnswersConfig(o,l),o.querySelector(`${p.selectors.elFibBlankOptions}`).querySelectorAll(`${p.selectors.elFibBlankOptionItem}:not(.clone)`).forEach(e=>{e.remove()});const t=o.querySelector(`${p.selectors.elBtnFibSaveContent}`);i.lpSetLoadingEl(n,1),this.fibSaveContent({e:null,target:t,callBackCompleted:()=>{i.lpSetLoadingEl(n,0)}})}})}fibClearContent(e){const{e:t,target:s}=e,n=s.closest(`${p.selectors.elBtnFibClearAllContent}`);if(!n)return;const o=n.closest(`${p.selectors.elQuestionEditMain}`);if(!o)return;const r=o.dataset.questionId,l=this.getDataAnswersConfig(o);a().fire({title:n.dataset.title,text:n.dataset.content,icon:"warning",showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(e=>{if(e.isConfirmed){window.tinymce.get(`lp-question-fib-input-${r}`).setContent(""),l.meta_data={},this.setDataAnswersConfig(o,l),o.querySelector(`${p.selectors.elFibBlankOptions}`).querySelectorAll(`${p.selectors.elFibBlankOptionItem}:not(.clone)`).forEach(e=>{e.remove()});const e=o.querySelector(`${p.selectors.elBtnFibSaveContent}`);i.lpSetLoadingEl(n,1),this.fibSaveContent({e:null,target:e,callBackCompleted:()=>{i.lpSetLoadingEl(n,0)}})}})}fibDeleteBlank(e){const{e:t,target:s}=e,n=s.closest(`${p.selectors.elBtnFibOptionDelete}`);if(!n)return;const o=n.closest(`${p.selectors.elQuestionEditMain}`);if(!o)return;const r=o.dataset.questionId,l=(o.querySelector(`${p.selectors.elAnswersConfig}`),this.getDataAnswersConfig(o)),c=n.closest(`${p.selectors.elFibBlankOptionItem}`),d=c.dataset.id;a().fire({title:n.dataset.title,text:n.dataset.content,icon:"warning",showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(e=>{if(e.isConfirmed){const e=window.tinymce.get(`${p.selectors.elQuestionFibInput}-${r}`),t=e.dom.select(`.${p.selectors.elQuestionFibInput}[data-id="${d}"]`);t[0]&&e.dom.remove(t[0],!0),c.remove(),l.meta_data=l.meta_data||{},l.meta_data[d]&&delete l.meta_data[d],this.setDataAnswersConfig(o,l);const s=o.querySelector(`${p.selectors.elBtnFibSaveContent}`);i.lpSetLoadingEl(c,1),this.fibSaveContent({e:null,target:s,callBackCompleted:()=>{i.lpSetLoadingEl(c,0)}})}})}fibOptionTitleInputChange(e){const{e:t,target:s}=e,i=s.closest(`${p.selectors.elFibOptionTitleInput}`);if(!i)return;const n=i.closest(`${p.selectors.elFibBlankOptionItem}`);if(!n)return;const o=i.closest(`${p.selectors.elQuestionEditMain}`);if(!o)return;const a=i.value.trim(),r=n.dataset.id,l=o.dataset.questionId,c=window.tinymce.get(`lp-question-fib-input-${l}`).dom.select(`.lp-question-fib-input[data-id="${r}"]`);c[0]&&(c[0].textContent=a),clearTimeout(u),u=setTimeout(()=>{const e=o.querySelector(`${p.selectors.elBtnFibSaveContent}`);this.fibSaveContent({e:null,target:e})},700)}fibSaveContent(e){const{e:t,target:s,callBackCompleted:o=null}=e,a=s.closest(`${p.selectors.elBtnFibSaveContent}`);if(!a)return;const r=a.closest(`${p.selectors.elQuestionEditMain}`),c=r.dataset.questionId,d=this.getDataAnswersConfig(r);if(!d)return;const u=window.tinymce.get(`${p.selectors.elQuestionFibInput}-${c}`);d.title=u.getContent();const h=r.querySelectorAll(`${p.selectors.elFibBlankOptionItem}:not(.clone)`);h&&h.forEach(e=>{const t=e.dataset.id,s=e.querySelector(`${p.selectors.elFibOptionMatchCaseInput}`),i=e.querySelector(`${p.selectors.elFibOptionComparisonInput}:checked`);d.meta_data[t].match_case=s.checked?1:0,d.meta_data[t].comparison=i.value}),o||i.lpSetLoadingEl(a,1);const m={success:e=>{const{message:t,status:s}=e;if("success"!==s)throw`Error: ${t}`;this.setDataAnswersConfig(r,d),n.W(t,s)},error:e=>{n.W(e,"error")},completed:()=>{o&&"function"==typeof o?o():i.lpSetLoadingEl(a,0)}},g={action:"update_question_answers_config",question_id:c,answers:d,args:{id_url:l}};window.lpAJAXG.fetchAJAX(g,m)}fibShowHideMatchCaseOption(e){const{e:t,target:s}=e,n=s.closest(`${p.selectors.elFibOptionMatchCaseInput}`);if(!n)return;const o=n.closest(`${p.selectors.elQuestionFibOptionDetail}`),a=o.querySelector(`${p.selectors.elFibOptionMatchCaseWrap}`);o&&a&&(n.checked?i.lpShowHideEl(a,1):i.lpShowHideEl(a,0),n.closest(`${p.selectors.elQuestionEditMain}`).querySelector(`${p.selectors.elBtnFibSaveContent}`).click())}randomString(e=10){let t="";for(let s=0;s<e;s++)t+="abcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(36*Math.random()));return t}decodeHtml(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}}const m=new p;i.lpOnElementReady(p.selectors.elEditQuestionWrap,e=>{const t=p.selectors.elQuestionEditMain.replace(".","");e.classList.contains(t)&&m.init()})},2603(e,t,s){"use strict";s.d(t,{W:()=>a});var i=s(7736),n=s.n(i);s(4316);const o={text:"",gravity:lpData.toast.gravity,position:lpData.toast.position,className:`${lpData.toast.classPrefix}`,close:1==lpData.toast.close,stopOnFocus:1==lpData.toast.stopOnFocus,duration:lpData.toast.duration},a=(e,t="success",s)=>{let i=o;s&&(i={...i,...s}),new(n())({...i,text:e,className:`${lpData.toast.classPrefix} ${t}`}).showToast()}},4223(e,t,s){"use strict";s.r(t),s.d(t,{debounce:()=>v,eventHandlers:()=>b,getDataOfForm:()=>m,getFieldKeysOfForm:()=>g,listenElementCreated:()=>l,listenElementViewed:()=>r,lpAddQueryArgs:()=>a,lpAjaxParseJsonOld:()=>d,lpClassName:()=>i,lpFetchAPI:()=>n,lpGetCurrentURLNoParam:()=>o,lpOnElementReady:()=>c,lpSetLoadingEl:()=>h,lpShowHideEl:()=>u,mergeDataWithDatForm:()=>f,toggleCollapse:()=>p});const i={hidden:"lp-hidden",loading:"loading",elCollapse:"lp-collapse",elSectionToggle:".lp-section-toggle",elTriggerToggle:".lp-trigger-toggle"},n=(e,t={},s={})=>{"function"==typeof s.before&&s.before(),fetch(e,{method:"GET",...t}).then(e=>e.json()).then(e=>{"function"==typeof s.success&&s.success(e)}).catch(e=>{"function"==typeof s.error&&s.error(e)}).finally(()=>{"function"==typeof s.completed&&s.completed()})},o=()=>{let e=window.location.href;return e.includes("?")&&(e=e.split("?")[0]),e},a=(e,t)=>{const s=new URL(e);return Object.keys(t).forEach(e=>{s.searchParams.set(e,t[e])}),s},r=(e,t)=>{new IntersectionObserver(function(e){for(const s of e)s.isIntersecting&&t(s)}).observe(e)},l=e=>{new MutationObserver(function(t){t.forEach(function(t){t.addedNodes&&t.addedNodes.forEach(function(t){1===t.nodeType&&e(t)})})}).observe(document,{childList:!0,subtree:!0})},c=(e,t)=>{const s=document.querySelector(e);if(s)return void t(s);const i=new MutationObserver((s,i)=>{const n=document.querySelector(e);n&&(i.disconnect(),t(n))});i.observe(document.documentElement,{childList:!0,subtree:!0})},d=e=>{if("string"!=typeof e)return e;const t=String.raw({raw:e}).match(/<-- LP_AJAX_START -->(.*)<-- LP_AJAX_END -->/s);try{e=t?JSON.parse(t[1].replace(/(?:\r\n|\r|\n)/g,"")):JSON.parse(e)}catch(t){e={}}return e},u=(e,t=0)=>{e&&(t?e.classList.remove(i.hidden):e.classList.add(i.hidden))},h=(e,t)=>{e&&(t?e.classList.add(i.loading):e.classList.remove(i.loading))},p=(e,t,s="",n=[],o)=>{if(s||(s=i.elTriggerToggle),n&&n.length>0)for(const e of n)if(t.closest(e))return;const a=t.closest(s);if(!a)return;const r=a.closest(`${i.elSectionToggle}`);r&&(r.classList.toggle(`${i.elCollapse}`),"function"==typeof o&&o(r))},m=e=>{const t={},s=new FormData(e);for(const e of s.entries()){const i=e[0],n=s.getAll(i);t.hasOwnProperty(i)||(t[i]=n.join(","))}return t},g=e=>{const t=[],s=e.elements;for(let e=0;e<s.length;e++){const i=s[e].name;i&&!t.includes(i)&&t.push(i)}return t},f=(e,t)=>{const s=m(e);return g(e).forEach(e=>{s.hasOwnProperty(e)?""===s[e][0]&&(delete s[e],delete t[e]):delete t[e]}),t={...t,...s}},b=(e,t)=>{document.addEventListener(e,s=>{const i=s.target;let n={e:s,target:i};t.forEach(t=>{n={...n,...t},t.conditionBeforeCallBack&&!0!==t.conditionBeforeCallBack(n)||"keydown"===e&&t.checkIsEventEnter&&"Enter"!==s.key||i.closest(t.selector)&&(t.class?t.class[t.callBack](n):t.callBack(n))})})},v=(e,t=500)=>{let s;return i=>{clearTimeout(s),s=setTimeout(()=>e(i),t)}}},9455(e,t,s){"use strict";s.d(t,{A:()=>r});var i=s(1601),n=s.n(i),o=s(6314),a=s.n(o)()(n());a.push([e.id,"/*!\n * Toastify js 1.12.0\n * https://github.com/apvarun/toastify-js\n * @license MIT licensed\n *\n * Copyright (C) 2018 Varun A P\n */\n\n.toastify {\n padding: 12px 20px;\n color: #ffffff;\n display: inline-block;\n box-shadow: 0 3px 6px -1px rgba(0, 0, 0, 0.12), 0 10px 36px -4px rgba(77, 96, 232, 0.3);\n background: -webkit-linear-gradient(315deg, #73a5ff, #5477f5);\n background: linear-gradient(135deg, #73a5ff, #5477f5);\n position: fixed;\n opacity: 0;\n transition: all 0.4s cubic-bezier(0.215, 0.61, 0.355, 1);\n border-radius: 2px;\n cursor: pointer;\n text-decoration: none;\n max-width: calc(50% - 20px);\n z-index: 2147483647;\n}\n\n.toastify.on {\n opacity: 1;\n}\n\n.toast-close {\n background: transparent;\n border: 0;\n color: white;\n cursor: pointer;\n font-family: inherit;\n font-size: 1em;\n opacity: 0.4;\n padding: 0 5px;\n}\n\n.toastify-right {\n right: 15px;\n}\n\n.toastify-left {\n left: 15px;\n}\n\n.toastify-top {\n top: -150px;\n}\n\n.toastify-bottom {\n bottom: -150px;\n}\n\n.toastify-rounded {\n border-radius: 25px;\n}\n\n.toastify-avatar {\n width: 1.5em;\n height: 1.5em;\n margin: -7px 5px;\n border-radius: 2px;\n}\n\n.toastify-center {\n margin-left: auto;\n margin-right: auto;\n left: 0;\n right: 0;\n max-width: fit-content;\n max-width: -moz-fit-content;\n}\n\n@media only screen and (max-width: 360px) {\n .toastify-right, .toastify-left {\n margin-left: auto;\n margin-right: auto;\n left: 0;\n right: 0;\n max-width: fit-content;\n }\n}\n",""]);const r=a},6314(e){"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var s="",i=void 0!==t[5];return t[4]&&(s+="@supports (".concat(t[4],") {")),t[2]&&(s+="@media ".concat(t[2]," {")),i&&(s+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),s+=e(t),i&&(s+="}"),t[2]&&(s+="}"),t[4]&&(s+="}"),s}).join("")},t.i=function(e,s,i,n,o){"string"==typeof e&&(e=[[null,e,void 0]]);var a={};if(i)for(var r=0;r<this.length;r++){var l=this[r][0];null!=l&&(a[l]=!0)}for(var c=0;c<e.length;c++){var d=[].concat(e[c]);i&&a[d[0]]||(void 0!==o&&(void 0===d[5]||(d[1]="@layer".concat(d[5].length>0?" ".concat(d[5]):""," {").concat(d[1],"}")),d[5]=o),s&&(d[2]?(d[1]="@media ".concat(d[2]," {").concat(d[1],"}"),d[2]=s):d[2]=s),n&&(d[4]?(d[1]="@supports (".concat(d[4],") {").concat(d[1],"}"),d[4]=n):d[4]="".concat(n)),t.push(d))}},t}},1601(e){"use strict";e.exports=function(e){return e[1]}},246(e,t,s){"use strict";function i(e,t,s){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var s=t.call(e,"string");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}function n(){return n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var i in s)({}).hasOwnProperty.call(s,i)&&(e[i]=s[i])}return e},n.apply(null,arguments)}function o(e,t){var s=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),s.push.apply(s,i)}return s}function a(e){for(var t=1;t<arguments.length;t++){var s=null!=arguments[t]?arguments[t]:{};t%2?o(Object(s),!0).forEach(function(t){i(e,t,s[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(s)):o(Object(s)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(s,t))})}return e}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function l(e){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(e)}s.d(t,{Ay:()=>nt});var c=l(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),d=l(/Edge/i),u=l(/firefox/i),h=l(/safari/i)&&!l(/chrome/i)&&!l(/android/i),p=l(/iP(ad|od|hone)/i),m=l(/chrome/i)&&l(/android/i),g={capture:!1,passive:!1};function f(e,t,s){e.addEventListener(t,s,!c&&g)}function b(e,t,s){e.removeEventListener(t,s,!c&&g)}function v(e,t){if(t){if(">"===t[0]&&(t=t.substring(1)),e)try{if(e.matches)return e.matches(t);if(e.msMatchesSelector)return e.msMatchesSelector(t);if(e.webkitMatchesSelector)return e.webkitMatchesSelector(t)}catch(e){return!1}return!1}}function y(e){return e.host&&e!==document&&e.host.nodeType&&e.host!==e?e.host:e.parentNode}function w(e,t,s,i){if(e){s=s||document;do{if(null!=t&&(">"===t[0]?e.parentNode===s&&v(e,t):v(e,t))||i&&e===s)return e;if(e===s)break}while(e=y(e))}return null}var _,x=/\s+/g;function S(e,t,s){if(e&&t)if(e.classList)e.classList[s?"add":"remove"](t);else{var i=(" "+e.className+" ").replace(x," ").replace(" "+t+" "," ");e.className=(i+(s?" "+t:"")).replace(x," ")}}function C(e,t,s){var i=e&&e.style;if(i){if(void 0===s)return document.defaultView&&document.defaultView.getComputedStyle?s=document.defaultView.getComputedStyle(e,""):e.currentStyle&&(s=e.currentStyle),void 0===t?s:s[t];t in i||-1!==t.indexOf("webkit")||(t="-webkit-"+t),i[t]=s+("string"==typeof s?"":"px")}}function k(e,t){var s="";if("string"==typeof e)s=e;else do{var i=C(e,"transform");i&&"none"!==i&&(s=i+" "+s)}while(!t&&(e=e.parentNode));var n=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return n&&new n(s)}function A(e,t,s){if(e){var i=e.getElementsByTagName(t),n=0,o=i.length;if(s)for(;n<o;n++)s(i[n],n);return i}return[]}function E(){return document.scrollingElement||document.documentElement}function T(e,t,s,i,n){if(e.getBoundingClientRect||e===window){var o,a,r,l,d,u,h;if(e!==window&&e.parentNode&&e!==E()?(a=(o=e.getBoundingClientRect()).top,r=o.left,l=o.bottom,d=o.right,u=o.height,h=o.width):(a=0,r=0,l=window.innerHeight,d=window.innerWidth,u=window.innerHeight,h=window.innerWidth),(t||s)&&e!==window&&(n=n||e.parentNode,!c))do{if(n&&n.getBoundingClientRect&&("none"!==C(n,"transform")||s&&"static"!==C(n,"position"))){var p=n.getBoundingClientRect();a-=p.top+parseInt(C(n,"border-top-width")),r-=p.left+parseInt(C(n,"border-left-width")),l=a+o.height,d=r+o.width;break}}while(n=n.parentNode);if(i&&e!==window){var m=k(n||e),g=m&&m.a,f=m&&m.d;m&&(l=(a/=f)+(u/=f),d=(r/=g)+(h/=g))}return{top:a,left:r,bottom:l,right:d,width:h,height:u}}}function L(e,t,s){for(var i=P(e,!0),n=T(e)[t];i;){var o=T(i)[s];if(!("top"===s||"left"===s?n>=o:n<=o))return i;if(i===E())break;i=P(i,!1)}return!1}function I(e,t,s,i){for(var n=0,o=0,a=e.children;o<a.length;){if("none"!==a[o].style.display&&a[o]!==ze.ghost&&(i||a[o]!==ze.dragged)&&w(a[o],s.draggable,e,!1)){if(n===t)return a[o];n++}o++}return null}function D(e,t){for(var s=e.lastElementChild;s&&(s===ze.ghost||"none"===C(s,"display")||t&&!v(s,t));)s=s.previousElementSibling;return s||null}function q(e,t){var s=0;if(!e||!e.parentNode)return-1;for(;e=e.previousElementSibling;)"TEMPLATE"===e.nodeName.toUpperCase()||e===ze.clone||t&&!v(e,t)||s++;return s}function B(e){var t=0,s=0,i=E();if(e)do{var n=k(e),o=n.a,a=n.d;t+=e.scrollLeft*o,s+=e.scrollTop*a}while(e!==i&&(e=e.parentNode));return[t,s]}function P(e,t){if(!e||!e.getBoundingClientRect)return E();var s=e,i=!1;do{if(s.clientWidth<s.scrollWidth||s.clientHeight<s.scrollHeight){var n=C(s);if(s.clientWidth<s.scrollWidth&&("auto"==n.overflowX||"scroll"==n.overflowX)||s.clientHeight<s.scrollHeight&&("auto"==n.overflowY||"scroll"==n.overflowY)){if(!s.getBoundingClientRect||s===document.body)return E();if(i||t)return s;i=!0}}}while(s=s.parentNode);return E()}function M(e,t){return Math.round(e.top)===Math.round(t.top)&&Math.round(e.left)===Math.round(t.left)&&Math.round(e.height)===Math.round(t.height)&&Math.round(e.width)===Math.round(t.width)}function O(e,t){return function(){if(!_){var s=arguments;1===s.length?e.call(this,s[0]):e.apply(this,s),_=setTimeout(function(){_=void 0},t)}}}function z(e,t,s){e.scrollLeft+=t,e.scrollTop+=s}function $(e){var t=window.Polymer,s=window.jQuery||window.Zepto;return t&&t.dom?t.dom(e).cloneNode(!0):s?s(e).clone(!0)[0]:e.cloneNode(!0)}function F(e,t,s){var i={};return Array.from(e.children).forEach(function(n){var o,a,r,l;if(w(n,t.draggable,e,!1)&&!n.animated&&n!==s){var c=T(n);i.left=Math.min(null!==(o=i.left)&&void 0!==o?o:1/0,c.left),i.top=Math.min(null!==(a=i.top)&&void 0!==a?a:1/0,c.top),i.right=Math.max(null!==(r=i.right)&&void 0!==r?r:-1/0,c.right),i.bottom=Math.max(null!==(l=i.bottom)&&void 0!==l?l:-1/0,c.bottom)}}),i.width=i.right-i.left,i.height=i.bottom-i.top,i.x=i.left,i.y=i.top,i}var H="Sortable"+(new Date).getTime();var Q=[],N={initializeByDefault:!0},R={mount:function(e){for(var t in N)N.hasOwnProperty(t)&&!(t in e)&&(e[t]=N[t]);Q.forEach(function(t){if(t.pluginName===e.pluginName)throw"Sortable: Cannot mount plugin ".concat(e.pluginName," more than once")}),Q.push(e)},pluginEvent:function(e,t,s){var i=this;this.eventCanceled=!1,s.cancel=function(){i.eventCanceled=!0};var n=e+"Global";Q.forEach(function(i){t[i.pluginName]&&(t[i.pluginName][n]&&t[i.pluginName][n](a({sortable:t},s)),t.options[i.pluginName]&&t[i.pluginName][e]&&t[i.pluginName][e](a({sortable:t},s)))})},initializePlugins:function(e,t,s,i){for(var o in Q.forEach(function(i){var o=i.pluginName;if(e.options[o]||i.initializeByDefault){var a=new i(e,t,e.options);a.sortable=e,a.options=e.options,e[o]=a,n(s,a.defaults)}}),e.options)if(e.options.hasOwnProperty(o)){var a=this.modifyOption(e,o,e.options[o]);void 0!==a&&(e.options[o]=a)}},getEventProperties:function(e,t){var s={};return Q.forEach(function(i){"function"==typeof i.eventProperties&&n(s,i.eventProperties.call(t[i.pluginName],e))}),s},modifyOption:function(e,t,s){var i;return Q.forEach(function(n){e[n.pluginName]&&n.optionListeners&&"function"==typeof n.optionListeners[t]&&(i=n.optionListeners[t].call(e[n.pluginName],s))}),i}};var W=["evt"],j=function(e,t){var s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=s.evt,n=function(e,t){if(null==e)return{};var s,i,n=function(e,t){if(null==e)return{};var s={};for(var i in e)if({}.hasOwnProperty.call(e,i)){if(-1!==t.indexOf(i))continue;s[i]=e[i]}return s}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i<o.length;i++)s=o[i],-1===t.indexOf(s)&&{}.propertyIsEnumerable.call(e,s)&&(n[s]=e[s])}return n}(s,W);R.pluginEvent.bind(ze)(e,t,a({dragEl:U,parentEl:X,ghostEl:J,rootEl:G,nextEl:Y,lastDownEl:K,cloneEl:Z,cloneHidden:ee,dragStarted:pe,putSortable:ae,activeSortable:ze.active,originalEvent:i,oldIndex:te,oldDraggableIndex:ie,newIndex:se,newDraggableIndex:ne,hideGhostForTarget:Be,unhideGhostForTarget:Pe,cloneNowHidden:function(){ee=!0},cloneNowShown:function(){ee=!1},dispatchSortableEvent:function(e){V({sortable:t,name:e,originalEvent:i})}},n))};function V(e){!function(e){var t=e.sortable,s=e.rootEl,i=e.name,n=e.targetEl,o=e.cloneEl,r=e.toEl,l=e.fromEl,u=e.oldIndex,h=e.newIndex,p=e.oldDraggableIndex,m=e.newDraggableIndex,g=e.originalEvent,f=e.putSortable,b=e.extraEventProperties;if(t=t||s&&s[H]){var v,y=t.options,w="on"+i.charAt(0).toUpperCase()+i.substr(1);!window.CustomEvent||c||d?(v=document.createEvent("Event")).initEvent(i,!0,!0):v=new CustomEvent(i,{bubbles:!0,cancelable:!0}),v.to=r||s,v.from=l||s,v.item=n||s,v.clone=o,v.oldIndex=u,v.newIndex=h,v.oldDraggableIndex=p,v.newDraggableIndex=m,v.originalEvent=g,v.pullMode=f?f.lastPutMode:void 0;var _=a(a({},b),R.getEventProperties(i,t));for(var x in _)v[x]=_[x];s&&s.dispatchEvent(v),y[w]&&y[w].call(t,v)}}(a({putSortable:ae,cloneEl:Z,targetEl:U,rootEl:G,oldIndex:te,oldDraggableIndex:ie,newIndex:se,newDraggableIndex:ne},e))}var U,X,J,G,Y,K,Z,ee,te,se,ie,ne,oe,ae,re,le,ce,de,ue,he,pe,me,ge,fe,be,ve=!1,ye=!1,we=[],_e=!1,xe=!1,Se=[],Ce=!1,ke=[],Ae="undefined"!=typeof document,Ee=p,Te=d||c?"cssFloat":"float",Le=Ae&&!m&&!p&&"draggable"in document.createElement("div"),Ie=function(){if(Ae){if(c)return!1;var e=document.createElement("x");return e.style.cssText="pointer-events:auto","auto"===e.style.pointerEvents}}(),De=function(e,t){var s=C(e),i=parseInt(s.width)-parseInt(s.paddingLeft)-parseInt(s.paddingRight)-parseInt(s.borderLeftWidth)-parseInt(s.borderRightWidth),n=I(e,0,t),o=I(e,1,t),a=n&&C(n),r=o&&C(o),l=a&&parseInt(a.marginLeft)+parseInt(a.marginRight)+T(n).width,c=r&&parseInt(r.marginLeft)+parseInt(r.marginRight)+T(o).width;if("flex"===s.display)return"column"===s.flexDirection||"column-reverse"===s.flexDirection?"vertical":"horizontal";if("grid"===s.display)return s.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(n&&a.float&&"none"!==a.float){var d="left"===a.float?"left":"right";return!o||"both"!==r.clear&&r.clear!==d?"horizontal":"vertical"}return n&&("block"===a.display||"flex"===a.display||"table"===a.display||"grid"===a.display||l>=i&&"none"===s[Te]||o&&"none"===s[Te]&&l+c>i)?"vertical":"horizontal"},qe=function(e){function t(e,s){return function(i,n,o,a){var r=i.options.group.name&&n.options.group.name&&i.options.group.name===n.options.group.name;if(null==e&&(s||r))return!0;if(null==e||!1===e)return!1;if(s&&"clone"===e)return e;if("function"==typeof e)return t(e(i,n,o,a),s)(i,n,o,a);var l=(s?i:n).options.group.name;return!0===e||"string"==typeof e&&e===l||e.join&&e.indexOf(l)>-1}}var s={},i=e.group;i&&"object"==r(i)||(i={name:i}),s.name=i.name,s.checkPull=t(i.pull,!0),s.checkPut=t(i.put),s.revertClone=i.revertClone,e.group=s},Be=function(){!Ie&&J&&C(J,"display","none")},Pe=function(){!Ie&&J&&C(J,"display","")};Ae&&!m&&document.addEventListener("click",function(e){if(ye)return e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation(),ye=!1,!1},!0);var Me=function(e){if(U){e=e.touches?e.touches[0]:e;var t=(n=e.clientX,o=e.clientY,we.some(function(e){var t=e[H].options.emptyInsertThreshold;if(t&&!D(e)){var s=T(e),i=n>=s.left-t&&n<=s.right+t,r=o>=s.top-t&&o<=s.bottom+t;return i&&r?a=e:void 0}}),a);if(t){var s={};for(var i in e)e.hasOwnProperty(i)&&(s[i]=e[i]);s.target=s.rootEl=t,s.preventDefault=void 0,s.stopPropagation=void 0,t[H]._onDragOver(s)}}var n,o,a},Oe=function(e){U&&U.parentNode[H]._isOutsideThisEl(e.target)};function ze(e,t){if(!e||!e.nodeType||1!==e.nodeType)throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(e));this.el=e,this.options=t=n({},t),e[H]=this;var s,i,o={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(e.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return De(e,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(e,t){e.setData("Text",t.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:!1!==ze.supportPointer&&"PointerEvent"in window&&(!h||p),emptyInsertThreshold:5};for(var r in R.initializePlugins(this,e,o),o)!(r in t)&&(t[r]=o[r]);for(var l in qe(t),this)"_"===l.charAt(0)&&"function"==typeof this[l]&&(this[l]=this[l].bind(this));this.nativeDraggable=!t.forceFallback&&Le,this.nativeDraggable&&(this.options.touchStartThreshold=1),t.supportPointer?f(e,"pointerdown",this._onTapStart):(f(e,"mousedown",this._onTapStart),f(e,"touchstart",this._onTapStart)),this.nativeDraggable&&(f(e,"dragover",this),f(e,"dragenter",this)),we.push(this.el),t.store&&t.store.get&&this.sort(t.store.get(this)||[]),n(this,(i=[],{captureAnimationState:function(){i=[],this.options.animation&&[].slice.call(this.el.children).forEach(function(e){if("none"!==C(e,"display")&&e!==ze.ghost){i.push({target:e,rect:T(e)});var t=a({},i[i.length-1].rect);if(e.thisAnimationDuration){var s=k(e,!0);s&&(t.top-=s.f,t.left-=s.e)}e.fromRect=t}})},addAnimationState:function(e){i.push(e)},removeAnimationState:function(e){i.splice(function(e,t){for(var s in e)if(e.hasOwnProperty(s))for(var i in t)if(t.hasOwnProperty(i)&&t[i]===e[s][i])return Number(s);return-1}(i,{target:e}),1)},animateAll:function(e){var t=this;if(!this.options.animation)return clearTimeout(s),void("function"==typeof e&&e());var n=!1,o=0;i.forEach(function(e){var s=0,i=e.target,a=i.fromRect,r=T(i),l=i.prevFromRect,c=i.prevToRect,d=e.rect,u=k(i,!0);u&&(r.top-=u.f,r.left-=u.e),i.toRect=r,i.thisAnimationDuration&&M(l,r)&&!M(a,r)&&(d.top-r.top)/(d.left-r.left)===(a.top-r.top)/(a.left-r.left)&&(s=function(e,t,s,i){return Math.sqrt(Math.pow(t.top-e.top,2)+Math.pow(t.left-e.left,2))/Math.sqrt(Math.pow(t.top-s.top,2)+Math.pow(t.left-s.left,2))*i.animation}(d,l,c,t.options)),M(r,a)||(i.prevFromRect=a,i.prevToRect=r,s||(s=t.options.animation),t.animate(i,d,r,s)),s&&(n=!0,o=Math.max(o,s),clearTimeout(i.animationResetTimer),i.animationResetTimer=setTimeout(function(){i.animationTime=0,i.prevFromRect=null,i.fromRect=null,i.prevToRect=null,i.thisAnimationDuration=null},s),i.thisAnimationDuration=s)}),clearTimeout(s),n?s=setTimeout(function(){"function"==typeof e&&e()},o):"function"==typeof e&&e(),i=[]},animate:function(e,t,s,i){if(i){C(e,"transition",""),C(e,"transform","");var n=k(this.el),o=n&&n.a,a=n&&n.d,r=(t.left-s.left)/(o||1),l=(t.top-s.top)/(a||1);e.animatingX=!!r,e.animatingY=!!l,C(e,"transform","translate3d("+r+"px,"+l+"px,0)"),this.forRepaintDummy=function(e){return e.offsetWidth}(e),C(e,"transition","transform "+i+"ms"+(this.options.easing?" "+this.options.easing:"")),C(e,"transform","translate3d(0,0,0)"),"number"==typeof e.animated&&clearTimeout(e.animated),e.animated=setTimeout(function(){C(e,"transition",""),C(e,"transform",""),e.animated=!1,e.animatingX=!1,e.animatingY=!1},i)}}}))}function $e(e,t,s,i,n,o,a,r){var l,u,h=e[H],p=h.options.onMove;return!window.CustomEvent||c||d?(l=document.createEvent("Event")).initEvent("move",!0,!0):l=new CustomEvent("move",{bubbles:!0,cancelable:!0}),l.to=t,l.from=e,l.dragged=s,l.draggedRect=i,l.related=n||t,l.relatedRect=o||T(t),l.willInsertAfter=r,l.originalEvent=a,e.dispatchEvent(l),p&&(u=p.call(h,l,a)),u}function Fe(e){e.draggable=!1}function He(){Ce=!1}function Qe(e){for(var t=e.tagName+e.className+e.src+e.href+e.textContent,s=t.length,i=0;s--;)i+=t.charCodeAt(s);return i.toString(36)}function Ne(e){return setTimeout(e,0)}function Re(e){return clearTimeout(e)}ze.prototype={constructor:ze,_isOutsideThisEl:function(e){this.el.contains(e)||e===this.el||(me=null)},_getDirection:function(e,t){return"function"==typeof this.options.direction?this.options.direction.call(this,e,t,U):this.options.direction},_onTapStart:function(e){if(e.cancelable){var t=this,s=this.el,i=this.options,n=i.preventOnFilter,o=e.type,a=e.touches&&e.touches[0]||e.pointerType&&"touch"===e.pointerType&&e,r=(a||e).target,l=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||r,c=i.filter;if(function(e){ke.length=0;for(var t=e.getElementsByTagName("input"),s=t.length;s--;){var i=t[s];i.checked&&ke.push(i)}}(s),!U&&!(/mousedown|pointerdown/.test(o)&&0!==e.button||i.disabled)&&!l.isContentEditable&&(this.nativeDraggable||!h||!r||"SELECT"!==r.tagName.toUpperCase())&&!((r=w(r,i.draggable,s,!1))&&r.animated||K===r)){if(te=q(r),ie=q(r,i.draggable),"function"==typeof c){if(c.call(this,e,r,this))return V({sortable:t,rootEl:l,name:"filter",targetEl:r,toEl:s,fromEl:s}),j("filter",t,{evt:e}),void(n&&e.preventDefault())}else if(c&&(c=c.split(",").some(function(i){if(i=w(l,i.trim(),s,!1))return V({sortable:t,rootEl:i,name:"filter",targetEl:r,fromEl:s,toEl:s}),j("filter",t,{evt:e}),!0})))return void(n&&e.preventDefault());i.handle&&!w(l,i.handle,s,!1)||this._prepareDragStart(e,a,r)}}},_prepareDragStart:function(e,t,s){var i,n=this,o=n.el,a=n.options,r=o.ownerDocument;if(s&&!U&&s.parentNode===o){var l=T(s);if(G=o,X=(U=s).parentNode,Y=U.nextSibling,K=s,oe=a.group,ze.dragged=U,re={target:U,clientX:(t||e).clientX,clientY:(t||e).clientY},ue=re.clientX-l.left,he=re.clientY-l.top,this._lastX=(t||e).clientX,this._lastY=(t||e).clientY,U.style["will-change"]="all",i=function(){j("delayEnded",n,{evt:e}),ze.eventCanceled?n._onDrop():(n._disableDelayedDragEvents(),!u&&n.nativeDraggable&&(U.draggable=!0),n._triggerDragStart(e,t),V({sortable:n,name:"choose",originalEvent:e}),S(U,a.chosenClass,!0))},a.ignore.split(",").forEach(function(e){A(U,e.trim(),Fe)}),f(r,"dragover",Me),f(r,"mousemove",Me),f(r,"touchmove",Me),a.supportPointer?(f(r,"pointerup",n._onDrop),!this.nativeDraggable&&f(r,"pointercancel",n._onDrop)):(f(r,"mouseup",n._onDrop),f(r,"touchend",n._onDrop),f(r,"touchcancel",n._onDrop)),u&&this.nativeDraggable&&(this.options.touchStartThreshold=4,U.draggable=!0),j("delayStart",this,{evt:e}),!a.delay||a.delayOnTouchOnly&&!t||this.nativeDraggable&&(d||c))i();else{if(ze.eventCanceled)return void this._onDrop();a.supportPointer?(f(r,"pointerup",n._disableDelayedDrag),f(r,"pointercancel",n._disableDelayedDrag)):(f(r,"mouseup",n._disableDelayedDrag),f(r,"touchend",n._disableDelayedDrag),f(r,"touchcancel",n._disableDelayedDrag)),f(r,"mousemove",n._delayedDragTouchMoveHandler),f(r,"touchmove",n._delayedDragTouchMoveHandler),a.supportPointer&&f(r,"pointermove",n._delayedDragTouchMoveHandler),n._dragStartTimer=setTimeout(i,a.delay)}}},_delayedDragTouchMoveHandler:function(e){var t=e.touches?e.touches[0]:e;Math.max(Math.abs(t.clientX-this._lastX),Math.abs(t.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){U&&Fe(U),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var e=this.el.ownerDocument;b(e,"mouseup",this._disableDelayedDrag),b(e,"touchend",this._disableDelayedDrag),b(e,"touchcancel",this._disableDelayedDrag),b(e,"pointerup",this._disableDelayedDrag),b(e,"pointercancel",this._disableDelayedDrag),b(e,"mousemove",this._delayedDragTouchMoveHandler),b(e,"touchmove",this._delayedDragTouchMoveHandler),b(e,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(e,t){t=t||"touch"==e.pointerType&&e,!this.nativeDraggable||t?this.options.supportPointer?f(document,"pointermove",this._onTouchMove):f(document,t?"touchmove":"mousemove",this._onTouchMove):(f(U,"dragend",this),f(G,"dragstart",this._onDragStart));try{document.selection?Ne(function(){document.selection.empty()}):window.getSelection().removeAllRanges()}catch(e){}},_dragStarted:function(e,t){if(ve=!1,G&&U){j("dragStarted",this,{evt:t}),this.nativeDraggable&&f(document,"dragover",Oe);var s=this.options;!e&&S(U,s.dragClass,!1),S(U,s.ghostClass,!0),ze.active=this,e&&this._appendGhost(),V({sortable:this,name:"start",originalEvent:t})}else this._nulling()},_emulateDragOver:function(){if(le){this._lastX=le.clientX,this._lastY=le.clientY,Be();for(var e=document.elementFromPoint(le.clientX,le.clientY),t=e;e&&e.shadowRoot&&(e=e.shadowRoot.elementFromPoint(le.clientX,le.clientY))!==t;)t=e;if(U.parentNode[H]._isOutsideThisEl(e),t)do{if(t[H]&&t[H]._onDragOver({clientX:le.clientX,clientY:le.clientY,target:e,rootEl:t})&&!this.options.dragoverBubble)break;e=t}while(t=y(t));Pe()}},_onTouchMove:function(e){if(re){var t=this.options,s=t.fallbackTolerance,i=t.fallbackOffset,n=e.touches?e.touches[0]:e,o=J&&k(J,!0),a=J&&o&&o.a,r=J&&o&&o.d,l=Ee&&be&&B(be),c=(n.clientX-re.clientX+i.x)/(a||1)+(l?l[0]-Se[0]:0)/(a||1),d=(n.clientY-re.clientY+i.y)/(r||1)+(l?l[1]-Se[1]:0)/(r||1);if(!ze.active&&!ve){if(s&&Math.max(Math.abs(n.clientX-this._lastX),Math.abs(n.clientY-this._lastY))<s)return;this._onDragStart(e,!0)}if(J){o?(o.e+=c-(ce||0),o.f+=d-(de||0)):o={a:1,b:0,c:0,d:1,e:c,f:d};var u="matrix(".concat(o.a,",").concat(o.b,",").concat(o.c,",").concat(o.d,",").concat(o.e,",").concat(o.f,")");C(J,"webkitTransform",u),C(J,"mozTransform",u),C(J,"msTransform",u),C(J,"transform",u),ce=c,de=d,le=n}e.cancelable&&e.preventDefault()}},_appendGhost:function(){if(!J){var e=this.options.fallbackOnBody?document.body:G,t=T(U,!0,Ee,!0,e),s=this.options;if(Ee){for(be=e;"static"===C(be,"position")&&"none"===C(be,"transform")&&be!==document;)be=be.parentNode;be!==document.body&&be!==document.documentElement?(be===document&&(be=E()),t.top+=be.scrollTop,t.left+=be.scrollLeft):be=E(),Se=B(be)}S(J=U.cloneNode(!0),s.ghostClass,!1),S(J,s.fallbackClass,!0),S(J,s.dragClass,!0),C(J,"transition",""),C(J,"transform",""),C(J,"box-sizing","border-box"),C(J,"margin",0),C(J,"top",t.top),C(J,"left",t.left),C(J,"width",t.width),C(J,"height",t.height),C(J,"opacity","0.8"),C(J,"position",Ee?"absolute":"fixed"),C(J,"zIndex","100000"),C(J,"pointerEvents","none"),ze.ghost=J,e.appendChild(J),C(J,"transform-origin",ue/parseInt(J.style.width)*100+"% "+he/parseInt(J.style.height)*100+"%")}},_onDragStart:function(e,t){var s=this,i=e.dataTransfer,n=s.options;j("dragStart",this,{evt:e}),ze.eventCanceled?this._onDrop():(j("setupClone",this),ze.eventCanceled||((Z=$(U)).removeAttribute("id"),Z.draggable=!1,Z.style["will-change"]="",this._hideClone(),S(Z,this.options.chosenClass,!1),ze.clone=Z),s.cloneId=Ne(function(){j("clone",s),ze.eventCanceled||(s.options.removeCloneOnHide||G.insertBefore(Z,U),s._hideClone(),V({sortable:s,name:"clone"}))}),!t&&S(U,n.dragClass,!0),t?(ye=!0,s._loopId=setInterval(s._emulateDragOver,50)):(b(document,"mouseup",s._onDrop),b(document,"touchend",s._onDrop),b(document,"touchcancel",s._onDrop),i&&(i.effectAllowed="move",n.setData&&n.setData.call(s,i,U)),f(document,"drop",s),C(U,"transform","translateZ(0)")),ve=!0,s._dragStartId=Ne(s._dragStarted.bind(s,t,e)),f(document,"selectstart",s),pe=!0,window.getSelection().removeAllRanges(),h&&C(document.body,"user-select","none"))},_onDragOver:function(e){var t,s,i,n,o=this.el,r=e.target,l=this.options,c=l.group,d=ze.active,u=oe===c,h=l.sort,p=ae||d,m=this,g=!1;if(!Ce){if(void 0!==e.preventDefault&&e.cancelable&&e.preventDefault(),r=w(r,l.draggable,o,!0),Q("dragOver"),ze.eventCanceled)return g;if(U.contains(e.target)||r.animated&&r.animatingX&&r.animatingY||m._ignoreWhileAnimating===r)return R(!1);if(ye=!1,d&&!l.disabled&&(u?h||(i=X!==G):ae===this||(this.lastPutMode=oe.checkPull(this,d,U,e))&&c.checkPut(this,d,U,e))){if(n="vertical"===this._getDirection(e,r),t=T(U),Q("dragOverValid"),ze.eventCanceled)return g;if(i)return X=G,N(),this._hideClone(),Q("revert"),ze.eventCanceled||(Y?G.insertBefore(U,Y):G.appendChild(U)),R(!0);var f=D(o,l.draggable);if(!f||function(e,t,s){var i=T(D(s.el,s.options.draggable)),n=F(s.el,s.options,J);return t?e.clientX>n.right+10||e.clientY>i.bottom&&e.clientX>i.left:e.clientY>n.bottom+10||e.clientX>i.right&&e.clientY>i.top}(e,n,this)&&!f.animated){if(f===U)return R(!1);if(f&&o===e.target&&(r=f),r&&(s=T(r)),!1!==$e(G,o,U,t,r,s,e,!!r))return N(),f&&f.nextSibling?o.insertBefore(U,f.nextSibling):o.appendChild(U),X=o,W(),R(!0)}else if(f&&function(e,t,s){var i=T(I(s.el,0,s.options,!0)),n=F(s.el,s.options,J);return t?e.clientX<n.left-10||e.clientY<i.top&&e.clientX<i.right:e.clientY<n.top-10||e.clientY<i.bottom&&e.clientX<i.left}(e,n,this)){var b=I(o,0,l,!0);if(b===U)return R(!1);if(s=T(r=b),!1!==$e(G,o,U,t,r,s,e,!1))return N(),o.insertBefore(U,b),X=o,W(),R(!0)}else if(r.parentNode===o){s=T(r);var v,y,_,x=U.parentNode!==o,k=!function(e,t,s){var i=s?e.left:e.top,n=s?e.right:e.bottom,o=s?e.width:e.height,a=s?t.left:t.top,r=s?t.right:t.bottom,l=s?t.width:t.height;return i===a||n===r||i+o/2===a+l/2}(U.animated&&U.toRect||t,r.animated&&r.toRect||s,n),A=n?"top":"left",E=L(r,"top","top")||L(U,"top","top"),B=E?E.scrollTop:void 0;if(me!==r&&(y=s[A],_e=!1,xe=!k&&l.invertSwap||x),v=function(e,t,s,i,n,o,a,r){var l=i?e.clientY:e.clientX,c=i?s.height:s.width,d=i?s.top:s.left,u=i?s.bottom:s.right,h=!1;if(!a)if(r&&fe<c*n){if(!_e&&(1===ge?l>d+c*o/2:l<u-c*o/2)&&(_e=!0),_e)h=!0;else if(1===ge?l<d+fe:l>u-fe)return-ge}else if(l>d+c*(1-n)/2&&l<u-c*(1-n)/2)return function(e){return q(U)<q(e)?1:-1}(t);return(h=h||a)&&(l<d+c*o/2||l>u-c*o/2)?l>d+c/2?1:-1:0}(e,r,s,n,k?1:l.swapThreshold,null==l.invertedSwapThreshold?l.swapThreshold:l.invertedSwapThreshold,xe,me===r),0!==v){var P=q(U);do{P-=v,_=X.children[P]}while(_&&("none"===C(_,"display")||_===J))}if(0===v||_===r)return R(!1);me=r,ge=v;var M=r.nextElementSibling,O=!1,$=$e(G,o,U,t,r,s,e,O=1===v);if(!1!==$)return 1!==$&&-1!==$||(O=1===$),Ce=!0,setTimeout(He,30),N(),O&&!M?o.appendChild(U):r.parentNode.insertBefore(U,O?M:r),E&&z(E,0,B-E.scrollTop),X=U.parentNode,void 0===y||xe||(fe=Math.abs(y-T(r)[A])),W(),R(!0)}if(o.contains(U))return R(!1)}return!1}function Q(l,c){j(l,m,a({evt:e,isOwner:u,axis:n?"vertical":"horizontal",revert:i,dragRect:t,targetRect:s,canSort:h,fromSortable:p,target:r,completed:R,onMove:function(s,i){return $e(G,o,U,t,s,T(s),e,i)},changed:W},c))}function N(){Q("dragOverAnimationCapture"),m.captureAnimationState(),m!==p&&p.captureAnimationState()}function R(t){return Q("dragOverCompleted",{insertion:t}),t&&(u?d._hideClone():d._showClone(m),m!==p&&(S(U,ae?ae.options.ghostClass:d.options.ghostClass,!1),S(U,l.ghostClass,!0)),ae!==m&&m!==ze.active?ae=m:m===ze.active&&ae&&(ae=null),p===m&&(m._ignoreWhileAnimating=r),m.animateAll(function(){Q("dragOverAnimationComplete"),m._ignoreWhileAnimating=null}),m!==p&&(p.animateAll(),p._ignoreWhileAnimating=null)),(r===U&&!U.animated||r===o&&!r.animated)&&(me=null),l.dragoverBubble||e.rootEl||r===document||(U.parentNode[H]._isOutsideThisEl(e.target),!t&&Me(e)),!l.dragoverBubble&&e.stopPropagation&&e.stopPropagation(),g=!0}function W(){se=q(U),ne=q(U,l.draggable),V({sortable:m,name:"change",toEl:o,newIndex:se,newDraggableIndex:ne,originalEvent:e})}},_ignoreWhileAnimating:null,_offMoveEvents:function(){b(document,"mousemove",this._onTouchMove),b(document,"touchmove",this._onTouchMove),b(document,"pointermove",this._onTouchMove),b(document,"dragover",Me),b(document,"mousemove",Me),b(document,"touchmove",Me)},_offUpEvents:function(){var e=this.el.ownerDocument;b(e,"mouseup",this._onDrop),b(e,"touchend",this._onDrop),b(e,"pointerup",this._onDrop),b(e,"pointercancel",this._onDrop),b(e,"touchcancel",this._onDrop),b(document,"selectstart",this)},_onDrop:function(e){var t=this.el,s=this.options;se=q(U),ne=q(U,s.draggable),j("drop",this,{evt:e}),X=U&&U.parentNode,se=q(U),ne=q(U,s.draggable),ze.eventCanceled||(ve=!1,xe=!1,_e=!1,clearInterval(this._loopId),clearTimeout(this._dragStartTimer),Re(this.cloneId),Re(this._dragStartId),this.nativeDraggable&&(b(document,"drop",this),b(t,"dragstart",this._onDragStart)),this._offMoveEvents(),this._offUpEvents(),h&&C(document.body,"user-select",""),C(U,"transform",""),e&&(pe&&(e.cancelable&&e.preventDefault(),!s.dropBubble&&e.stopPropagation()),J&&J.parentNode&&J.parentNode.removeChild(J),(G===X||ae&&"clone"!==ae.lastPutMode)&&Z&&Z.parentNode&&Z.parentNode.removeChild(Z),U&&(this.nativeDraggable&&b(U,"dragend",this),Fe(U),U.style["will-change"]="",pe&&!ve&&S(U,ae?ae.options.ghostClass:this.options.ghostClass,!1),S(U,this.options.chosenClass,!1),V({sortable:this,name:"unchoose",toEl:X,newIndex:null,newDraggableIndex:null,originalEvent:e}),G!==X?(se>=0&&(V({rootEl:X,name:"add",toEl:X,fromEl:G,originalEvent:e}),V({sortable:this,name:"remove",toEl:X,originalEvent:e}),V({rootEl:X,name:"sort",toEl:X,fromEl:G,originalEvent:e}),V({sortable:this,name:"sort",toEl:X,originalEvent:e})),ae&&ae.save()):se!==te&&se>=0&&(V({sortable:this,name:"update",toEl:X,originalEvent:e}),V({sortable:this,name:"sort",toEl:X,originalEvent:e})),ze.active&&(null!=se&&-1!==se||(se=te,ne=ie),V({sortable:this,name:"end",toEl:X,originalEvent:e}),this.save())))),this._nulling()},_nulling:function(){j("nulling",this),G=U=X=J=Y=Z=K=ee=re=le=pe=se=ne=te=ie=me=ge=ae=oe=ze.dragged=ze.ghost=ze.clone=ze.active=null;var e=this.el;ke.forEach(function(t){e.contains(t)&&(t.checked=!0)}),ke.length=ce=de=0},handleEvent:function(e){switch(e.type){case"drop":case"dragend":this._onDrop(e);break;case"dragenter":case"dragover":U&&(this._onDragOver(e),function(e){e.dataTransfer&&(e.dataTransfer.dropEffect="move"),e.cancelable&&e.preventDefault()}(e));break;case"selectstart":e.preventDefault()}},toArray:function(){for(var e,t=[],s=this.el.children,i=0,n=s.length,o=this.options;i<n;i++)w(e=s[i],o.draggable,this.el,!1)&&t.push(e.getAttribute(o.dataIdAttr)||Qe(e));return t},sort:function(e,t){var s={},i=this.el;this.toArray().forEach(function(e,t){var n=i.children[t];w(n,this.options.draggable,i,!1)&&(s[e]=n)},this),t&&this.captureAnimationState(),e.forEach(function(e){s[e]&&(i.removeChild(s[e]),i.appendChild(s[e]))}),t&&this.animateAll()},save:function(){var e=this.options.store;e&&e.set&&e.set(this)},closest:function(e,t){return w(e,t||this.options.draggable,this.el,!1)},option:function(e,t){var s=this.options;if(void 0===t)return s[e];var i=R.modifyOption(this,e,t);s[e]=void 0!==i?i:t,"group"===e&&qe(s)},destroy:function(){j("destroy",this);var e=this.el;e[H]=null,b(e,"mousedown",this._onTapStart),b(e,"touchstart",this._onTapStart),b(e,"pointerdown",this._onTapStart),this.nativeDraggable&&(b(e,"dragover",this),b(e,"dragenter",this)),Array.prototype.forEach.call(e.querySelectorAll("[draggable]"),function(e){e.removeAttribute("draggable")}),this._onDrop(),this._disableDelayedDragEvents(),we.splice(we.indexOf(this.el),1),this.el=e=null},_hideClone:function(){if(!ee){if(j("hideClone",this),ze.eventCanceled)return;C(Z,"display","none"),this.options.removeCloneOnHide&&Z.parentNode&&Z.parentNode.removeChild(Z),ee=!0}},_showClone:function(e){if("clone"===e.lastPutMode){if(ee){if(j("showClone",this),ze.eventCanceled)return;U.parentNode!=G||this.options.group.revertClone?Y?G.insertBefore(Z,Y):G.appendChild(Z):G.insertBefore(Z,U),this.options.group.revertClone&&this.animate(U,Z),C(Z,"display",""),ee=!1}}else this._hideClone()}},Ae&&f(document,"touchmove",function(e){(ze.active||ve)&&e.cancelable&&e.preventDefault()}),ze.utils={on:f,off:b,css:C,find:A,is:function(e,t){return!!w(e,t,e,!1)},extend:function(e,t){if(e&&t)for(var s in t)t.hasOwnProperty(s)&&(e[s]=t[s]);return e},throttle:O,closest:w,toggleClass:S,clone:$,index:q,nextTick:Ne,cancelNextTick:Re,detectDirection:De,getChild:I,expando:H},ze.get=function(e){return e[H]},ze.mount=function(){for(var e=arguments.length,t=new Array(e),s=0;s<e;s++)t[s]=arguments[s];t[0].constructor===Array&&(t=t[0]),t.forEach(function(e){if(!e.prototype||!e.prototype.constructor)throw"Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(e));e.utils&&(ze.utils=a(a({},ze.utils),e.utils)),R.mount(e)})},ze.create=function(e,t){return new ze(e,t)},ze.version="1.15.7";var We,je,Ve,Ue,Xe,Je,Ge=[],Ye=!1;function Ke(){Ge.forEach(function(e){clearInterval(e.pid)}),Ge=[]}function Ze(){clearInterval(Je)}var et=O(function(e,t,s,i){if(t.scroll){var n,o=(e.touches?e.touches[0]:e).clientX,a=(e.touches?e.touches[0]:e).clientY,r=t.scrollSensitivity,l=t.scrollSpeed,c=E(),d=!1;je!==s&&(je=s,Ke(),We=t.scroll,n=t.scrollFn,!0===We&&(We=P(s,!0)));var u=0,h=We;do{var p=h,m=T(p),g=m.top,f=m.bottom,b=m.left,v=m.right,y=m.width,w=m.height,_=void 0,x=void 0,S=p.scrollWidth,k=p.scrollHeight,A=C(p),L=p.scrollLeft,I=p.scrollTop;p===c?(_=y<S&&("auto"===A.overflowX||"scroll"===A.overflowX||"visible"===A.overflowX),x=w<k&&("auto"===A.overflowY||"scroll"===A.overflowY||"visible"===A.overflowY)):(_=y<S&&("auto"===A.overflowX||"scroll"===A.overflowX),x=w<k&&("auto"===A.overflowY||"scroll"===A.overflowY));var D=_&&(Math.abs(v-o)<=r&&L+y<S)-(Math.abs(b-o)<=r&&!!L),q=x&&(Math.abs(f-a)<=r&&I+w<k)-(Math.abs(g-a)<=r&&!!I);if(!Ge[u])for(var B=0;B<=u;B++)Ge[B]||(Ge[B]={});Ge[u].vx==D&&Ge[u].vy==q&&Ge[u].el===p||(Ge[u].el=p,Ge[u].vx=D,Ge[u].vy=q,clearInterval(Ge[u].pid),0==D&&0==q||(d=!0,Ge[u].pid=setInterval(function(){i&&0===this.layer&&ze.active._onTouchMove(Xe);var t=Ge[this.layer].vy?Ge[this.layer].vy*l:0,s=Ge[this.layer].vx?Ge[this.layer].vx*l:0;"function"==typeof n&&"continue"!==n.call(ze.dragged.parentNode[H],s,t,e,Xe,Ge[this.layer].el)||z(Ge[this.layer].el,s,t)}.bind({layer:u}),24))),u++}while(t.bubbleScroll&&h!==c&&(h=P(h,!1)));Ye=d}},30),tt=function(e){var t=e.originalEvent,s=e.putSortable,i=e.dragEl,n=e.activeSortable,o=e.dispatchSortableEvent,a=e.hideGhostForTarget,r=e.unhideGhostForTarget;if(t){var l=s||n;a();var c=t.changedTouches&&t.changedTouches.length?t.changedTouches[0]:t,d=document.elementFromPoint(c.clientX,c.clientY);r(),l&&!l.el.contains(d)&&(o("spill"),this.onSpill({dragEl:i,putSortable:s}))}};function st(){}function it(){}st.prototype={startIndex:null,dragStart:function(e){var t=e.oldDraggableIndex;this.startIndex=t},onSpill:function(e){var t=e.dragEl,s=e.putSortable;this.sortable.captureAnimationState(),s&&s.captureAnimationState();var i=I(this.sortable.el,this.startIndex,this.options);i?this.sortable.el.insertBefore(t,i):this.sortable.el.appendChild(t),this.sortable.animateAll(),s&&s.animateAll()},drop:tt},n(st,{pluginName:"revertOnSpill"}),it.prototype={onSpill:function(e){var t=e.dragEl,s=e.putSortable||this.sortable;s.captureAnimationState(),t.parentNode&&t.parentNode.removeChild(t),s.animateAll()},drop:tt},n(it,{pluginName:"removeOnSpill"}),ze.mount(new function(){function e(){for(var e in this.defaults={scroll:!0,forceAutoScrollFallback:!1,scrollSensitivity:30,scrollSpeed:10,bubbleScroll:!0},this)"_"===e.charAt(0)&&"function"==typeof this[e]&&(this[e]=this[e].bind(this))}return e.prototype={dragStarted:function(e){var t=e.originalEvent;this.sortable.nativeDraggable?f(document,"dragover",this._handleAutoScroll):this.options.supportPointer?f(document,"pointermove",this._handleFallbackAutoScroll):t.touches?f(document,"touchmove",this._handleFallbackAutoScroll):f(document,"mousemove",this._handleFallbackAutoScroll)},dragOverCompleted:function(e){var t=e.originalEvent;this.options.dragOverBubble||t.rootEl||this._handleAutoScroll(t)},drop:function(){this.sortable.nativeDraggable?b(document,"dragover",this._handleAutoScroll):(b(document,"pointermove",this._handleFallbackAutoScroll),b(document,"touchmove",this._handleFallbackAutoScroll),b(document,"mousemove",this._handleFallbackAutoScroll)),Ze(),Ke(),clearTimeout(_),_=void 0},nulling:function(){Xe=je=We=Ye=Je=Ve=Ue=null,Ge.length=0},_handleFallbackAutoScroll:function(e){this._handleAutoScroll(e,!0)},_handleAutoScroll:function(e,t){var s=this,i=(e.touches?e.touches[0]:e).clientX,n=(e.touches?e.touches[0]:e).clientY,o=document.elementFromPoint(i,n);if(Xe=e,t||this.options.forceAutoScrollFallback||d||c||h){et(e,this.options,o,t);var a=P(o,!0);!Ye||Je&&i===Ve&&n===Ue||(Je&&Ze(),Je=setInterval(function(){var o=P(document.elementFromPoint(i,n),!0);o!==a&&(a=o,Ke()),et(e,s.options,o,t)},10),Ve=i,Ue=n)}else{if(!this.options.bubbleScroll||P(o,!0)===E())return void Ke();et(e,this.options,P(o,!1),!1)}}},n(e,{pluginName:"scroll",initializeByDefault:!0})}),ze.mount(it,st);const nt=ze},4316(e,t,s){"use strict";var i=s(5072),n=s.n(i),o=s(7825),a=s.n(o),r=s(7659),l=s.n(r),c=s(5056),d=s.n(c),u=s(540),h=s.n(u),p=s(1113),m=s.n(p),g=s(9455),f={};f.styleTagTransform=m(),f.setAttributes=d(),f.insert=l().bind(null,"head"),f.domAPI=a(),f.insertStyleElement=h(),n()(g.A,f),g.A&&g.A.locals&&g.A.locals},5072(e){"use strict";var t=[];function s(e){for(var s=-1,i=0;i<t.length;i++)if(t[i].identifier===e){s=i;break}return s}function i(e,i){for(var o={},a=[],r=0;r<e.length;r++){var l=e[r],c=i.base?l[0]+i.base:l[0],d=o[c]||0,u="".concat(c," ").concat(d);o[c]=d+1;var h=s(u),p={css:l[1],media:l[2],sourceMap:l[3],supports:l[4],layer:l[5]};if(-1!==h)t[h].references++,t[h].updater(p);else{var m=n(p,i);i.byIndex=r,t.splice(r,0,{identifier:u,updater:m,references:1})}a.push(u)}return a}function n(e,t){var s=t.domAPI(t);return s.update(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap&&t.supports===e.supports&&t.layer===e.layer)return;s.update(e=t)}else s.remove()}}e.exports=function(e,n){var o=i(e=e||[],n=n||{});return function(e){e=e||[];for(var a=0;a<o.length;a++){var r=s(o[a]);t[r].references--}for(var l=i(e,n),c=0;c<o.length;c++){var d=s(o[c]);0===t[d].references&&(t[d].updater(),t.splice(d,1))}o=l}}},7659(e){"use strict";var t={};e.exports=function(e,s){var i=function(e){if(void 0===t[e]){var s=document.querySelector(e);if(window.HTMLIFrameElement&&s instanceof window.HTMLIFrameElement)try{s=s.contentDocument.head}catch(e){s=null}t[e]=s}return t[e]}(e);if(!i)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");i.appendChild(s)}},540(e){"use strict";e.exports=function(e){var t=document.createElement("style");return e.setAttributes(t,e.attributes),e.insert(t,e.options),t}},5056(e,t,s){"use strict";e.exports=function(e){var t=s.nc;t&&e.setAttribute("nonce",t)}},7825(e){"use strict";e.exports=function(e){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var t=e.insertStyleElement(e);return{update:function(s){!function(e,t,s){var i="";s.supports&&(i+="@supports (".concat(s.supports,") {")),s.media&&(i+="@media ".concat(s.media," {"));var n=void 0!==s.layer;n&&(i+="@layer".concat(s.layer.length>0?" ".concat(s.layer):""," {")),i+=s.css,n&&(i+="}"),s.media&&(i+="}"),s.supports&&(i+="}");var o=s.sourceMap;o&&"undefined"!=typeof btoa&&(i+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(o))))," */")),t.styleTagTransform(i,e,t.options)}(t,e,s)},remove:function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(t)}}}},1113(e){"use strict";e.exports=function(e,t){if(t.styleSheet)t.styleSheet.cssText=e;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(e))}}},8465(e){e.exports=function(){"use strict";function e(e,t,s){if("function"==typeof e?e===t:e.has(t))return arguments.length<3?t:s;throw new TypeError("Private element is not present on this object")}function t(t,s){return t.get(e(t,s))}function s(e,t,s){(function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")})(e,t),t.set(e,s)}const i={},n=e=>new Promise(t=>{if(!e)return t();const s=window.scrollX,n=window.scrollY;i.restoreFocusTimeout=setTimeout(()=>{i.previousActiveElement instanceof HTMLElement?(i.previousActiveElement.focus(),i.previousActiveElement=null):document.body&&document.body.focus(),t()},100),window.scrollTo(s,n)}),o="swal2-",a=["container","shown","height-auto","iosfix","popup","modal","no-backdrop","no-transition","toast","toast-shown","show","hide","close","title","html-container","actions","confirm","deny","cancel","footer","icon","icon-content","image","input","file","range","select","radio","checkbox","label","textarea","inputerror","input-label","validation-message","progress-steps","active-progress-step","progress-step","progress-step-line","loader","loading","styled","top","top-start","top-end","top-left","top-right","center","center-start","center-end","center-left","center-right","bottom","bottom-start","bottom-end","bottom-left","bottom-right","grow-row","grow-column","grow-fullscreen","rtl","timer-progress-bar","timer-progress-bar-container","scrollbar-measure","icon-success","icon-warning","icon-info","icon-question","icon-error","draggable","dragging"].reduce((e,t)=>(e[t]=o+t,e),{}),r=["success","warning","info","question","error"].reduce((e,t)=>(e[t]=o+t,e),{}),l="SweetAlert2:",c=e=>e.charAt(0).toUpperCase()+e.slice(1),d=e=>{console.warn(`${l} ${"object"==typeof e?e.join(" "):e}`)},u=e=>{console.error(`${l} ${e}`)},h=[],p=(e,t=null)=>{var s;s=`"${e}" is deprecated and will be removed in the next major release.${t?` Use "${t}" instead.`:""}`,h.includes(s)||(h.push(s),d(s))},m=e=>"function"==typeof e?e():e,g=e=>e&&"function"==typeof e.toPromise,f=e=>g(e)?e.toPromise():Promise.resolve(e),b=e=>e&&Promise.resolve(e)===e,v=()=>document.body.querySelector(`.${a.container}`),y=e=>{const t=v();return t?t.querySelector(e):null},w=e=>y(`.${e}`),_=()=>w(a.popup),x=()=>w(a.icon),S=()=>w(a.title),C=()=>w(a["html-container"]),k=()=>w(a.image),A=()=>w(a["progress-steps"]),E=()=>w(a["validation-message"]),T=()=>y(`.${a.actions} .${a.confirm}`),L=()=>y(`.${a.actions} .${a.cancel}`),I=()=>y(`.${a.actions} .${a.deny}`),D=()=>y(`.${a.loader}`),q=()=>w(a.actions),B=()=>w(a.footer),P=()=>w(a["timer-progress-bar"]),M=()=>w(a.close),O=()=>{const e=_();if(!e)return[];const t=e.querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])'),s=Array.from(t).sort((e,t)=>{const s=parseInt(e.getAttribute("tabindex")||"0"),i=parseInt(t.getAttribute("tabindex")||"0");return s>i?1:s<i?-1:0}),i=e.querySelectorAll('\n a[href],\n area[href],\n input:not([disabled]),\n select:not([disabled]),\n textarea:not([disabled]),\n button:not([disabled]),\n iframe,\n object,\n embed,\n [tabindex="0"],\n [contenteditable],\n audio[controls],\n video[controls],\n summary\n'),n=Array.from(i).filter(e=>"-1"!==e.getAttribute("tabindex"));return[...new Set(s.concat(n))].filter(e=>ee(e))},z=()=>H(document.body,a.shown)&&!H(document.body,a["toast-shown"])&&!H(document.body,a["no-backdrop"]),$=()=>{const e=_();return!!e&&H(e,a.toast)},F=(e,t)=>{if(e.textContent="",t){const s=(new DOMParser).parseFromString(t,"text/html"),i=s.querySelector("head");i&&Array.from(i.childNodes).forEach(t=>{e.appendChild(t)});const n=s.querySelector("body");n&&Array.from(n.childNodes).forEach(t=>{t instanceof HTMLVideoElement||t instanceof HTMLAudioElement?e.appendChild(t.cloneNode(!0)):e.appendChild(t)})}},H=(e,t)=>{if(!t)return!1;const s=t.split(/\s+/);for(let t=0;t<s.length;t++)if(!e.classList.contains(s[t]))return!1;return!0},Q=(e,t,s)=>{if(((e,t)=>{Array.from(e.classList).forEach(s=>{Object.values(a).includes(s)||Object.values(r).includes(s)||Object.values(t.showClass||{}).includes(s)||e.classList.remove(s)})})(e,t),!t.customClass)return;const i=t.customClass[s];i&&("string"==typeof i||i.forEach?j(e,i):d(`Invalid type of customClass.${s}! Expected string or iterable object, got "${typeof i}"`))},N=(e,t)=>{if(!t)return null;switch(t){case"select":case"textarea":case"file":return e.querySelector(`.${a.popup} > .${a[t]}`);case"checkbox":return e.querySelector(`.${a.popup} > .${a.checkbox} input`);case"radio":return e.querySelector(`.${a.popup} > .${a.radio} input:checked`)||e.querySelector(`.${a.popup} > .${a.radio} input:first-child`);case"range":return e.querySelector(`.${a.popup} > .${a.range} input`);default:return e.querySelector(`.${a.popup} > .${a.input}`)}},R=e=>{if(e.focus(),"file"!==e.type){const t=e.value;e.value="",e.value=t}},W=(e,t,s)=>{e&&t&&("string"==typeof t&&(t=t.split(/\s+/).filter(Boolean)),t.forEach(t=>{Array.isArray(e)?e.forEach(e=>{s?e.classList.add(t):e.classList.remove(t)}):s?e.classList.add(t):e.classList.remove(t)}))},j=(e,t)=>{W(e,t,!0)},V=(e,t)=>{W(e,t,!1)},U=(e,t)=>{const s=Array.from(e.children);for(let e=0;e<s.length;e++){const i=s[e];if(i instanceof HTMLElement&&H(i,t))return i}},X=(e,t,s)=>{s===`${parseInt(`${s}`)}`&&(s=parseInt(s)),s||0===parseInt(`${s}`)?e.style.setProperty(t,"number"==typeof s?`${s}px`:s):e.style.removeProperty(t)},J=(e,t="flex")=>{e&&(e.style.display=t)},G=e=>{e&&(e.style.display="none")},Y=(e,t="block")=>{e&&new MutationObserver(()=>{Z(e,e.innerHTML,t)}).observe(e,{childList:!0,subtree:!0})},K=(e,t,s,i)=>{const n=e.querySelector(t);n&&n.style.setProperty(s,i)},Z=(e,t,s="flex")=>{t?J(e,s):G(e)},ee=e=>Boolean(e&&(e.offsetWidth||e.offsetHeight||e.getClientRects().length)),te=e=>Boolean(e.scrollHeight>e.clientHeight),se=e=>{const t=window.getComputedStyle(e),s=parseFloat(t.getPropertyValue("animation-duration")||"0"),i=parseFloat(t.getPropertyValue("transition-duration")||"0");return s>0||i>0},ie=(e,t=!1)=>{const s=P();s&&ee(s)&&(t&&(s.style.transition="none",s.style.width="100%"),setTimeout(()=>{s.style.transition=`width ${e/1e3}s linear`,s.style.width="0%"},10))},ne=`\n <div aria-labelledby="${a.title}" aria-describedby="${a["html-container"]}" class="${a.popup}" tabindex="-1">\n <button type="button" class="${a.close}"></button>\n <ul class="${a["progress-steps"]}"></ul>\n <div class="${a.icon}"></div>\n <img class="${a.image}" />\n <h2 class="${a.title}" id="${a.title}"></h2>\n <div class="${a["html-container"]}" id="${a["html-container"]}"></div>\n <input class="${a.input}" id="${a.input}" />\n <input type="file" class="${a.file}" />\n <div class="${a.range}">\n <input type="range" />\n <output></output>\n </div>\n <select class="${a.select}" id="${a.select}"></select>\n <div class="${a.radio}"></div>\n <label class="${a.checkbox}">\n <input type="checkbox" id="${a.checkbox}" />\n <span class="${a.label}"></span>\n </label>\n <textarea class="${a.textarea}" id="${a.textarea}"></textarea>\n <div class="${a["validation-message"]}" id="${a["validation-message"]}"></div>\n <div class="${a.actions}">\n <div class="${a.loader}"></div>\n <button type="button" class="${a.confirm}"></button>\n <button type="button" class="${a.deny}"></button>\n <button type="button" class="${a.cancel}"></button>\n </div>\n <div class="${a.footer}"></div>\n <div class="${a["timer-progress-bar-container"]}">\n <div class="${a["timer-progress-bar"]}"></div>\n </div>\n </div>\n`.replace(/(^|\n)\s*/g,""),oe=()=>{i.currentInstance&&i.currentInstance.resetValidationMessage()},ae=e=>{const t=(()=>{const e=v();return!!e&&(e.remove(),V([document.documentElement,document.body],[a["no-backdrop"],a["toast-shown"],a["has-column"]]),!0)})();if("undefined"==typeof window||"undefined"==typeof document)return void u("SweetAlert2 requires document to initialize");const s=document.createElement("div");s.className=a.container,t&&j(s,a["no-transition"]),F(s,ne),s.dataset.swal2Theme=e.theme;const n=(e=>{if("string"==typeof e){const t=document.querySelector(e);if(!t)throw new Error(`Target element "${e}" not found`);return t}return e})(e.target||"body");n.appendChild(s),e.topLayer&&(s.setAttribute("popover",""),s.showPopover()),(e=>{const t=_();t&&(t.setAttribute("role",e.toast?"alert":"dialog"),t.setAttribute("aria-live",e.toast?"polite":"assertive"),e.toast||t.setAttribute("aria-modal","true"))})(e),(e=>{"rtl"===window.getComputedStyle(e).direction&&(j(v(),a.rtl),i.isRTL=!0)})(n),(()=>{const e=_();if(!e)return;const t=U(e,a.input),s=U(e,a.file),i=e.querySelector(`.${a.range} input`),n=e.querySelector(`.${a.range} output`),o=U(e,a.select),r=e.querySelector(`.${a.checkbox} input`),l=U(e,a.textarea);t&&(t.oninput=oe),s&&(s.onchange=oe),o&&(o.onchange=oe),r&&(r.onchange=oe),l&&(l.oninput=oe),i&&n&&(i.oninput=()=>{oe(),n.value=i.value},i.onchange=()=>{oe(),n.value=i.value})})()},re=(e,t)=>{e instanceof HTMLElement?t.appendChild(e):"object"==typeof e?le(e,t):e&&F(t,e)},le=(e,t)=>{"jquery"in e?ce(t,e):F(t,e.toString())},ce=(e,t)=>{if(e.textContent="",0 in t)for(let s=0;s in t;s++)e.appendChild(t[s].cloneNode(!0));else e.appendChild(t.cloneNode(!0))},de=(e,t)=>{const s=q(),i=D();s&&i&&(t.showConfirmButton||t.showDenyButton||t.showCancelButton?J(s):G(s),Q(s,t,"actions"),function(e,t,s){const i=T(),n=I(),o=L();i&&n&&o&&(he(i,"confirm",s),he(n,"deny",s),he(o,"cancel",s),function(e,t,s,i){i.buttonsStyling?(j([e,t,s],a.styled),i.confirmButtonColor&&e.style.setProperty("--swal2-confirm-button-background-color",i.confirmButtonColor),i.denyButtonColor&&t.style.setProperty("--swal2-deny-button-background-color",i.denyButtonColor),i.cancelButtonColor&&s.style.setProperty("--swal2-cancel-button-background-color",i.cancelButtonColor),ue(e),ue(t),ue(s)):V([e,t,s],a.styled)}(i,n,o,s),s.reverseButtons&&(s.toast?(e.insertBefore(o,i),e.insertBefore(n,i)):(e.insertBefore(o,t),e.insertBefore(n,t),e.insertBefore(i,t))))}(s,i,t),F(i,t.loaderHtml||""),Q(i,t,"loader"))};function ue(e){const t=window.getComputedStyle(e);if(t.getPropertyValue("--swal2-action-button-focus-box-shadow"))return;const s=t.backgroundColor.replace(/rgba?\((\d+), (\d+), (\d+).*/,"rgba($1, $2, $3, 0.5)");e.style.setProperty("--swal2-action-button-focus-box-shadow",t.getPropertyValue("--swal2-outline").replace(/ rgba\(.*/,` ${s}`))}function he(e,t,s){const i=c(t);Z(e,s[`show${i}Button`],"inline-block"),F(e,s[`${t}ButtonText`]||""),e.setAttribute("aria-label",s[`${t}ButtonAriaLabel`]||""),e.className=a[t],Q(e,s,`${t}Button`)}const pe=(e,t)=>{const s=v();s&&(function(e,t){"string"==typeof t?e.style.background=t:t||j([document.documentElement,document.body],a["no-backdrop"])}(s,t.backdrop),function(e,t){t&&(t in a?j(e,a[t]):(d('The "position" parameter is not valid, defaulting to "center"'),j(e,a.center)))}(s,t.position),function(e,t){t&&j(e,a[`grow-${t}`])}(s,t.grow),Q(s,t,"container"))};var me={innerParams:new WeakMap,domCache:new WeakMap};const ge=["input","file","range","select","radio","checkbox","textarea"],fe=e=>{if(!e.input)return;if(!Se[e.input])return void u(`Unexpected type of input! Expected ${Object.keys(Se).join(" | ")}, got "${e.input}"`);const t=_e(e.input);if(!t)return;const s=Se[e.input](t,e);J(t),e.inputAutoFocus&&setTimeout(()=>{R(s)})},be=(e,t)=>{const s=_();if(!s)return;const i=N(s,e);if(i){(e=>{for(let t=0;t<e.attributes.length;t++){const s=e.attributes[t].name;["id","type","value","style"].includes(s)||e.removeAttribute(s)}})(i);for(const e in t)i.setAttribute(e,t[e])}},ve=e=>{if(!e.input)return;const t=_e(e.input);t&&Q(t,e,"input")},ye=(e,t)=>{!e.placeholder&&t.inputPlaceholder&&(e.placeholder=t.inputPlaceholder)},we=(e,t,s)=>{if(s.inputLabel){const i=document.createElement("label"),n=a["input-label"];i.setAttribute("for",e.id),i.className=n,"object"==typeof s.customClass&&j(i,s.customClass.inputLabel),i.innerText=s.inputLabel,t.insertAdjacentElement("beforebegin",i)}},_e=e=>{const t=_();if(t)return U(t,a[e]||a.input)},xe=(e,t)=>{["string","number"].includes(typeof t)?e.value=`${t}`:b(t)||d(`Unexpected type of inputValue! Expected "string", "number" or "Promise", got "${typeof t}"`)},Se={};Se.text=Se.email=Se.password=Se.number=Se.tel=Se.url=Se.search=Se.date=Se["datetime-local"]=Se.time=Se.week=Se.month=(e,t)=>{const s=e;return xe(s,t.inputValue),we(s,s,t),ye(s,t),s.type=t.input,s},Se.file=(e,t)=>{const s=e;return we(s,s,t),ye(s,t),s},Se.range=(e,t)=>{const s=e,i=s.querySelector("input"),n=s.querySelector("output");return i&&(xe(i,t.inputValue),i.type=t.input,we(i,e,t)),n&&xe(n,t.inputValue),e},Se.select=(e,t)=>{const s=e;if(s.textContent="",t.inputPlaceholder){const e=document.createElement("option");F(e,t.inputPlaceholder),e.value="",e.disabled=!0,e.selected=!0,s.appendChild(e)}return we(s,s,t),s},Se.radio=e=>(e.textContent="",e),Se.checkbox=(e,t)=>{const s=_();if(!s)throw new Error("Popup not found");const i=N(s,"checkbox");if(!i)throw new Error("Checkbox input not found");i.value="1",i.checked=Boolean(t.inputValue);const n=e.querySelector("span");if(n){const e=t.inputPlaceholder||t.inputLabel;e&&F(n,e)}return i},Se.textarea=(e,t)=>{const s=e;xe(s,t.inputValue),ye(s,t),we(s,s,t);return setTimeout(()=>{if("MutationObserver"in window){const e=_();if(!e)return;const i=parseInt(window.getComputedStyle(e).width);new MutationObserver(()=>{if(!document.body.contains(s))return;const e=s.offsetWidth+(o=s,parseInt(window.getComputedStyle(o).marginLeft)+parseInt(window.getComputedStyle(o).marginRight)),n=_();var o;n&&(e>i?n.style.width=`${e}px`:X(n,"width",t.width))}).observe(s,{attributes:!0,attributeFilter:["style"]})}}),s};const Ce=(e,t)=>{const s=C();s&&(Y(s),Q(s,t,"htmlContainer"),t.html?(re(t.html,s),J(s,"block")):t.text?(s.textContent=t.text,J(s,"block")):G(s),((e,t)=>{const s=_();if(!s)return;const i=me.innerParams.get(e),n=!i||t.input!==i.input;ge.forEach(e=>{const i=U(s,a[e]);i&&(be(e,t.inputAttributes),i.className=a[e],n&&G(i))}),t.input&&(n&&fe(t),ve(t))})(e,t))},ke=(e,t)=>{for(const[s,i]of Object.entries(r))t.icon!==s&&V(e,i);j(e,t.icon&&r[t.icon]),Te(e,t),Ae(),Q(e,t,"icon")},Ae=()=>{const e=_();if(!e)return;const t=window.getComputedStyle(e).getPropertyValue("background-color"),s=e.querySelectorAll("[class^=swal2-success-circular-line], .swal2-success-fix");for(let e=0;e<s.length;e++)s[e].style.backgroundColor=t},Ee=(e,t)=>{if(!t.icon&&!t.iconHtml)return;let s=e.innerHTML,i="";t.iconHtml?i=Le(t.iconHtml):"success"===t.icon?(i=(e=>`\n ${e.animation?'<div class="swal2-success-circular-line-left"></div>':""}\n <span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span>\n <div class="swal2-success-ring"></div>\n ${e.animation?'<div class="swal2-success-fix"></div>':""}\n ${e.animation?'<div class="swal2-success-circular-line-right"></div>':""}\n`)(t),s=s.replace(/ style=".*?"/g,"")):"error"===t.icon?i='\n <span class="swal2-x-mark">\n <span class="swal2-x-mark-line-left"></span>\n <span class="swal2-x-mark-line-right"></span>\n </span>\n':t.icon&&(i=Le({question:"?",warning:"!",info:"i"}[t.icon])),s.trim()!==i.trim()&&F(e,i)},Te=(e,t)=>{if(t.iconColor){e.style.color=t.iconColor,e.style.borderColor=t.iconColor;for(const s of[".swal2-success-line-tip",".swal2-success-line-long",".swal2-x-mark-line-left",".swal2-x-mark-line-right"])K(e,s,"background-color",t.iconColor);K(e,".swal2-success-ring","border-color",t.iconColor)}},Le=e=>`<div class="${a["icon-content"]}">${e}</div>`;let Ie=!1,De=0,qe=0,Be=0,Pe=0;const Me=e=>{const t=_();if(!t)return;const s=x();if(e.target===t||s&&s.contains(e.target)){Ie=!0;const s=$e(e);De=s.clientX,qe=s.clientY,Be=parseInt(t.style.insetInlineStart)||0,Pe=parseInt(t.style.insetBlockStart)||0,j(t,"swal2-dragging")}},Oe=e=>{const t=_();if(t&&Ie){let{clientX:s,clientY:n}=$e(e);const o=s-De;t.style.insetInlineStart=`${Be+(i.isRTL?-o:o)}px`,t.style.insetBlockStart=`${Pe+(n-qe)}px`}},ze=()=>{const e=_();Ie=!1,V(e,"swal2-dragging")},$e=e=>{let t=0,s=0;return e.type.startsWith("mouse")?(t=e.clientX,s=e.clientY):e.type.startsWith("touch")&&(t=e.touches[0].clientX,s=e.touches[0].clientY),{clientX:t,clientY:s}},Fe=(e,t)=>{const s=v(),i=_();if(s&&i){if(t.toast){X(s,"width",t.width),i.style.width="100%";const e=D();e&&i.insertBefore(e,x())}else X(i,"width",t.width);X(i,"padding",t.padding),t.color&&(i.style.color=t.color),t.background&&(i.style.background=t.background),G(E()),He(i,t),t.draggable&&!t.toast?(j(i,a.draggable),(e=>{e.addEventListener("mousedown",Me),document.body.addEventListener("mousemove",Oe),e.addEventListener("mouseup",ze),e.addEventListener("touchstart",Me),document.body.addEventListener("touchmove",Oe),e.addEventListener("touchend",ze)})(i)):(V(i,a.draggable),(e=>{e.removeEventListener("mousedown",Me),document.body.removeEventListener("mousemove",Oe),e.removeEventListener("mouseup",ze),e.removeEventListener("touchstart",Me),document.body.removeEventListener("touchmove",Oe),e.removeEventListener("touchend",ze)})(i))}},He=(e,t)=>{const s=t.showClass||{};e.className=`${a.popup} ${ee(e)?s.popup:""}`,t.toast?(j([document.documentElement,document.body],a["toast-shown"]),j(e,a.toast)):j(e,a.modal),Q(e,t,"popup"),"string"==typeof t.customClass&&j(e,t.customClass),t.icon&&j(e,a[`icon-${t.icon}`])},Qe=e=>{const t=document.createElement("li");return j(t,a["progress-step"]),F(t,e),t},Ne=e=>{const t=document.createElement("li");return j(t,a["progress-step-line"]),e.progressStepsDistance&&X(t,"width",e.progressStepsDistance),t},Re=(e,t)=>{var s;Fe(0,t),pe(0,t),((e,t)=>{const s=A();if(!s)return;const{progressSteps:i,currentProgressStep:n}=t;i&&0!==i.length&&void 0!==n?(J(s),s.textContent="",n>=i.length&&d("Invalid currentProgressStep parameter, it should be less than progressSteps.length (currentProgressStep like JS arrays starts from 0)"),i.forEach((e,o)=>{const r=Qe(e);if(s.appendChild(r),o===n&&j(r,a["active-progress-step"]),o!==i.length-1){const e=Ne(t);s.appendChild(e)}})):G(s)})(0,t),((e,t)=>{const s=me.innerParams.get(e),i=x();if(i){if(s&&t.icon===s.icon)return Ee(i,t),void ke(i,t);if(t.icon||t.iconHtml){if(t.icon&&-1===Object.keys(r).indexOf(t.icon))return u(`Unknown icon! Expected "success", "error", "warning", "info" or "question", got "${t.icon}"`),void G(i);J(i),Ee(i,t),ke(i,t),j(i,t.showClass&&t.showClass.icon),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",Ae)}else G(i)}})(e,t),((e,t)=>{const s=k();s&&(t.imageUrl?(J(s,""),s.setAttribute("src",t.imageUrl),s.setAttribute("alt",t.imageAlt||""),X(s,"width",t.imageWidth),X(s,"height",t.imageHeight),s.className=a.image,Q(s,t,"image")):G(s))})(0,t),((e,t)=>{const s=S();s&&(Y(s),Z(s,Boolean(t.title||t.titleText),"block"),t.title&&re(t.title,s),t.titleText&&(s.innerText=t.titleText),Q(s,t,"title"))})(0,t),((e,t)=>{const s=M();s&&(F(s,t.closeButtonHtml||""),Q(s,t,"closeButton"),Z(s,t.showCloseButton),s.setAttribute("aria-label",t.closeButtonAriaLabel||""))})(0,t),Ce(e,t),de(0,t),((e,t)=>{const s=B();s&&(Y(s),Z(s,Boolean(t.footer),"block"),t.footer&&re(t.footer,s),Q(s,t,"footer"))})(0,t);const n=_();"function"==typeof t.didRender&&n&&t.didRender(n),null===(s=i.eventEmitter)||void 0===s||s.emit("didRender",n)},We=()=>{var e;return null===(e=T())||void 0===e?void 0:e.click()},je=Object.freeze({cancel:"cancel",backdrop:"backdrop",close:"close",esc:"esc",timer:"timer"}),Ve=e=>{if(e.keydownTarget&&e.keydownHandlerAdded&&e.keydownHandler){const t=e.keydownHandler;e.keydownTarget.removeEventListener("keydown",t,{capture:e.keydownListenerCapture}),e.keydownHandlerAdded=!1}},Ue=(e,t)=>{var s;const i=O();if(i.length)return-2===(e+=t)&&(e=i.length-1),e===i.length?e=0:-1===e&&(e=i.length-1),void i[e].focus();null===(s=_())||void 0===s||s.focus()},Xe=["ArrowRight","ArrowDown"],Je=["ArrowLeft","ArrowUp"],Ge=(e,t,s)=>{e&&(t.isComposing||229===t.keyCode||(e.stopKeydownPropagation&&t.stopPropagation(),"Enter"===t.key?Ye(t,e):"Tab"===t.key?Ke(t):[...Xe,...Je].includes(t.key)?Ze(t.key):"Escape"===t.key&&et(t,e,s)))},Ye=(e,t)=>{if(!m(t.allowEnterKey))return;const s=_();if(!s||!t.input)return;const i=N(s,t.input);if(e.target&&i&&e.target instanceof HTMLElement&&e.target.outerHTML===i.outerHTML){if(["textarea","file"].includes(t.input))return;We(),e.preventDefault()}},Ke=e=>{const t=e.target,s=O();let i=-1;for(let e=0;e<s.length;e++)if(t===s[e]){i=e;break}e.shiftKey?Ue(i,-1):Ue(i,1),e.stopPropagation(),e.preventDefault()},Ze=e=>{const t=q(),s=T(),i=I(),n=L();if(!(t&&s&&i&&n))return;const o=[s,i,n];if(document.activeElement instanceof HTMLElement&&!o.includes(document.activeElement))return;const a=Xe.includes(e)?"nextElementSibling":"previousElementSibling";let r=document.activeElement;if(r){for(let e=0;e<t.children.length;e++){if(r=r[a],!r)return;if(r instanceof HTMLButtonElement&&ee(r))break}r instanceof HTMLButtonElement&&r.focus()}},et=(e,t,s)=>{e.preventDefault(),m(t.allowEscapeKey)&&s(je.esc)};var tt={swalPromiseResolve:new WeakMap,swalPromiseReject:new WeakMap};const st=()=>{Array.from(document.body.children).forEach(e=>{e.hasAttribute("data-previous-aria-hidden")?(e.setAttribute("aria-hidden",e.getAttribute("data-previous-aria-hidden")||""),e.removeAttribute("data-previous-aria-hidden")):e.removeAttribute("aria-hidden")})},it="undefined"!=typeof window&&Boolean(window.GestureEvent),nt=()=>{const e=v();if(!e)return;let t;e.ontouchstart=e=>{t=ot(e)},e.ontouchmove=e=>{t&&(e.preventDefault(),e.stopPropagation())}},ot=e=>{const t=e.target,s=v(),i=C();return!(!s||!i||at(e)||rt(e)||t!==s&&(te(s)||!(t instanceof HTMLElement)||((e,t)=>{let s=e;for(;s&&s!==t;){if(te(s))return!0;s=s.parentElement}return!1})(t,i)||"INPUT"===t.tagName||"TEXTAREA"===t.tagName||te(i)&&i.contains(t)))},at=e=>Boolean(e.touches&&e.touches.length&&"stylus"===e.touches[0].touchType),rt=e=>e.touches&&e.touches.length>1;let lt=null;const ct=e=>{null===lt&&(document.body.scrollHeight>window.innerHeight||"scroll"===e)&&(lt=parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right")),document.body.style.paddingRight=`${lt+(()=>{const e=document.createElement("div");e.className=a["scrollbar-measure"],document.body.appendChild(e);const t=e.getBoundingClientRect().width-e.clientWidth;return document.body.removeChild(e),t})()}px`)};function dt(e,t,s,o){$()?vt(e,o):(n(s).then(()=>vt(e,o)),Ve(i)),it?(t.setAttribute("style","display:none !important"),t.removeAttribute("class"),t.innerHTML=""):t.remove(),z()&&(null!==lt&&(document.body.style.paddingRight=`${lt}px`,lt=null),(()=>{if(H(document.body,a.iosfix)){const e=parseInt(document.body.style.top,10);V(document.body,a.iosfix),document.body.style.top="",document.body.scrollTop=-1*e}})(),st()),V([document.documentElement,document.body],[a.shown,a["height-auto"],a["no-backdrop"],a["toast-shown"]])}function ut(e){e=gt(e);const t=tt.swalPromiseResolve.get(this),s=ht(this);this.isAwaitingPromise?e.isDismissed||(mt(this),t(e)):s&&t(e)}const ht=e=>{const t=_();if(!t)return!1;const s=me.innerParams.get(e);if(!s||H(t,s.hideClass.popup))return!1;V(t,s.showClass.popup),j(t,s.hideClass.popup);const i=v();return V(i,s.showClass.backdrop),j(i,s.hideClass.backdrop),ft(e,t,s),!0};function pt(e){const t=tt.swalPromiseReject.get(this);mt(this),t&&t(e)}const mt=e=>{e.isAwaitingPromise&&(delete e.isAwaitingPromise,me.innerParams.get(e)||e._destroy())},gt=e=>void 0===e?{isConfirmed:!1,isDenied:!1,isDismissed:!0}:Object.assign({isConfirmed:!1,isDenied:!1,isDismissed:!1},e),ft=(e,t,s)=>{var n;const o=v(),a=se(t);"function"==typeof s.willClose&&s.willClose(t),null===(n=i.eventEmitter)||void 0===n||n.emit("willClose",t),a&&o?bt(e,t,o,Boolean(s.returnFocus),s.didClose):o&&dt(e,o,Boolean(s.returnFocus),s.didClose)},bt=(e,t,s,n,o)=>{i.swalCloseEventFinishedCallback=dt.bind(null,e,s,n,o);const a=function(e){var s;e.target===t&&(null===(s=i.swalCloseEventFinishedCallback)||void 0===s||s.call(i),delete i.swalCloseEventFinishedCallback,t.removeEventListener("animationend",a),t.removeEventListener("transitionend",a))};t.addEventListener("animationend",a),t.addEventListener("transitionend",a)},vt=(e,t)=>{setTimeout(()=>{var s;"function"==typeof t&&t.bind(e.params)(),null===(s=i.eventEmitter)||void 0===s||s.emit("didClose"),e._destroy&&e._destroy()})},yt=e=>{let t=_();if(t||new Ks,t=_(),!t)return;const s=D();$()?G(x()):wt(t,e),J(s),t.setAttribute("data-loading","true"),t.setAttribute("aria-busy","true"),t.focus()},wt=(e,t)=>{const s=q(),i=D();s&&i&&(!t&&ee(T())&&(t=T()),J(s),t&&(G(t),i.setAttribute("data-button-to-replace",t.className),s.insertBefore(i,t)),j([e,s],a.loading))},_t=e=>e.checked?1:0,xt=e=>e.checked?e.value:null,St=e=>e.files&&e.files.length?null!==e.getAttribute("multiple")?e.files:e.files[0]:null,Ct=(e,t)=>{const s=_();if(!s)return;const i=e=>{"select"===t.input?function(e,t,s){const i=U(e,a.select);if(!i)return;const n=(e,t,i)=>{const n=document.createElement("option");n.value=i,F(n,t),n.selected=Et(i,s.inputValue),e.appendChild(n)};t.forEach(e=>{const t=e[0],s=e[1];if(Array.isArray(s)){const e=document.createElement("optgroup");e.label=t,e.disabled=!1,i.appendChild(e),s.forEach(t=>n(e,t[1],t[0]))}else n(i,s,t)}),i.focus()}(s,At(e),t):"radio"===t.input&&function(e,t,s){const i=U(e,a.radio);if(!i)return;t.forEach(e=>{const t=e[0],n=e[1],o=document.createElement("input"),r=document.createElement("label");o.type="radio",o.name=a.radio,o.value=t,Et(t,s.inputValue)&&(o.checked=!0);const l=document.createElement("span");F(l,n),l.className=a.label,r.appendChild(o),r.appendChild(l),i.appendChild(r)});const n=i.querySelectorAll("input");n.length&&n[0].focus()}(s,At(e),t)};g(t.inputOptions)||b(t.inputOptions)?(yt(T()),f(t.inputOptions).then(t=>{e.hideLoading(),i(t)})):"object"==typeof t.inputOptions?i(t.inputOptions):u("Unexpected type of inputOptions! Expected object, Map or Promise, got "+typeof t.inputOptions)},kt=(e,t)=>{const s=e.getInput();s&&(G(s),f(t.inputValue).then(i=>{s.value="number"===t.input?`${parseFloat(i)||0}`:`${i}`,J(s),s.focus(),e.hideLoading()}).catch(t=>{u(`Error in inputValue promise: ${t}`),s.value="",J(s),s.focus(),e.hideLoading()}))};const At=e=>{const t=[];return e instanceof Map?e.forEach((e,s)=>{let i=e;"object"==typeof i&&(i=At(i)),t.push([s,i])}):Object.keys(e).forEach(s=>{let i=e[s];"object"==typeof i&&(i=At(i)),t.push([s,i])}),t},Et=(e,t)=>Boolean(t)&&null!=t&&t.toString()===e.toString(),Tt=(e,t)=>{const s=me.innerParams.get(e);if(!s.input)return void u(`The "input" parameter is needed to be set when using returnInputValueOn${c(t)}`);const i=e.getInput(),n=((e,t)=>{const s=e.getInput();if(!s)return null;switch(t.input){case"checkbox":return _t(s);case"radio":return xt(s);case"file":return St(s);default:return t.inputAutoTrim?s.value.trim():s.value}})(e,s);s.inputValidator?Lt(e,n,t):i&&!i.checkValidity()?(e.enableButtons(),e.showValidationMessage(s.validationMessage||i.validationMessage)):"deny"===t?It(e,n):Bt(e,n)},Lt=(e,t,s)=>{const i=me.innerParams.get(e);e.disableInput(),Promise.resolve().then(()=>f(i.inputValidator(t,i.validationMessage))).then(i=>{e.enableButtons(),e.enableInput(),i?e.showValidationMessage(i):"deny"===s?It(e,t):Bt(e,t)})},It=(e,t)=>{const s=me.innerParams.get(e);s.showLoaderOnDeny&&yt(I()),s.preDeny?(e.isAwaitingPromise=!0,Promise.resolve().then(()=>f(s.preDeny(t,s.validationMessage))).then(s=>{!1===s?(e.hideLoading(),mt(e)):e.close({isDenied:!0,value:void 0===s?t:s})}).catch(t=>qt(e,t))):e.close({isDenied:!0,value:t})},Dt=(e,t)=>{e.close({isConfirmed:!0,value:t})},qt=(e,t)=>{e.rejectPromise(t)},Bt=(e,t)=>{const s=me.innerParams.get(e);s.showLoaderOnConfirm&&yt(),s.preConfirm?(e.resetValidationMessage(),e.isAwaitingPromise=!0,Promise.resolve().then(()=>f(s.preConfirm(t,s.validationMessage))).then(s=>{ee(E())||!1===s?(e.hideLoading(),mt(e)):Dt(e,void 0===s?t:s)}).catch(t=>qt(e,t))):Dt(e,t)};function Pt(){const e=me.innerParams.get(this);if(!e)return;const t=me.domCache.get(this);G(t.loader),$()?e.icon&&J(x()):Mt(t),V([t.popup,t.actions],a.loading),t.popup.removeAttribute("aria-busy"),t.popup.removeAttribute("data-loading"),t.confirmButton.disabled=!1,t.denyButton.disabled=!1,t.cancelButton.disabled=!1}const Mt=e=>{const t=e.loader.getAttribute("data-button-to-replace"),s=t?e.popup.getElementsByClassName(t):[];s.length?J(s[0],"inline-block"):!ee(T())&&!ee(I())&&!ee(L())&&G(e.actions)};function Ot(){const e=me.innerParams.get(this),t=me.domCache.get(this);return t?N(t.popup,e.input):null}function zt(e,t,s){const i=me.domCache.get(e);t.forEach(e=>{i[e].disabled=s})}function $t(e,t){const s=_();if(s&&e)if("radio"===e.type){const e=s.querySelectorAll(`[name="${a.radio}"]`);for(let s=0;s<e.length;s++)e[s].disabled=t}else e.disabled=t}function Ft(){zt(this,["confirmButton","denyButton","cancelButton"],!1)}function Ht(){zt(this,["confirmButton","denyButton","cancelButton"],!0)}function Qt(){$t(this.getInput(),!1)}function Nt(){$t(this.getInput(),!0)}function Rt(e){const t=me.domCache.get(this),s=me.innerParams.get(this);F(t.validationMessage,e),t.validationMessage.className=a["validation-message"],s.customClass&&s.customClass.validationMessage&&j(t.validationMessage,s.customClass.validationMessage),J(t.validationMessage);const i=this.getInput();i&&(i.setAttribute("aria-invalid","true"),i.setAttribute("aria-describedby",a["validation-message"]),R(i),j(i,a.inputerror))}function Wt(){const e=me.domCache.get(this);e.validationMessage&&G(e.validationMessage);const t=this.getInput();t&&(t.removeAttribute("aria-invalid"),t.removeAttribute("aria-describedby"),V(t,a.inputerror))}const jt={title:"",titleText:"",text:"",html:"",footer:"",icon:void 0,iconColor:void 0,iconHtml:void 0,template:void 0,toast:!1,draggable:!1,animation:!0,theme:"light",showClass:{popup:"swal2-show",backdrop:"swal2-backdrop-show",icon:"swal2-icon-show"},hideClass:{popup:"swal2-hide",backdrop:"swal2-backdrop-hide",icon:"swal2-icon-hide"},customClass:{},target:"body",color:void 0,backdrop:!0,heightAuto:!0,allowOutsideClick:!0,allowEscapeKey:!0,allowEnterKey:!0,stopKeydownPropagation:!0,keydownListenerCapture:!1,showConfirmButton:!0,showDenyButton:!1,showCancelButton:!1,preConfirm:void 0,preDeny:void 0,confirmButtonText:"OK",confirmButtonAriaLabel:"",confirmButtonColor:void 0,denyButtonText:"No",denyButtonAriaLabel:"",denyButtonColor:void 0,cancelButtonText:"Cancel",cancelButtonAriaLabel:"",cancelButtonColor:void 0,buttonsStyling:!0,reverseButtons:!1,focusConfirm:!0,focusDeny:!1,focusCancel:!1,returnFocus:!0,showCloseButton:!1,closeButtonHtml:"×",closeButtonAriaLabel:"Close this dialog",loaderHtml:"",showLoaderOnConfirm:!1,showLoaderOnDeny:!1,imageUrl:void 0,imageWidth:void 0,imageHeight:void 0,imageAlt:"",timer:void 0,timerProgressBar:!1,width:void 0,padding:void 0,background:void 0,input:void 0,inputPlaceholder:"",inputLabel:"",inputValue:"",inputOptions:{},inputAutoFocus:!0,inputAutoTrim:!0,inputAttributes:{},inputValidator:void 0,returnInputValueOnDeny:!1,validationMessage:void 0,grow:!1,position:"center",progressSteps:[],currentProgressStep:void 0,progressStepsDistance:void 0,willOpen:void 0,didOpen:void 0,didRender:void 0,willClose:void 0,didClose:void 0,didDestroy:void 0,scrollbarPadding:!0,topLayer:!1},Vt=["allowEscapeKey","allowOutsideClick","background","buttonsStyling","cancelButtonAriaLabel","cancelButtonColor","cancelButtonText","closeButtonAriaLabel","closeButtonHtml","color","confirmButtonAriaLabel","confirmButtonColor","confirmButtonText","currentProgressStep","customClass","denyButtonAriaLabel","denyButtonColor","denyButtonText","didClose","didDestroy","draggable","footer","hideClass","html","icon","iconColor","iconHtml","imageAlt","imageHeight","imageUrl","imageWidth","preConfirm","preDeny","progressSteps","returnFocus","reverseButtons","showCancelButton","showCloseButton","showConfirmButton","showDenyButton","text","title","titleText","theme","willClose"],Ut={allowEnterKey:void 0},Xt=["allowOutsideClick","allowEnterKey","backdrop","draggable","focusConfirm","focusDeny","focusCancel","returnFocus","heightAuto","keydownListenerCapture"],Jt=e=>Object.prototype.hasOwnProperty.call(jt,e),Gt=e=>-1!==Vt.indexOf(e),Yt=e=>Ut[e],Kt=e=>{Jt(e)||d(`Unknown parameter "${e}"`)},Zt=e=>{Xt.includes(e)&&d(`The parameter "${e}" is incompatible with toasts`)},es=e=>{const t=Yt(e);t&&p(e,t)},ts=e=>{!1===e.backdrop&&e.allowOutsideClick&&d('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`'),e.theme&&!["light","dark","auto","minimal","borderless","bootstrap-4","bootstrap-4-light","bootstrap-4-dark","bootstrap-5","bootstrap-5-light","bootstrap-5-dark","material-ui","material-ui-light","material-ui-dark","embed-iframe","bulma","bulma-light","bulma-dark"].includes(e.theme)&&d(`Invalid theme "${e.theme}"`);for(const t in e)Kt(t),e.toast&&Zt(t),es(t)};function ss(e){const t=v(),s=_(),i=me.innerParams.get(this);if(!s||H(s,i.hideClass.popup))return void d("You're trying to update the closed or closing popup, that won't work. Use the update() method in preConfirm parameter or show a new popup.");const n=is(e),o=Object.assign({},i,n);ts(o),t&&(t.dataset.swal2Theme=o.theme),Re(this,o),me.innerParams.set(this,o),Object.defineProperties(this,{params:{value:Object.assign({},this.params,e),writable:!1,enumerable:!0}})}const is=e=>{const t={};return Object.keys(e).forEach(s=>{if(Gt(s)){const i=e;t[s]=i[s]}else d(`Invalid parameter to update: ${s}`)}),t};function ns(){var e;const t=me.domCache.get(this),s=me.innerParams.get(this);s?(t.popup&&i.swalCloseEventFinishedCallback&&(i.swalCloseEventFinishedCallback(),delete i.swalCloseEventFinishedCallback),"function"==typeof s.didDestroy&&s.didDestroy(),null===(e=i.eventEmitter)||void 0===e||e.emit("didDestroy"),os(this)):as(this)}const os=e=>{as(e),delete e.params,delete i.keydownHandler,delete i.keydownTarget,delete i.currentInstance},as=e=>{e.isAwaitingPromise?(rs(me,e),e.isAwaitingPromise=!0):(rs(tt,e),rs(me,e),delete e.isAwaitingPromise,delete e.disableButtons,delete e.enableButtons,delete e.getInput,delete e.disableInput,delete e.enableInput,delete e.hideLoading,delete e.disableLoading,delete e.showValidationMessage,delete e.resetValidationMessage,delete e.close,delete e.closePopup,delete e.closeModal,delete e.closeToast,delete e.rejectPromise,delete e.update,delete e._destroy)},rs=(e,t)=>{for(const s in e)e[s].delete(t)};var ls=Object.freeze({__proto__:null,_destroy:ns,close:ut,closeModal:ut,closePopup:ut,closeToast:ut,disableButtons:Ht,disableInput:Nt,disableLoading:Pt,enableButtons:Ft,enableInput:Qt,getInput:Ot,handleAwaitingPromise:mt,hideLoading:Pt,rejectPromise:pt,resetValidationMessage:Wt,showValidationMessage:Rt,update:ss});const cs=(e,t,s)=>{t.popup.onclick=()=>{e&&(ds(e)||e.timer||e.input)||s(je.close)}},ds=e=>Boolean(e.showConfirmButton||e.showDenyButton||e.showCancelButton||e.showCloseButton);let us=!1;const hs=e=>{e.popup.onmousedown=()=>{e.container.onmouseup=function(t){e.container.onmouseup=()=>{},t.target===e.container&&(us=!0)}}},ps=e=>{e.container.onmousedown=t=>{t.target===e.container&&t.preventDefault(),e.popup.onmouseup=function(t){e.popup.onmouseup=()=>{},(t.target===e.popup||t.target instanceof HTMLElement&&e.popup.contains(t.target))&&(us=!0)}}},ms=(e,t,s)=>{t.container.onclick=i=>{us?us=!1:i.target===t.container&&m(e.allowOutsideClick)&&s(je.backdrop)}},gs=e=>e instanceof Element||(e=>"object"==typeof e&&e.jquery)(e);const fs=()=>{if(i.timeout)return(()=>{const e=P();if(!e)return;const t=parseInt(window.getComputedStyle(e).width);e.style.removeProperty("transition"),e.style.width="100%";const s=t/parseInt(window.getComputedStyle(e).width)*100;e.style.width=`${s}%`})(),i.timeout.stop()},bs=()=>{if(i.timeout){const e=i.timeout.start();return ie(e),e}};let vs=!1;const ys={};const ws=e=>{for(let t=e.target;t&&t!==document;t=t.parentNode)for(const e in ys){const s=t.getAttribute&&t.getAttribute(e);if(s)return void ys[e].fire({template:s})}};i.eventEmitter=new class{constructor(){this.events={}}_getHandlersByEventName(e){return void 0===this.events[e]&&(this.events[e]=[]),this.events[e]}on(e,t){const s=this._getHandlersByEventName(e);s.includes(t)||s.push(t)}once(e,t){const s=(...i)=>{this.removeListener(e,s),t.apply(this,i)};this.on(e,s)}emit(e,...t){this._getHandlersByEventName(e).forEach(e=>{try{e.apply(this,t)}catch(e){console.error(e)}})}removeListener(e,t){const s=this._getHandlersByEventName(e),i=s.indexOf(t);i>-1&&s.splice(i,1)}removeAllListeners(e){void 0!==this.events[e]&&(this.events[e].length=0)}reset(){this.events={}}};var _s=Object.freeze({__proto__:null,argsToParams:e=>{const t={};return"object"!=typeof e[0]||gs(e[0])?["title","html","icon"].forEach((s,i)=>{const n=e[i];"string"==typeof n||gs(n)?t[s]=n:void 0!==n&&u(`Unexpected type of ${s}! Expected "string" or "Element", got ${typeof n}`)}):Object.assign(t,e[0]),t},bindClickHandler:function(e="data-swal-template"){ys[e]=this,vs||(document.body.addEventListener("click",ws),vs=!0)},clickCancel:()=>{var e;return null===(e=L())||void 0===e?void 0:e.click()},clickConfirm:We,clickDeny:()=>{var e;return null===(e=I())||void 0===e?void 0:e.click()},enableLoading:yt,fire:function(...e){return new this(...e)},getActions:q,getCancelButton:L,getCloseButton:M,getConfirmButton:T,getContainer:v,getDenyButton:I,getFocusableElements:O,getFooter:B,getHtmlContainer:C,getIcon:x,getIconContent:()=>w(a["icon-content"]),getImage:k,getInputLabel:()=>w(a["input-label"]),getLoader:D,getPopup:_,getProgressSteps:A,getTimerLeft:()=>i.timeout&&i.timeout.getTimerLeft(),getTimerProgressBar:P,getTitle:S,getValidationMessage:E,increaseTimer:e=>{if(i.timeout){const t=i.timeout.increase(e);return ie(t,!0),t}},isDeprecatedParameter:Yt,isLoading:()=>{const e=_();return!!e&&e.hasAttribute("data-loading")},isTimerRunning:()=>Boolean(i.timeout&&i.timeout.isRunning()),isUpdatableParameter:Gt,isValidParameter:Jt,isVisible:()=>ee(_()),mixin:function(e){return class extends(this){_main(t,s){return super._main(t,Object.assign({},e,s))}}},off:(e,t)=>{i.eventEmitter&&(e?t?i.eventEmitter.removeListener(e,t):i.eventEmitter.removeAllListeners(e):i.eventEmitter.reset())},on:(e,t)=>{i.eventEmitter&&i.eventEmitter.on(e,t)},once:(e,t)=>{i.eventEmitter&&i.eventEmitter.once(e,t)},resumeTimer:bs,showLoading:yt,stopTimer:fs,toggleTimer:()=>{const e=i.timeout;return e&&(e.running?fs():bs())}});class xs{constructor(e,t){this.callback=e,this.remaining=t,this.running=!1,this.start()}start(){return this.running||(this.running=!0,this.started=new Date,this.id=setTimeout(this.callback,this.remaining)),this.remaining}stop(){return this.started&&this.running&&(this.running=!1,clearTimeout(this.id),this.remaining-=(new Date).getTime()-this.started.getTime()),this.remaining}increase(e){const t=this.running;return t&&this.stop(),this.remaining+=e,t&&this.start(),this.remaining}getTimerLeft(){return this.running&&(this.stop(),this.start()),this.remaining}isRunning(){return this.running}}const Ss=["swal-title","swal-html","swal-footer"],Cs=e=>{const t={};return Array.from(e.querySelectorAll("swal-param")).forEach(e=>{qs(e,["name","value"]);const s=e.getAttribute("name"),i=e.getAttribute("value");s&&i&&(t[s]=s in jt&&"boolean"==typeof jt[s]?"false"!==i:s in jt&&"object"==typeof jt[s]?JSON.parse(i):i)}),t},ks=e=>{const t={};return Array.from(e.querySelectorAll("swal-function-param")).forEach(e=>{const s=e.getAttribute("name"),i=e.getAttribute("value");s&&i&&(t[s]=new Function(`return ${i}`)())}),t},As=e=>{const t={};return Array.from(e.querySelectorAll("swal-button")).forEach(e=>{qs(e,["type","color","aria-label"]);const s=e.getAttribute("type");if(s&&["confirm","cancel","deny"].includes(s)){if(t[`${s}ButtonText`]=e.innerHTML,t[`show${c(s)}Button`]=!0,e.hasAttribute("color")){const i=e.getAttribute("color");null!==i&&(t[`${s}ButtonColor`]=i)}if(e.hasAttribute("aria-label")){const i=e.getAttribute("aria-label");null!==i&&(t[`${s}ButtonAriaLabel`]=i)}}}),t},Es=e=>{const t={},s=e.querySelector("swal-image");return s&&(qs(s,["src","width","height","alt"]),s.hasAttribute("src")&&(t.imageUrl=s.getAttribute("src")||void 0),s.hasAttribute("width")&&(t.imageWidth=s.getAttribute("width")||void 0),s.hasAttribute("height")&&(t.imageHeight=s.getAttribute("height")||void 0),s.hasAttribute("alt")&&(t.imageAlt=s.getAttribute("alt")||void 0)),t},Ts=e=>{const t={},s=e.querySelector("swal-icon");return s&&(qs(s,["type","color"]),s.hasAttribute("type")&&(t.icon=s.getAttribute("type")),s.hasAttribute("color")&&(t.iconColor=s.getAttribute("color")),t.iconHtml=s.innerHTML),t},Ls=e=>{const t={},s=e.querySelector("swal-input");s&&(qs(s,["type","label","placeholder","value"]),t.input=s.getAttribute("type")||"text",s.hasAttribute("label")&&(t.inputLabel=s.getAttribute("label")),s.hasAttribute("placeholder")&&(t.inputPlaceholder=s.getAttribute("placeholder")),s.hasAttribute("value")&&(t.inputValue=s.getAttribute("value")));const i=Array.from(e.querySelectorAll("swal-input-option"));return i.length&&(t.inputOptions={},i.forEach(e=>{qs(e,["value"]);const s=e.getAttribute("value");if(!s)return;const i=e.innerHTML;t.inputOptions[s]=i})),t},Is=(e,t)=>{const s={};for(const i in t){const n=t[i],o=e.querySelector(n);o&&(qs(o,[]),s[n.replace(/^swal-/,"")]=o.innerHTML.trim())}return s},Ds=e=>{const t=Ss.concat(["swal-param","swal-function-param","swal-button","swal-image","swal-icon","swal-input","swal-input-option"]);Array.from(e.children).forEach(e=>{const s=e.tagName.toLowerCase();t.includes(s)||d(`Unrecognized element <${s}>`)})},qs=(e,t)=>{Array.from(e.attributes).forEach(s=>{-1===t.indexOf(s.name)&&d([`Unrecognized attribute "${s.name}" on <${e.tagName.toLowerCase()}>.`,t.length?`Allowed attributes are: ${t.join(", ")}`:"To set the value, use HTML within the element."])})},Bs=e=>{var t,s;const n=v(),o=_();if(!n||!o)return;"function"==typeof e.willOpen&&e.willOpen(o),null===(t=i.eventEmitter)||void 0===t||t.emit("willOpen",o);const a=window.getComputedStyle(document.body).overflowY;if(zs(n,o,e),setTimeout(()=>{Ms(n,o)},10),z()&&(Os(n,void 0!==e.scrollbarPadding&&e.scrollbarPadding,a),(()=>{const e=v();Array.from(document.body.children).forEach(t=>{t.contains(e)||(t.hasAttribute("aria-hidden")&&t.setAttribute("data-previous-aria-hidden",t.getAttribute("aria-hidden")||""),t.setAttribute("aria-hidden","true"))})})()),$()||i.previousActiveElement||(i.previousActiveElement=document.activeElement),"function"==typeof e.didOpen){const t=e.didOpen;setTimeout(()=>t(o))}null===(s=i.eventEmitter)||void 0===s||s.emit("didOpen",o)},Ps=e=>{const t=_();if(!t||e.target!==t)return;const s=v();s&&(t.removeEventListener("animationend",Ps),t.removeEventListener("transitionend",Ps),s.style.overflowY="auto",V(s,a["no-transition"]))},Ms=(e,t)=>{se(t)?(e.style.overflowY="hidden",t.addEventListener("animationend",Ps),t.addEventListener("transitionend",Ps)):e.style.overflowY="auto"},Os=(e,t,s)=>{(()=>{if(it&&!H(document.body,a.iosfix)){const e=document.body.scrollTop;document.body.style.top=-1*e+"px",j(document.body,a.iosfix),nt()}})(),t&&"hidden"!==s&&ct(s),setTimeout(()=>{e.scrollTop=0})},zs=(e,t,s)=>{var i;null!==(i=s.showClass)&&void 0!==i&&i.backdrop&&j(e,s.showClass.backdrop),s.animation?(t.style.setProperty("opacity","0","important"),J(t,"grid"),setTimeout(()=>{var e;null!==(e=s.showClass)&&void 0!==e&&e.popup&&j(t,s.showClass.popup),t.style.removeProperty("opacity")},10)):J(t,"grid"),j([document.documentElement,document.body],a.shown),s.heightAuto&&s.backdrop&&!s.toast&&j([document.documentElement,document.body],a["height-auto"])};var $s=(e,t)=>/^[a-zA-Z0-9.+_'-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]+$/.test(e)?Promise.resolve():Promise.resolve(t||"Invalid email address"),Fs=(e,t)=>/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/.test(e)?Promise.resolve():Promise.resolve(t||"Invalid URL");function Hs(e){(function(e){e.inputValidator||("email"===e.input&&(e.inputValidator=$s),"url"===e.input&&(e.inputValidator=Fs))})(e),e.showLoaderOnConfirm&&!e.preConfirm&&d("showLoaderOnConfirm is set to true, but preConfirm is not defined.\nshowLoaderOnConfirm should be used together with preConfirm, see usage example:\nhttps://sweetalert2.github.io/#ajax-request"),function(e){(!e.target||"string"==typeof e.target&&!document.querySelector(e.target)||"string"!=typeof e.target&&!e.target.appendChild)&&(d('Target parameter is not valid, defaulting to "body"'),e.target="body")}(e),"string"==typeof e.title&&(e.title=e.title.split("\n").join("<br />")),ae(e)}let Qs;var Ns=new WeakMap;class Rs{constructor(...t){if(s(this,Ns,Promise.resolve({isConfirmed:!1,isDenied:!1,isDismissed:!0})),"undefined"==typeof window)return;Qs=this;const i=Object.freeze(this.constructor.argsToParams(t));var n,o,a;this.params=i,this.isAwaitingPromise=!1,n=Ns,o=this,a=this._main(Qs.params),n.set(e(n,o),a)}_main(e,t={}){if(ts(Object.assign({},t,e)),i.currentInstance){const e=tt.swalPromiseResolve.get(i.currentInstance),{isAwaitingPromise:t}=i.currentInstance;i.currentInstance._destroy(),t||e({isDismissed:!0}),z()&&st()}i.currentInstance=Qs;const s=js(e,t);Hs(s),Object.freeze(s),i.timeout&&(i.timeout.stop(),delete i.timeout),clearTimeout(i.restoreFocusTimeout);const n=Vs(Qs);return Re(Qs,s),me.innerParams.set(Qs,s),Ws(Qs,n,s)}then(e){return t(Ns,this).then(e)}finally(e){return t(Ns,this).finally(e)}}const Ws=(e,t,s)=>new Promise((n,o)=>{const a=t=>{e.close({isDismissed:!0,dismiss:t,isConfirmed:!1,isDenied:!1})};tt.swalPromiseResolve.set(e,n),tt.swalPromiseReject.set(e,o),t.confirmButton.onclick=()=>{(e=>{const t=me.innerParams.get(e);e.disableButtons(),t.input?Tt(e,"confirm"):Bt(e,!0)})(e)},t.denyButton.onclick=()=>{(e=>{const t=me.innerParams.get(e);e.disableButtons(),t.returnInputValueOnDeny?Tt(e,"deny"):It(e,!1)})(e)},t.cancelButton.onclick=()=>{((e,t)=>{e.disableButtons(),t(je.cancel)})(e,a)},t.closeButton.onclick=()=>{a(je.close)},((e,t,s)=>{e.toast?cs(e,t,s):(hs(t),ps(t),ms(e,t,s))})(s,t,a),((e,t,s)=>{if(Ve(e),!t.toast){const i=e=>Ge(t,e,s);e.keydownHandler=i;const n=t.keydownListenerCapture?window:_();if(n){e.keydownTarget=n,e.keydownListenerCapture=t.keydownListenerCapture;const s=i;e.keydownTarget.addEventListener("keydown",s,{capture:e.keydownListenerCapture}),e.keydownHandlerAdded=!0}}})(i,s,a),((e,t)=>{"select"===t.input||"radio"===t.input?Ct(e,t):["text","email","number","tel","textarea"].some(e=>e===t.input)&&(g(t.inputValue)||b(t.inputValue))&&(yt(T()),kt(e,t))})(e,s),Bs(s),Us(i,s,a),Xs(t,s),setTimeout(()=>{t.container.scrollTop=0})}),js=(e,t)=>{const s=(e=>{const t="string"==typeof e.template?document.querySelector(e.template):e.template;if(!t)return{};const s=t.content;return Ds(s),Object.assign(Cs(s),ks(s),As(s),Es(s),Ts(s),Ls(s),Is(s,Ss))})(e),i=Object.assign({},jt,t,s,e);return i.showClass=Object.assign({},jt.showClass,i.showClass),i.hideClass=Object.assign({},jt.hideClass,i.hideClass),!1===i.animation&&(i.showClass={backdrop:"swal2-noanimation"},i.hideClass={}),i},Vs=e=>{const t={popup:_(),container:v(),actions:q(),confirmButton:T(),denyButton:I(),cancelButton:L(),loader:D(),closeButton:M(),validationMessage:E(),progressSteps:A()};return me.domCache.set(e,t),t},Us=(e,t,s)=>{const i=P();G(i),t.timer&&(e.timeout=new xs(()=>{s("timer"),delete e.timeout},t.timer),t.timerProgressBar&&i&&(J(i),Q(i,t,"timerProgressBar"),setTimeout(()=>{e.timeout&&e.timeout.running&&ie(t.timer)})))},Xs=(e,t)=>{if(!t.toast)return m(t.allowEnterKey)?void(Js(e)||Gs(e,t)||Ue(-1,1)):(p("allowEnterKey"),void Ys())},Js=e=>{const t=Array.from(e.popup.querySelectorAll("[autofocus]"));for(const e of t)if(e instanceof HTMLElement&&ee(e))return e.focus(),!0;return!1},Gs=(e,t)=>t.focusDeny&&ee(e.denyButton)?(e.denyButton.focus(),!0):t.focusCancel&&ee(e.cancelButton)?(e.cancelButton.focus(),!0):!(!t.focusConfirm||!ee(e.confirmButton)||(e.confirmButton.focus(),0)),Ys=()=>{document.activeElement instanceof HTMLElement&&"function"==typeof document.activeElement.blur&&document.activeElement.blur()};Rs.prototype.disableButtons=Ht,Rs.prototype.enableButtons=Ft,Rs.prototype.getInput=Ot,Rs.prototype.disableInput=Nt,Rs.prototype.enableInput=Qt,Rs.prototype.hideLoading=Pt,Rs.prototype.disableLoading=Pt,Rs.prototype.showValidationMessage=Rt,Rs.prototype.resetValidationMessage=Wt,Rs.prototype.close=ut,Rs.prototype.closePopup=ut,Rs.prototype.closeModal=ut,Rs.prototype.closeToast=ut,Rs.prototype.rejectPromise=pt,Rs.prototype.update=ss,Rs.prototype._destroy=ns,Object.assign(Rs,_s),Object.keys(ls).forEach(e=>{Rs[e]=function(...t){if(Qs&&Qs[e])return Qs[e](...t)}}),Rs.DismissReason=je,Rs.version="11.26.17";const Ks=Rs;return Ks.default=Ks,Ks}(),void 0!==this&&this.Sweetalert2&&(this.swal=this.sweetAlert=this.Swal=this.SweetAlert=this.Sweetalert2),"undefined"!=typeof document&&function(e,t){var s=e.createElement("style");if(e.getElementsByTagName("head")[0].appendChild(s),s.styleSheet)s.styleSheet.disabled||(s.styleSheet.cssText=t);else try{s.innerHTML=t}catch(e){s.innerText=t}}(document,':root{--swal2-outline: 0 0 0 3px rgba(100, 150, 200, 0.5);--swal2-container-padding: 0.625em;--swal2-backdrop: rgba(0, 0, 0, 0.4);--swal2-backdrop-transition: background-color 0.15s;--swal2-width: 32em;--swal2-padding: 0 0 1.25em;--swal2-border: none;--swal2-border-radius: 0.3125rem;--swal2-background: white;--swal2-color: #545454;--swal2-show-animation: swal2-show 0.3s;--swal2-hide-animation: swal2-hide 0.15s forwards;--swal2-icon-zoom: 1;--swal2-icon-animations: true;--swal2-title-padding: 0.8em 1em 0;--swal2-html-container-padding: 1em 1.6em 0.3em;--swal2-input-border: 1px solid #d9d9d9;--swal2-input-border-radius: 0.1875em;--swal2-input-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.06), 0 0 0 3px transparent;--swal2-input-background: transparent;--swal2-input-transition: border-color 0.2s, box-shadow 0.2s;--swal2-input-hover-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.06), 0 0 0 3px transparent;--swal2-input-focus-border: 1px solid #b4dbed;--swal2-input-focus-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.06), 0 0 0 3px rgba(100, 150, 200, 0.5);--swal2-progress-step-background: #add8e6;--swal2-validation-message-background: #f0f0f0;--swal2-validation-message-color: #666;--swal2-footer-border-color: #eee;--swal2-footer-background: transparent;--swal2-footer-color: inherit;--swal2-timer-progress-bar-background: rgba(0, 0, 0, 0.3);--swal2-close-button-position: initial;--swal2-close-button-inset: auto;--swal2-close-button-font-size: 2.5em;--swal2-close-button-color: #ccc;--swal2-close-button-transition: color 0.2s, box-shadow 0.2s;--swal2-close-button-outline: initial;--swal2-close-button-box-shadow: inset 0 0 0 3px transparent;--swal2-close-button-focus-box-shadow: inset var(--swal2-outline);--swal2-close-button-hover-transform: none;--swal2-actions-justify-content: center;--swal2-actions-width: auto;--swal2-actions-margin: 1.25em auto 0;--swal2-actions-padding: 0;--swal2-actions-border-radius: 0;--swal2-actions-background: transparent;--swal2-action-button-transition: background-color 0.2s, box-shadow 0.2s;--swal2-action-button-hover: black 10%;--swal2-action-button-active: black 10%;--swal2-confirm-button-box-shadow: none;--swal2-confirm-button-border-radius: 0.25em;--swal2-confirm-button-background-color: #7066e0;--swal2-confirm-button-color: #fff;--swal2-deny-button-box-shadow: none;--swal2-deny-button-border-radius: 0.25em;--swal2-deny-button-background-color: #dc3741;--swal2-deny-button-color: #fff;--swal2-cancel-button-box-shadow: none;--swal2-cancel-button-border-radius: 0.25em;--swal2-cancel-button-background-color: #6e7881;--swal2-cancel-button-color: #fff;--swal2-toast-show-animation: swal2-toast-show 0.5s;--swal2-toast-hide-animation: swal2-toast-hide 0.1s forwards;--swal2-toast-border: none;--swal2-toast-box-shadow: 0 0 1px hsl(0deg 0% 0% / 0.075), 0 1px 2px hsl(0deg 0% 0% / 0.075), 1px 2px 4px hsl(0deg 0% 0% / 0.075), 1px 3px 8px hsl(0deg 0% 0% / 0.075), 2px 4px 16px hsl(0deg 0% 0% / 0.075)}[data-swal2-theme=dark]{--swal2-dark-theme-black: #19191a;--swal2-dark-theme-white: #e1e1e1;--swal2-background: var(--swal2-dark-theme-black);--swal2-color: var(--swal2-dark-theme-white);--swal2-footer-border-color: #555;--swal2-input-background: color-mix(in srgb, var(--swal2-dark-theme-black), var(--swal2-dark-theme-white) 10%);--swal2-validation-message-background: color-mix( in srgb, var(--swal2-dark-theme-black), var(--swal2-dark-theme-white) 10% );--swal2-validation-message-color: var(--swal2-dark-theme-white);--swal2-timer-progress-bar-background: rgba(255, 255, 255, 0.7)}@media(prefers-color-scheme: dark){[data-swal2-theme=auto]{--swal2-dark-theme-black: #19191a;--swal2-dark-theme-white: #e1e1e1;--swal2-background: var(--swal2-dark-theme-black);--swal2-color: var(--swal2-dark-theme-white);--swal2-footer-border-color: #555;--swal2-input-background: color-mix(in srgb, var(--swal2-dark-theme-black), var(--swal2-dark-theme-white) 10%);--swal2-validation-message-background: color-mix( in srgb, var(--swal2-dark-theme-black), var(--swal2-dark-theme-white) 10% );--swal2-validation-message-color: var(--swal2-dark-theme-white);--swal2-timer-progress-bar-background: rgba(255, 255, 255, 0.7)}}body.swal2-shown:not(.swal2-no-backdrop,.swal2-toast-shown){overflow:hidden}body.swal2-height-auto{height:auto !important}body.swal2-no-backdrop .swal2-container{background-color:rgba(0,0,0,0) !important;pointer-events:none}body.swal2-no-backdrop .swal2-container .swal2-popup{pointer-events:all}body.swal2-no-backdrop .swal2-container .swal2-modal{box-shadow:0 0 10px var(--swal2-backdrop)}body.swal2-toast-shown .swal2-container{box-sizing:border-box;width:360px;max-width:100%;background-color:rgba(0,0,0,0);pointer-events:none}body.swal2-toast-shown .swal2-container.swal2-top{inset:0 auto auto 50%;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-top-end,body.swal2-toast-shown .swal2-container.swal2-top-right{inset:0 0 auto auto}body.swal2-toast-shown .swal2-container.swal2-top-start,body.swal2-toast-shown .swal2-container.swal2-top-left{inset:0 auto auto 0}body.swal2-toast-shown .swal2-container.swal2-center-start,body.swal2-toast-shown .swal2-container.swal2-center-left{inset:50% auto auto 0;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-center{inset:50% auto auto 50%;transform:translate(-50%, -50%)}body.swal2-toast-shown .swal2-container.swal2-center-end,body.swal2-toast-shown .swal2-container.swal2-center-right{inset:50% 0 auto auto;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-start,body.swal2-toast-shown .swal2-container.swal2-bottom-left{inset:auto auto 0 0}body.swal2-toast-shown .swal2-container.swal2-bottom{inset:auto auto 0 50%;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-end,body.swal2-toast-shown .swal2-container.swal2-bottom-right{inset:auto 0 0 auto}@media print{body.swal2-shown:not(.swal2-no-backdrop,.swal2-toast-shown){overflow-y:scroll !important}body.swal2-shown:not(.swal2-no-backdrop,.swal2-toast-shown)>[aria-hidden=true]{display:none}body.swal2-shown:not(.swal2-no-backdrop,.swal2-toast-shown) .swal2-container{position:static !important}}div:where(.swal2-container){display:grid;position:fixed;z-index:1060;inset:0;box-sizing:border-box;grid-template-areas:"top-start top top-end" "center-start center center-end" "bottom-start bottom-center bottom-end";grid-template-rows:minmax(min-content, auto) minmax(min-content, auto) minmax(min-content, auto);height:100%;padding:var(--swal2-container-padding);overflow-x:hidden;transition:var(--swal2-backdrop-transition);-webkit-overflow-scrolling:touch}div:where(.swal2-container).swal2-backdrop-show,div:where(.swal2-container).swal2-noanimation{background:var(--swal2-backdrop)}div:where(.swal2-container).swal2-backdrop-hide{background:rgba(0,0,0,0) !important}div:where(.swal2-container).swal2-top-start,div:where(.swal2-container).swal2-center-start,div:where(.swal2-container).swal2-bottom-start{grid-template-columns:minmax(0, 1fr) auto auto}div:where(.swal2-container).swal2-top,div:where(.swal2-container).swal2-center,div:where(.swal2-container).swal2-bottom{grid-template-columns:auto minmax(0, 1fr) auto}div:where(.swal2-container).swal2-top-end,div:where(.swal2-container).swal2-center-end,div:where(.swal2-container).swal2-bottom-end{grid-template-columns:auto auto minmax(0, 1fr)}div:where(.swal2-container).swal2-top-start>.swal2-popup{align-self:start}div:where(.swal2-container).swal2-top>.swal2-popup{grid-column:2;place-self:start center}div:where(.swal2-container).swal2-top-end>.swal2-popup,div:where(.swal2-container).swal2-top-right>.swal2-popup{grid-column:3;place-self:start end}div:where(.swal2-container).swal2-center-start>.swal2-popup,div:where(.swal2-container).swal2-center-left>.swal2-popup{grid-row:2;align-self:center}div:where(.swal2-container).swal2-center>.swal2-popup{grid-column:2;grid-row:2;place-self:center center}div:where(.swal2-container).swal2-center-end>.swal2-popup,div:where(.swal2-container).swal2-center-right>.swal2-popup{grid-column:3;grid-row:2;place-self:center end}div:where(.swal2-container).swal2-bottom-start>.swal2-popup,div:where(.swal2-container).swal2-bottom-left>.swal2-popup{grid-column:1;grid-row:3;align-self:end}div:where(.swal2-container).swal2-bottom>.swal2-popup{grid-column:2;grid-row:3;place-self:end center}div:where(.swal2-container).swal2-bottom-end>.swal2-popup,div:where(.swal2-container).swal2-bottom-right>.swal2-popup{grid-column:3;grid-row:3;place-self:end end}div:where(.swal2-container).swal2-grow-row>.swal2-popup,div:where(.swal2-container).swal2-grow-fullscreen>.swal2-popup{grid-column:1/4;width:100%}div:where(.swal2-container).swal2-grow-column>.swal2-popup,div:where(.swal2-container).swal2-grow-fullscreen>.swal2-popup{grid-row:1/4;align-self:stretch}div:where(.swal2-container).swal2-no-transition{transition:none !important}div:where(.swal2-container)[popover]{width:auto;border:0}div:where(.swal2-container) div:where(.swal2-popup){display:none;position:relative;box-sizing:border-box;grid-template-columns:minmax(0, 100%);width:var(--swal2-width);max-width:100%;padding:var(--swal2-padding);border:var(--swal2-border);border-radius:var(--swal2-border-radius);background:var(--swal2-background);color:var(--swal2-color);font-family:inherit;font-size:1rem;container-name:swal2-popup}div:where(.swal2-container) div:where(.swal2-popup):focus{outline:none}div:where(.swal2-container) div:where(.swal2-popup).swal2-loading{overflow-y:hidden}div:where(.swal2-container) div:where(.swal2-popup).swal2-draggable{cursor:grab}div:where(.swal2-container) div:where(.swal2-popup).swal2-draggable div:where(.swal2-icon){cursor:grab}div:where(.swal2-container) div:where(.swal2-popup).swal2-dragging{cursor:grabbing}div:where(.swal2-container) div:where(.swal2-popup).swal2-dragging div:where(.swal2-icon){cursor:grabbing}div:where(.swal2-container) h2:where(.swal2-title){position:relative;max-width:100%;margin:0;padding:var(--swal2-title-padding);color:inherit;font-size:1.875em;font-weight:600;text-align:center;text-transform:none;overflow-wrap:break-word;cursor:initial}div:where(.swal2-container) div:where(.swal2-actions){display:flex;z-index:1;box-sizing:border-box;flex-wrap:wrap;align-items:center;justify-content:var(--swal2-actions-justify-content);width:var(--swal2-actions-width);margin:var(--swal2-actions-margin);padding:var(--swal2-actions-padding);border-radius:var(--swal2-actions-border-radius);background:var(--swal2-actions-background)}div:where(.swal2-container) div:where(.swal2-loader){display:none;align-items:center;justify-content:center;width:2.2em;height:2.2em;margin:0 1.875em;animation:swal2-rotate-loading 1.5s linear 0s infinite normal;border-width:.25em;border-style:solid;border-radius:100%;border-color:#2778c4 rgba(0,0,0,0) #2778c4 rgba(0,0,0,0)}div:where(.swal2-container) button:where(.swal2-styled){margin:.3125em;padding:.625em 1.1em;transition:var(--swal2-action-button-transition);border:none;box-shadow:0 0 0 3px rgba(0,0,0,0);font-weight:500}div:where(.swal2-container) button:where(.swal2-styled):not([disabled]){cursor:pointer}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-confirm){border-radius:var(--swal2-confirm-button-border-radius);background:initial;background-color:var(--swal2-confirm-button-background-color);box-shadow:var(--swal2-confirm-button-box-shadow);color:var(--swal2-confirm-button-color);font-size:1em}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-confirm):hover{background-color:color-mix(in srgb, var(--swal2-confirm-button-background-color), var(--swal2-action-button-hover))}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-confirm):active{background-color:color-mix(in srgb, var(--swal2-confirm-button-background-color), var(--swal2-action-button-active))}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-deny){border-radius:var(--swal2-deny-button-border-radius);background:initial;background-color:var(--swal2-deny-button-background-color);box-shadow:var(--swal2-deny-button-box-shadow);color:var(--swal2-deny-button-color);font-size:1em}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-deny):hover{background-color:color-mix(in srgb, var(--swal2-deny-button-background-color), var(--swal2-action-button-hover))}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-deny):active{background-color:color-mix(in srgb, var(--swal2-deny-button-background-color), var(--swal2-action-button-active))}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-cancel){border-radius:var(--swal2-cancel-button-border-radius);background:initial;background-color:var(--swal2-cancel-button-background-color);box-shadow:var(--swal2-cancel-button-box-shadow);color:var(--swal2-cancel-button-color);font-size:1em}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-cancel):hover{background-color:color-mix(in srgb, var(--swal2-cancel-button-background-color), var(--swal2-action-button-hover))}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-cancel):active{background-color:color-mix(in srgb, var(--swal2-cancel-button-background-color), var(--swal2-action-button-active))}div:where(.swal2-container) button:where(.swal2-styled):focus-visible{outline:none;box-shadow:var(--swal2-action-button-focus-box-shadow)}div:where(.swal2-container) button:where(.swal2-styled)[disabled]:not(.swal2-loading){opacity:.4}div:where(.swal2-container) button:where(.swal2-styled)::-moz-focus-inner{border:0}div:where(.swal2-container) div:where(.swal2-footer){margin:1em 0 0;padding:1em 1em 0;border-top:1px solid var(--swal2-footer-border-color);background:var(--swal2-footer-background);color:var(--swal2-footer-color);font-size:1em;text-align:center;cursor:initial}div:where(.swal2-container) .swal2-timer-progress-bar-container{position:absolute;right:0;bottom:0;left:0;grid-column:auto !important;overflow:hidden;border-bottom-right-radius:var(--swal2-border-radius);border-bottom-left-radius:var(--swal2-border-radius)}div:where(.swal2-container) div:where(.swal2-timer-progress-bar){width:100%;height:.25em;background:var(--swal2-timer-progress-bar-background)}div:where(.swal2-container) img:where(.swal2-image){max-width:100%;margin:2em auto 1em;cursor:initial}div:where(.swal2-container) button:where(.swal2-close){position:var(--swal2-close-button-position);inset:var(--swal2-close-button-inset);z-index:2;align-items:center;justify-content:center;width:1.2em;height:1.2em;margin-top:0;margin-right:0;margin-bottom:-1.2em;padding:0;overflow:hidden;transition:var(--swal2-close-button-transition);border:none;border-radius:var(--swal2-border-radius);outline:var(--swal2-close-button-outline);background:rgba(0,0,0,0);color:var(--swal2-close-button-color);font-family:monospace;font-size:var(--swal2-close-button-font-size);cursor:pointer;justify-self:end}div:where(.swal2-container) button:where(.swal2-close):hover{transform:var(--swal2-close-button-hover-transform);background:rgba(0,0,0,0);color:#f27474}div:where(.swal2-container) button:where(.swal2-close):focus-visible{outline:none;box-shadow:var(--swal2-close-button-focus-box-shadow)}div:where(.swal2-container) button:where(.swal2-close)::-moz-focus-inner{border:0}div:where(.swal2-container) div:where(.swal2-html-container){z-index:1;justify-content:center;margin:0;padding:var(--swal2-html-container-padding);overflow:auto;color:inherit;font-size:1.125em;font-weight:normal;line-height:normal;text-align:center;overflow-wrap:break-word;word-break:break-word;cursor:initial}div:where(.swal2-container) input:where(.swal2-input),div:where(.swal2-container) input:where(.swal2-file),div:where(.swal2-container) textarea:where(.swal2-textarea),div:where(.swal2-container) select:where(.swal2-select),div:where(.swal2-container) div:where(.swal2-radio),div:where(.swal2-container) label:where(.swal2-checkbox){margin:1em 2em 3px}div:where(.swal2-container) input:where(.swal2-input),div:where(.swal2-container) input:where(.swal2-file),div:where(.swal2-container) textarea:where(.swal2-textarea){box-sizing:border-box;width:auto;transition:var(--swal2-input-transition);border:var(--swal2-input-border);border-radius:var(--swal2-input-border-radius);background:var(--swal2-input-background);box-shadow:var(--swal2-input-box-shadow);color:inherit;font-size:1.125em}div:where(.swal2-container) input:where(.swal2-input).swal2-inputerror,div:where(.swal2-container) input:where(.swal2-file).swal2-inputerror,div:where(.swal2-container) textarea:where(.swal2-textarea).swal2-inputerror{border-color:#f27474 !important;box-shadow:0 0 2px #f27474 !important}div:where(.swal2-container) input:where(.swal2-input):hover,div:where(.swal2-container) input:where(.swal2-file):hover,div:where(.swal2-container) textarea:where(.swal2-textarea):hover{box-shadow:var(--swal2-input-hover-box-shadow)}div:where(.swal2-container) input:where(.swal2-input):focus,div:where(.swal2-container) input:where(.swal2-file):focus,div:where(.swal2-container) textarea:where(.swal2-textarea):focus{border:var(--swal2-input-focus-border);outline:none;box-shadow:var(--swal2-input-focus-box-shadow)}div:where(.swal2-container) input:where(.swal2-input)::placeholder,div:where(.swal2-container) input:where(.swal2-file)::placeholder,div:where(.swal2-container) textarea:where(.swal2-textarea)::placeholder{color:#ccc}div:where(.swal2-container) .swal2-range{margin:1em 2em 3px;background:var(--swal2-background)}div:where(.swal2-container) .swal2-range input{width:80%}div:where(.swal2-container) .swal2-range output{width:20%;color:inherit;font-weight:600;text-align:center}div:where(.swal2-container) .swal2-range input,div:where(.swal2-container) .swal2-range output{height:2.625em;padding:0;font-size:1.125em;line-height:2.625em}div:where(.swal2-container) .swal2-input{height:2.625em;padding:0 .75em}div:where(.swal2-container) .swal2-file{width:75%;margin-right:auto;margin-left:auto;background:var(--swal2-input-background);font-size:1.125em}div:where(.swal2-container) .swal2-textarea{height:6.75em;padding:.75em}div:where(.swal2-container) .swal2-select{min-width:50%;max-width:100%;padding:.375em .625em;background:var(--swal2-input-background);color:inherit;font-size:1.125em}div:where(.swal2-container) .swal2-radio,div:where(.swal2-container) .swal2-checkbox{align-items:center;justify-content:center;background:var(--swal2-background);color:inherit}div:where(.swal2-container) .swal2-radio label,div:where(.swal2-container) .swal2-checkbox label{margin:0 .6em;font-size:1.125em}div:where(.swal2-container) .swal2-radio input,div:where(.swal2-container) .swal2-checkbox input{flex-shrink:0;margin:0 .4em}div:where(.swal2-container) label:where(.swal2-input-label){display:flex;justify-content:center;margin:1em auto 0}div:where(.swal2-container) div:where(.swal2-validation-message){align-items:center;justify-content:center;margin:1em 0 0;padding:.625em;overflow:hidden;background:var(--swal2-validation-message-background);color:var(--swal2-validation-message-color);font-size:1em;font-weight:300}div:where(.swal2-container) div:where(.swal2-validation-message)::before{content:"!";display:inline-block;width:1.5em;min-width:1.5em;height:1.5em;margin:0 .625em;border-radius:50%;background-color:#f27474;color:#fff;font-weight:600;line-height:1.5em;text-align:center}div:where(.swal2-container) .swal2-progress-steps{flex-wrap:wrap;align-items:center;max-width:100%;margin:1.25em auto;padding:0;background:rgba(0,0,0,0);font-weight:600}div:where(.swal2-container) .swal2-progress-steps li{display:inline-block;position:relative}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step{z-index:20;flex-shrink:0;width:2em;height:2em;border-radius:2em;background:#2778c4;color:#fff;line-height:2em;text-align:center}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step{background:#2778c4}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step{background:var(--swal2-progress-step-background);color:#fff}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step-line{background:var(--swal2-progress-step-background)}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step-line{z-index:10;flex-shrink:0;width:2.5em;height:.4em;margin:0 -1px;background:#2778c4}div:where(.swal2-icon){position:relative;box-sizing:content-box;justify-content:center;width:5em;height:5em;margin:2.5em auto .6em;zoom:var(--swal2-icon-zoom);border:.25em solid rgba(0,0,0,0);border-radius:50%;border-color:#000;font-family:inherit;line-height:5em;cursor:default;user-select:none}div:where(.swal2-icon) .swal2-icon-content{display:flex;align-items:center;font-size:3.75em}div:where(.swal2-icon).swal2-error{border-color:#f27474;color:#f27474}div:where(.swal2-icon).swal2-error .swal2-x-mark{position:relative;flex-grow:1}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line]{display:block;position:absolute;top:2.3125em;width:2.9375em;height:.3125em;border-radius:.125em;background-color:#f27474}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line][class$=left]{left:1.0625em;transform:rotate(45deg)}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line][class$=right]{right:1em;transform:rotate(-45deg)}@container swal2-popup style(--swal2-icon-animations:true){div:where(.swal2-icon).swal2-error.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-error.swal2-icon-show .swal2-x-mark{animation:swal2-animate-error-x-mark .5s}}div:where(.swal2-icon).swal2-warning{border-color:#f8bb86;color:#f8bb86}@container swal2-popup style(--swal2-icon-animations:true){div:where(.swal2-icon).swal2-warning.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-warning.swal2-icon-show .swal2-icon-content{animation:swal2-animate-i-mark .5s}}div:where(.swal2-icon).swal2-info{border-color:#3fc3ee;color:#3fc3ee}@container swal2-popup style(--swal2-icon-animations:true){div:where(.swal2-icon).swal2-info.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-info.swal2-icon-show .swal2-icon-content{animation:swal2-animate-i-mark .8s}}div:where(.swal2-icon).swal2-question{border-color:#87adbd;color:#87adbd}@container swal2-popup style(--swal2-icon-animations:true){div:where(.swal2-icon).swal2-question.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-question.swal2-icon-show .swal2-icon-content{animation:swal2-animate-question-mark .8s}}div:where(.swal2-icon).swal2-success{border-color:#a5dc86;color:#a5dc86}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line]{position:absolute;width:3.75em;height:7.5em;border-radius:50%}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line][class$=left]{top:-0.4375em;left:-2.0635em;transform:rotate(-45deg);transform-origin:3.75em 3.75em;border-radius:7.5em 0 0 7.5em}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line][class$=right]{top:-0.6875em;left:1.875em;transform:rotate(-45deg);transform-origin:0 3.75em;border-radius:0 7.5em 7.5em 0}div:where(.swal2-icon).swal2-success .swal2-success-ring{position:absolute;z-index:2;top:-0.25em;left:-0.25em;box-sizing:content-box;width:100%;height:100%;border:.25em solid rgba(165,220,134,.3);border-radius:50%}div:where(.swal2-icon).swal2-success .swal2-success-fix{position:absolute;z-index:1;top:.5em;left:1.625em;width:.4375em;height:5.625em;transform:rotate(-45deg)}div:where(.swal2-icon).swal2-success [class^=swal2-success-line]{display:block;position:absolute;z-index:2;height:.3125em;border-radius:.125em;background-color:#a5dc86}div:where(.swal2-icon).swal2-success [class^=swal2-success-line][class$=tip]{top:2.875em;left:.8125em;width:1.5625em;transform:rotate(45deg)}div:where(.swal2-icon).swal2-success [class^=swal2-success-line][class$=long]{top:2.375em;right:.5em;width:2.9375em;transform:rotate(-45deg)}@container swal2-popup style(--swal2-icon-animations:true){div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-animate-success-line-tip .75s}div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-animate-success-line-long .75s}div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-circular-line-right{animation:swal2-rotate-success-circular-line 4.25s ease-in}}[class^=swal2]{-webkit-tap-highlight-color:rgba(0,0,0,0)}.swal2-show{animation:var(--swal2-show-animation)}.swal2-hide{animation:var(--swal2-hide-animation)}.swal2-noanimation{transition:none}.swal2-scrollbar-measure{position:absolute;top:-9999px;width:50px;height:50px;overflow:scroll}.swal2-rtl .swal2-close{margin-right:initial;margin-left:0}.swal2-rtl .swal2-timer-progress-bar{right:0;left:auto}.swal2-toast{box-sizing:border-box;grid-column:1/4 !important;grid-row:1/4 !important;grid-template-columns:min-content auto min-content;padding:1em;overflow-y:hidden;border:var(--swal2-toast-border);background:var(--swal2-background);box-shadow:var(--swal2-toast-box-shadow);pointer-events:all}.swal2-toast>*{grid-column:2}.swal2-toast h2:where(.swal2-title){margin:.5em 1em;padding:0;font-size:1em;text-align:initial}.swal2-toast .swal2-loading{justify-content:center}.swal2-toast input:where(.swal2-input){height:2em;margin:.5em;font-size:1em}.swal2-toast .swal2-validation-message{font-size:1em}.swal2-toast div:where(.swal2-footer){margin:.5em 0 0;padding:.5em 0 0;font-size:.8em}.swal2-toast button:where(.swal2-close){grid-column:3/3;grid-row:1/99;align-self:center;width:.8em;height:.8em;margin:0;font-size:2em}.swal2-toast div:where(.swal2-html-container){margin:.5em 1em;padding:0;overflow:initial;font-size:1em;text-align:initial}.swal2-toast div:where(.swal2-html-container):empty{padding:0}.swal2-toast .swal2-loader{grid-column:1;grid-row:1/99;align-self:center;width:2em;height:2em;margin:.25em}.swal2-toast .swal2-icon{grid-column:1;grid-row:1/99;align-self:center;width:2em;min-width:2em;height:2em;margin:0 .5em 0 0}.swal2-toast .swal2-icon .swal2-icon-content{display:flex;align-items:center;font-size:1.8em;font-weight:bold}.swal2-toast .swal2-icon.swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line]{top:.875em;width:1.375em}.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:.3125em}.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:.3125em}.swal2-toast div:where(.swal2-actions){justify-content:flex-start;height:auto;margin:0;margin-top:.5em;padding:0 .5em}.swal2-toast button:where(.swal2-styled){margin:.25em .5em;padding:.4em .6em;font-size:1em}.swal2-toast .swal2-success{border-color:#a5dc86}.swal2-toast .swal2-success [class^=swal2-success-circular-line]{position:absolute;width:1.6em;height:3em;border-radius:50%}.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=left]{top:-0.8em;left:-0.5em;transform:rotate(-45deg);transform-origin:2em 2em;border-radius:4em 0 0 4em}.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=right]{top:-0.25em;left:.9375em;transform-origin:0 1.5em;border-radius:0 4em 4em 0}.swal2-toast .swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-toast .swal2-success .swal2-success-fix{top:0;left:.4375em;width:.4375em;height:2.6875em}.swal2-toast .swal2-success [class^=swal2-success-line]{height:.3125em}.swal2-toast .swal2-success [class^=swal2-success-line][class$=tip]{top:1.125em;left:.1875em;width:.75em}.swal2-toast .swal2-success [class^=swal2-success-line][class$=long]{top:.9375em;right:.1875em;width:1.375em}@container swal2-popup style(--swal2-icon-animations:true){.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-toast-animate-success-line-tip .75s}.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-toast-animate-success-line-long .75s}}.swal2-toast.swal2-show{animation:var(--swal2-toast-show-animation)}.swal2-toast.swal2-hide{animation:var(--swal2-toast-hide-animation)}@keyframes swal2-show{0%{transform:translate3d(0, -50px, 0) scale(0.9);opacity:0}100%{transform:translate3d(0, 0, 0) scale(1);opacity:1}}@keyframes swal2-hide{0%{transform:translate3d(0, 0, 0) scale(1);opacity:1}100%{transform:translate3d(0, -50px, 0) scale(0.9);opacity:0}}@keyframes swal2-animate-success-line-tip{0%{top:1.1875em;left:.0625em;width:0}54%{top:1.0625em;left:.125em;width:0}70%{top:2.1875em;left:-0.375em;width:3.125em}84%{top:3em;left:1.3125em;width:1.0625em}100%{top:2.8125em;left:.8125em;width:1.5625em}}@keyframes swal2-animate-success-line-long{0%{top:3.375em;right:2.875em;width:0}65%{top:3.375em;right:2.875em;width:0}84%{top:2.1875em;right:0;width:3.4375em}100%{top:2.375em;right:.5em;width:2.9375em}}@keyframes swal2-rotate-success-circular-line{0%{transform:rotate(-45deg)}5%{transform:rotate(-45deg)}12%{transform:rotate(-405deg)}100%{transform:rotate(-405deg)}}@keyframes swal2-animate-error-x-mark{0%{margin-top:1.625em;transform:scale(0.4);opacity:0}50%{margin-top:1.625em;transform:scale(0.4);opacity:0}80%{margin-top:-0.375em;transform:scale(1.15)}100%{margin-top:0;transform:scale(1);opacity:1}}@keyframes swal2-animate-error-icon{0%{transform:rotateX(100deg);opacity:0}100%{transform:rotateX(0deg);opacity:1}}@keyframes swal2-rotate-loading{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}@keyframes swal2-animate-question-mark{0%{transform:rotateY(-360deg)}100%{transform:rotateY(0)}}@keyframes swal2-animate-i-mark{0%{transform:rotateZ(45deg);opacity:0}25%{transform:rotateZ(-25deg);opacity:.4}50%{transform:rotateZ(15deg);opacity:.8}75%{transform:rotateZ(-5deg);opacity:1}100%{transform:rotateX(0);opacity:1}}@keyframes swal2-toast-show{0%{transform:translateY(-0.625em) rotateZ(2deg)}33%{transform:translateY(0) rotateZ(-2deg)}66%{transform:translateY(0.3125em) rotateZ(2deg)}100%{transform:translateY(0) rotateZ(0deg)}}@keyframes swal2-toast-hide{100%{transform:rotateZ(1deg);opacity:0}}@keyframes swal2-toast-animate-success-line-tip{0%{top:.5625em;left:.0625em;width:0}54%{top:.125em;left:.125em;width:0}70%{top:.625em;left:-0.25em;width:1.625em}84%{top:1.0625em;left:.75em;width:.5em}100%{top:1.125em;left:.1875em;width:.75em}}@keyframes swal2-toast-animate-success-line-long{0%{top:1.625em;right:1.375em;width:0}65%{top:1.25em;right:.9375em;width:0}84%{top:.9375em;right:0;width:1.125em}100%{top:.9375em;right:.1875em;width:1.375em}}')},7736(e){var t;t=function(e){var t=function(e){return new t.lib.init(e)};function s(e,t){return t.offset[e]?isNaN(t.offset[e])?t.offset[e]:t.offset[e]+"px":"0px"}function i(e,t){return!(!e||"string"!=typeof t||!(e.className&&e.className.trim().split(/\s+/gi).indexOf(t)>-1))}return t.defaults={oldestFirst:!0,text:"Toastify is awesome!",node:void 0,duration:3e3,selector:void 0,callback:function(){},destination:void 0,newWindow:!1,close:!1,gravity:"toastify-top",positionLeft:!1,position:"",backgroundColor:"",avatar:"",className:"",stopOnFocus:!0,onClick:function(){},offset:{x:0,y:0},escapeMarkup:!0,ariaLive:"polite",style:{background:""}},t.lib=t.prototype={toastify:"1.12.0",constructor:t,init:function(e){return e||(e={}),this.options={},this.toastElement=null,this.options.text=e.text||t.defaults.text,this.options.node=e.node||t.defaults.node,this.options.duration=0===e.duration?0:e.duration||t.defaults.duration,this.options.selector=e.selector||t.defaults.selector,this.options.callback=e.callback||t.defaults.callback,this.options.destination=e.destination||t.defaults.destination,this.options.newWindow=e.newWindow||t.defaults.newWindow,this.options.close=e.close||t.defaults.close,this.options.gravity="bottom"===e.gravity?"toastify-bottom":t.defaults.gravity,this.options.positionLeft=e.positionLeft||t.defaults.positionLeft,this.options.position=e.position||t.defaults.position,this.options.backgroundColor=e.backgroundColor||t.defaults.backgroundColor,this.options.avatar=e.avatar||t.defaults.avatar,this.options.className=e.className||t.defaults.className,this.options.stopOnFocus=void 0===e.stopOnFocus?t.defaults.stopOnFocus:e.stopOnFocus,this.options.onClick=e.onClick||t.defaults.onClick,this.options.offset=e.offset||t.defaults.offset,this.options.escapeMarkup=void 0!==e.escapeMarkup?e.escapeMarkup:t.defaults.escapeMarkup,this.options.ariaLive=e.ariaLive||t.defaults.ariaLive,this.options.style=e.style||t.defaults.style,e.backgroundColor&&(this.options.style.background=e.backgroundColor),this},buildToast:function(){if(!this.options)throw"Toastify is not initialized";var e=document.createElement("div");for(var t in e.className="toastify on "+this.options.className,this.options.position?e.className+=" toastify-"+this.options.position:!0===this.options.positionLeft?(e.className+=" toastify-left",console.warn("Property `positionLeft` will be depreciated in further versions. Please use `position` instead.")):e.className+=" toastify-right",e.className+=" "+this.options.gravity,this.options.backgroundColor&&console.warn('DEPRECATION NOTICE: "backgroundColor" is being deprecated. Please use the "style.background" property.'),this.options.style)e.style[t]=this.options.style[t];if(this.options.ariaLive&&e.setAttribute("aria-live",this.options.ariaLive),this.options.node&&this.options.node.nodeType===Node.ELEMENT_NODE)e.appendChild(this.options.node);else if(this.options.escapeMarkup?e.innerText=this.options.text:e.innerHTML=this.options.text,""!==this.options.avatar){var i=document.createElement("img");i.src=this.options.avatar,i.className="toastify-avatar","left"==this.options.position||!0===this.options.positionLeft?e.appendChild(i):e.insertAdjacentElement("afterbegin",i)}if(!0===this.options.close){var n=document.createElement("button");n.type="button",n.setAttribute("aria-label","Close"),n.className="toast-close",n.innerHTML="✖",n.addEventListener("click",function(e){e.stopPropagation(),this.removeElement(this.toastElement),window.clearTimeout(this.toastElement.timeOutValue)}.bind(this));var o=window.innerWidth>0?window.innerWidth:screen.width;("left"==this.options.position||!0===this.options.positionLeft)&&o>360?e.insertAdjacentElement("afterbegin",n):e.appendChild(n)}if(this.options.stopOnFocus&&this.options.duration>0){var a=this;e.addEventListener("mouseover",function(t){window.clearTimeout(e.timeOutValue)}),e.addEventListener("mouseleave",function(){e.timeOutValue=window.setTimeout(function(){a.removeElement(e)},a.options.duration)})}if(void 0!==this.options.destination&&e.addEventListener("click",function(e){e.stopPropagation(),!0===this.options.newWindow?window.open(this.options.destination,"_blank"):window.location=this.options.destination}.bind(this)),"function"==typeof this.options.onClick&&void 0===this.options.destination&&e.addEventListener("click",function(e){e.stopPropagation(),this.options.onClick()}.bind(this)),"object"==typeof this.options.offset){var r=s("x",this.options),l=s("y",this.options),c="left"==this.options.position?r:"-"+r,d="toastify-top"==this.options.gravity?l:"-"+l;e.style.transform="translate("+c+","+d+")"}return e},showToast:function(){var e;if(this.toastElement=this.buildToast(),!(e="string"==typeof this.options.selector?document.getElementById(this.options.selector):this.options.selector instanceof HTMLElement||"undefined"!=typeof ShadowRoot&&this.options.selector instanceof ShadowRoot?this.options.selector:document.body))throw"Root element is not defined";var s=t.defaults.oldestFirst?e.firstChild:e.lastChild;return e.insertBefore(this.toastElement,s),t.reposition(),this.options.duration>0&&(this.toastElement.timeOutValue=window.setTimeout(function(){this.removeElement(this.toastElement)}.bind(this),this.options.duration)),this},hideToast:function(){this.toastElement.timeOutValue&&clearTimeout(this.toastElement.timeOutValue),this.removeElement(this.toastElement)},removeElement:function(e){e.className=e.className.replace(" on",""),window.setTimeout(function(){this.options.node&&this.options.node.parentNode&&this.options.node.parentNode.removeChild(this.options.node),e.parentNode&&e.parentNode.removeChild(e),this.options.callback.call(e),t.reposition()}.bind(this),400)}},t.reposition=function(){for(var e,t={top:15,bottom:15},s={top:15,bottom:15},n={top:15,bottom:15},o=document.getElementsByClassName("toastify"),a=0;a<o.length;a++){e=!0===i(o[a],"toastify-top")?"toastify-top":"toastify-bottom";var r=o[a].offsetHeight;e=e.substr(9,e.length-1),(window.innerWidth>0?window.innerWidth:screen.width)<=360?(o[a].style[e]=n[e]+"px",n[e]+=r+15):!0===i(o[a],"toastify-left")?(o[a].style[e]=t[e]+"px",t[e]+=r+15):(o[a].style[e]=s[e]+"px",s[e]+=r+15)}return this},t.lib.init.prototype=t.lib,t},e.exports?e.exports=t():this.Toastify=t()}},t={};function s(i){var n=t[i];if(void 0!==n)return n.exports;var o=t[i]={id:i,exports:{}};return e[i].call(o.exports,o,o.exports,s),o.exports}s.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return s.d(t,{a:t}),t},s.d=(e,t)=>{for(var i in t)s.o(t,i)&&!s.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.nc=void 0,(()=>{"use strict";var e=s(4223),t=s(8465),i=s.n(t),n=s(2603);const o='<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_3318_1035)"><path fill-rule="evenodd" clip-rule="evenodd" d="M30.628 4C31.6888 4.00023 32.706 4.4218 33.456 5.172L42.828 14.544C43.5782 15.294 43.9998 16.3112 44 17.372V30.628C43.9998 31.6888 43.5782 32.706 42.828 33.456L33.456 42.828C32.706 43.5782 31.6888 43.9998 30.628 44H17.372C16.3112 43.9998 15.294 43.5782 14.544 42.828L5.172 33.456C4.4218 32.706 4.00023 31.6888 4 30.628V17.372C4.00023 16.3112 4.4218 15.294 5.172 14.544L14.544 5.172C15.294 4.4218 16.3112 4.00023 17.372 4H30.628ZM24 30C23.4696 30 22.9609 30.2107 22.5858 30.5858C22.2107 30.9609 22 31.4696 22 32C22 32.5304 22.2107 33.0391 22.5858 33.4142C22.9609 33.7893 23.4696 34 24 34C24.5304 34 25.0391 33.7893 25.4142 33.4142C25.7893 33.0391 26 32.5304 26 32C26 31.4696 25.7893 30.9609 25.4142 30.5858C25.0391 30.2107 24.5304 30 24 30ZM24 12C23.5101 12.0001 23.0373 12.1799 22.6713 12.5054C22.3052 12.8309 22.0713 13.2795 22.014 13.766L22 14V26C22.0006 26.5098 22.1958 27.0001 22.5457 27.3707C22.8956 27.7414 23.3739 27.9645 23.8828 27.9943C24.3917 28.0242 24.8928 27.8587 25.2837 27.5315C25.6746 27.2043 25.9258 26.7402 25.986 26.234L26 26V14C26 13.4696 25.7893 12.9609 25.4142 12.5858C25.0391 12.2107 24.5304 12 24 12Z" fill="#F8A100"/></g><defs><clipPath id="clip0_3318_1035"><rect width="48" height="48" fill="white"/></clipPath></defs></svg>',a='<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_3318_1040)"><path d="M24 4C35.046 4 44 12.954 44 24C44 35.046 35.046 44 24 44C12.954 44 4 35.046 4 24C4 12.954 12.954 4 24 4ZM23.98 20H22C21.4902 20.0006 20.9999 20.1958 20.6293 20.5457C20.2586 20.8956 20.0355 21.3739 20.0057 21.8828C19.9758 22.3917 20.1413 22.8928 20.4685 23.2837C20.7957 23.6746 21.2598 23.9258 21.766 23.986L22 24V33.98C22 35.02 22.788 35.88 23.8 35.988L24.02 36H25C25.4206 36 25.8305 35.8674 26.1715 35.621C26.5124 35.3747 26.767 35.0271 26.899 34.6277C27.031 34.2283 27.0337 33.7975 26.9068 33.3965C26.7799 32.9955 26.5298 32.6447 26.192 32.394L26 32.268V22.02C26 20.98 25.212 20.12 24.2 20.012L23.98 20ZM24 14C23.4696 14 22.9609 14.2107 22.5858 14.5858C22.2107 14.9609 22 15.4696 22 16C22 16.5304 22.2107 17.0391 22.5858 17.4142C22.9609 17.7893 23.4696 18 24 18C24.5304 18 25.0391 17.7893 25.4142 17.4142C25.7893 17.0391 26 16.5304 26 16C26 15.4696 25.7893 14.9609 25.4142 14.5858C25.0391 14.2107 24.5304 14 24 14Z" fill="#2E91FA"/></g><defs><clipPath id="clip0_3318_1040"><rect width="48" height="48" fill="white"/></clipPath></defs></svg>',r='<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_5385_4939)"><path d="M26.5983 6.2959L43.8663 36.2039C44.1297 36.66 44.2683 37.1773 44.2683 37.7039C44.2683 38.2305 44.1297 38.7478 43.8664 39.2039C43.6031 39.6599 43.2244 40.0386 42.7683 40.3019C42.3123 40.5653 41.795 40.7039 41.2683 40.7039H6.73235C6.20574 40.7039 5.68842 40.5653 5.23237 40.3019C4.77633 40.0386 4.39762 39.6599 4.13433 39.2039C3.87103 38.7478 3.73242 38.2305 3.73242 37.7039C3.73243 37.1773 3.87104 36.66 4.13435 36.2039L21.4023 6.2959C22.5563 4.2959 25.4423 4.2959 26.5983 6.2959ZM24.0003 29.9999C23.4699 29.9999 22.9612 30.2106 22.5861 30.5857C22.2111 30.9608 22.0003 31.4695 22.0003 31.9999C22.0003 32.5303 22.2111 33.039 22.5861 33.4141C22.9612 33.7892 23.4699 33.9999 24.0003 33.9999C24.5308 33.9999 25.0395 33.7892 25.4146 33.4141C25.7896 33.039 26.0003 32.5303 26.0003 31.9999C26.0003 31.4695 25.7896 30.9608 25.4146 30.5857C25.0395 30.2106 24.5308 29.9999 24.0003 29.9999ZM24.0003 15.9999C23.5105 16 23.0377 16.1798 22.6716 16.5053C22.3055 16.8308 22.0717 17.2794 22.0143 17.7659L22.0003 17.9999V25.9999C22.0009 26.5097 22.1961 27 22.546 27.3706C22.896 27.7413 23.3743 27.9644 23.8831 27.9942C24.392 28.0241 24.8931 27.8586 25.284 27.5314C25.6749 27.2042 25.9261 26.7401 25.9863 26.2339L26.0003 25.9999V17.9999C26.0003 17.4695 25.7896 16.9608 25.4146 16.5857C25.0395 16.2106 24.5308 15.9999 24.0003 15.9999Z" fill="#E31A1A"/></g><defs><clipPath id="clip0_5385_4939"><rect width="48" height="48" fill="white"/></clipPath></defs></svg>';class l{constructor(){this.init()}static selectors={elBtnCreateCourse:"a.cb-btn-add-new[href]",elCourseItem:".course-item",elCourseExpandedItems:".course-action-expanded__items",elCourseDuplicate:".course-action-expanded__duplicate",elCourseTrash:".course-action-expanded__trash",elCourseDraft:".course-action-expanded__draft",elCourseDelete:".course-action-expanded__delete",elCourseActionExpanded:".course-action-expanded",elCourseStatus:".course-status"};init(){this.events()}events(){l._loadedEvents||(l._loadedEvents=!0,e.eventHandlers("click",[{selector:l.selectors.elCourseDuplicate,class:this,callBack:this.duplicateCourse.name},{selector:l.selectors.elCourseTrash,class:this,callBack:this.trashCourse.name},{selector:l.selectors.elCourseDraft,class:this,callBack:this.draftCourse.name},{selector:l.selectors.elCourseDelete,class:this,callBack:this.deleteCourse.name},{selector:l.selectors.elCourseActionExpanded,class:this,callBack:this.toggleExpandedAction.name},{selector:l.selectors.elBtnCreateCourse,callBack:t=>{const{target:s}=t,i=s.closest(l.selectors.elBtnCreateCourse);i&&e.lpSetLoadingEl(i,1)}}]),document.addEventListener("click",e=>{e.target.closest(l.selectors.elCourseActionExpanded)||this.closeAllExpanded()}))}duplicateCourse(t){const{target:s}=t,o=s.closest(l.selectors.elCourseDuplicate),r=o.closest(l.selectors.elCourseItem);if(!r)return;const c=r.dataset.courseId||"";c&&i().fire({title:o.dataset.title||"Duplicate Course",text:o.dataset.content||"Are you sure you want to duplicate this course?",iconHtml:a,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(o,1);const t={action:"duplicate_course",args:{id_url:"duplicate-course"},course_id:c},s={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s||"Duplicated successfully!",t),i?.html){const e=o.closest(".course"),t=e.closest(".courses-list")||e.parentElement;if(t){t.insertAdjacentHTML("afterbegin",i.html);const e=t.firstElementChild;e&&(e.scrollIntoView({behavior:"smooth",block:"nearest"}),e.classList.add("highlight-new-course"),setTimeout(()=>{e.classList.remove("highlight-new-course")},1500))}}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(o,0)}};window.lpAJAXG.fetchAJAX(t,s)}})}trashCourse(t){const{target:s}=t,a=s.closest(l.selectors.elCourseTrash),r=a.closest(l.selectors.elCourseItem);if(!r)return;const c=r.dataset.courseId||"";i().fire({title:a.dataset.title||"Trash Course",text:a.dataset.content||"Are you sure you want to move this course to trash?",iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(a,1);const t={action:"move_trash_course",args:{id_url:"move-trash-course"},course_id:c},s={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),i?.status){const e=a.closest(".course");this.updateStatusUI(e,i.status)}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(t,s)}})}draftCourse(e){const{target:t}=e,s=t.closest(l.selectors.elCourseDraft),n=s.closest(l.selectors.elCourseItem);if(!n)return;const a=n.querySelector(l.selectors.elCourseStatus);if(a&&a.classList.contains("publish")){const e=s.dataset.confirmUnpublish||"Saving as draft will unpublish this item. Are you sure?";return void i().fire({title:"Draft Course",text:e,iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(e=>{e.isConfirmed&&this.draftCourseExecute(s,n)})}this.draftCourseExecute(s,n)}draftCourseExecute(t,s){e.lpSetLoadingEl(t,1);const i={action:"move_trash_course",args:{id_url:"move-trash-course"},course_id:s.dataset.courseId||0,status:"draft"},o={success:e=>{const{status:s,message:i,data:o}=e;if(n.W(i,s),o?.status){const e=t.closest(".course");this.updateStatusUI(e,o.status)}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(t,0)}};window.lpAJAXG.fetchAJAX(i,o)}deleteCourse(e){const{target:t}=e,s=t.closest(l.selectors.elCourseDelete),o=s.closest(l.selectors.elCourseItem);if(!o)return;const a=o.dataset.courseId||"";a&&i().fire({title:s.dataset.title||"Delete Course",text:s.dataset.content||"Are you sure you want to permanently delete this course?",iconHtml:r,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(e=>{if(e.isConfirmed){const e={action:"move_trash_course",args:{id_url:"move-trash-course"},course_id:a,status:"delete"},t={success:e=>{const{status:t,message:i}=e;n.W(i,t);const o=s.closest(".course");o.style.transition="opacity 0.4s ease-out, transform 0.4s ease-out",o.style.opacity="0",o.style.transform="translateX(160px)",setTimeout(()=>{o.remove()},400)},error:e=>{n.W(e.message||e,"error")}};window.lpAJAXG.fetchAJAX(e,t)}})}toggleExpandedAction(e){const{target:t}=e,s=t.closest(l.selectors.elCourseActionExpanded);if(!s)return;const i=s.closest(l.selectors.elCourseItem);if(!i)return;const n=i.querySelector(l.selectors.elCourseExpandedItems);n&&(this.closeAllExpanded(n),n.classList.toggle("active"),s.classList.toggle("active"))}closeAllExpanded(e=null){document.querySelectorAll(`${l.selectors.elCourseExpandedItems}.active`).forEach(t=>{if(t===e)return;t.classList.remove("active");const s=t.closest(l.selectors.elCourseItem);if(!s)return;const i=s.querySelector(l.selectors.elCourseActionExpanded);i&&i.classList.remove("active")})}updateStatusUI(e,t){const s=e.querySelector(l.selectors.elCourseStatus),i=e.querySelector(`${l.selectors.elCourseStatus} span`);i&&s&&(s.className="course-status "+t,i.textContent=t)}}var c=s(246);let d,u,h=[];class p{constructor(){this.init()}static selectors={elBtnShowPopupItemsToSelect:".lp-btn-show-popup-items-to-select",elBtnAddItemsSelected:".lp-btn-add-items-selected",elBtnCountItemsSelected:".lp-btn-count-items-selected",elHeaderCountItemSelected:".header-count-items-selected",elSelectItem:".lp-select-item",elListItems:".list-items",elPopupItemsToSelect:".lp-popup-items-to-select",elSearchTitleItem:".lp-search-title-item",elBtnBackListItems:".lp-btn-back-to-select-items",elListItemsWrap:".list-items-wrap",elListItemsSelected:".list-items-selected",elItemSelectedClone:".li-item-selected.clone",elItemSelected:".li-item-selected",LPTarget:".lp-target"};init(){this.events()}events=()=>{p._loadedEvents||(p._loadedEvents=!0,e.eventHandlers("click",[{selector:p.selectors.elBtnShowPopupItemsToSelect,callBack:this.showPopupItemsToSelect.name,class:this},{selector:p.selectors.elSelectItem,callBack:this.selectItemsFromList.name,class:this},{selector:p.selectors.elBtnCountItemsSelected,callBack:this.showItemsSelected.name,class:this},{selector:p.selectors.elBtnBackListItems,callBack:this.backToSelectItems.name,class:this},{selector:p.selectors.elItemSelected,callBack:this.removeItemSelected.name,class:this},{selector:".tabs .tab",callBack:this.chooseTabItemsType.name,class:this}]),e.eventHandlers("keyup",[{selector:p.selectors.elSearchTitleItem,callBack:this.searchTitleItemToSelect.name,class:this}]))};showPopupItemsToSelect=e=>{const{e:t,target:s=!1,callBack:n}=e;if(!s.closest(`${p.selectors.elBtnShowPopupItemsToSelect}`))return;h=[];const o=s.dataset.template||"",a=document.querySelector(o);i().fire({html:a.innerHTML,showConfirmButton:!1,showCloseButton:!0,width:"60%",customClass:{popup:"lp-select-items-popup",htmlContainer:"lp-select-items-html-container",container:"lp-select-items-container"},willOpen:()=>{d=i().getPopup();const e=d.querySelector(`${p.selectors.LPTarget}`);if(e){const t=window.lpAJAXG.getDataSetCurrent(e);t.args.paged=1,t.args.item_selecting=h||[],window.lpAJAXG.setDataSetCurrent(e,t),window.lpAJAXG.fetchAJAX(t,{success:t=>{const{data:s}=t;d.querySelector(".lp-skeleton-animation").remove(),e.innerHTML=s.content||"",this.watchItemsSelectedDataChange()}})}}}).then(e=>{e.isDismissed})};chooseTabItemsType=e=>{const{e:t,target:s,callBack:i}=e,o=s.closest(".tab");if(!o)return;t.preventDefault();const a=o.closest(".tabs");if(!a)return;const r=a.closest(`${p.selectors.elPopupItemsToSelect}`),l=r.querySelector(`${p.selectors.elSearchTitleItem}`),c=o.dataset.type;a.querySelectorAll(".tab").forEach(e=>{e.classList.contains("active")&&e.classList.remove("active")}),o.classList.add("active"),l.value="";const d=r.querySelector(`${p.selectors.LPTarget}`),u=window.lpAJAXG.getDataSetCurrent(d);u.args.item_type=c,u.args.paged=1,u.args.item_selecting=h||[],window.lpAJAXG.setDataSetCurrent(d,u),window.lpAJAXG.showHideLoading(d,1),window.lpAJAXG.fetchAJAX(u,{success:e=>{const{data:t}=e;d.innerHTML=t.content||""},error:e=>{n.W(e,"error")},completed:()=>{window.lpAJAXG.showHideLoading(d,0),this.watchItemsSelectedDataChange()}})};selectItemsFromList=e=>{const{e:t,target:s}=e,i=s.closest(`${p.selectors.elSelectItem}`);if(!i)return;const n=i.querySelector('input[type="checkbox"]');if("INPUT"!==s.tagName)return void n.click();if(!i.closest(`${p.selectors.elListItems}`))return;const o={...n.dataset};if(n.checked)h.some(e=>e.id===o.id)||h.push(o);else{const e=h.findIndex(e=>e.id===o.id);-1!==e&&h.splice(e,1)}this.watchItemsSelectedDataChange()};searchTitleItemToSelect=e=>{const{e:t,target:s}=e,i=s.closest(p.selectors.elSearchTitleItem);if(!i)return;const o=d.querySelector(`${p.selectors.LPTarget}`);clearTimeout(u),u=setTimeout(()=>{const e=window.lpAJAXG.getDataSetCurrent(o);e.args.search_title=i.value.trim(),e.args.item_selecting=h,e.args.paged=1,window.lpAJAXG.setDataSetCurrent(o,e),window.lpAJAXG.showHideLoading(o,1),window.lpAJAXG.fetchAJAX(e,{success:e=>{const{data:t}=e;o.innerHTML=t.content||""},error:e=>{n.W(e,"error")},completed:()=>{window.lpAJAXG.showHideLoading(o,0)}})},800)};showItemsSelected=t=>{const{e:s,target:i}=t,n=i.closest(`${p.selectors.elBtnCountItemsSelected}`);if(!n)return;const o=d.querySelector(`${p.selectors.elBtnBackListItems}`),a=d.querySelector(".tabs"),r=d.querySelector(`${p.selectors.elListItemsWrap}`),l=d.querySelector(`${p.selectors.elHeaderCountItemSelected}`),c=d.querySelector(`${p.selectors.elListItemsSelected}`),u=c.querySelector(`${p.selectors.elItemSelectedClone}`);l.innerHTML=n.innerHTML,e.lpShowHideEl(r,0),e.lpShowHideEl(n,0),e.lpShowHideEl(a,0),e.lpShowHideEl(o,1),e.lpShowHideEl(l,1),e.lpShowHideEl(c,1),c.querySelectorAll(`${p.selectors.elItemSelected}:not(.clone)`).forEach(e=>{e.remove()}),h.forEach(t=>{const s=u.cloneNode(!0);s.classList.remove("clone"),Object.entries(t).forEach(([e,t])=>{s.dataset[e]=t}),s.querySelector(".title-display").innerHTML=t.title,e.lpShowHideEl(s,1),u.insertAdjacentElement("beforebegin",s)})};backToSelectItems=t=>{const{e:s,target:i}=t,n=i.closest(`${p.selectors.elBtnBackListItems}`);if(!n)return;const o=d.querySelector(`${p.selectors.elBtnCountItemsSelected}`),a=d.querySelector(".tabs"),r=d.querySelector(`${p.selectors.elListItemsWrap}`),l=d.querySelector(`${p.selectors.elHeaderCountItemSelected}`),c=d.querySelector(`${p.selectors.elListItemsSelected}`);e.lpShowHideEl(o,1),e.lpShowHideEl(r,1),e.lpShowHideEl(a,1),e.lpShowHideEl(n,0),e.lpShowHideEl(l,0),e.lpShowHideEl(c,0)};removeItemSelected=e=>{const{e:t,target:s}=e,i=s.closest(`${p.selectors.elItemSelected}`);if(!i)return;const n=i.dataset,o=h.findIndex(e=>e.id===n.id);-1!==o&&h.splice(o,1),i.remove(),this.watchItemsSelectedDataChange()};watchItemsSelectedDataChange=()=>{const e=d.querySelector(`${p.selectors.elBtnAddItemsSelected}`),t=d.querySelector(`${p.selectors.elBtnCountItemsSelected}`),s=t.querySelector("span"),i=d.querySelector(`${p.selectors.elHeaderCountItemSelected}`),n=d.querySelector(`${p.selectors.LPTarget}`);0!==h.length?(t.disabled=!1,e.disabled=!1,e.classList.add("active"),s.textContent=`(${h.length})`,i.innerHTML=t.innerHTML):(t.disabled=!0,e.disabled=!0,e.classList.remove("active"),s.textContent="",i.textContent=""),d.querySelector(`${p.selectors.elListItems}`).querySelectorAll('input[type="checkbox"]').forEach(e=>{const t=e.dataset,s=h.some(e=>e.id===t.id);e.checked=s});const o=window.lpAJAXG.getDataSetCurrent(n);o.args.item_selecting=h,window.lpAJAXG.setDataSetCurrent(n,o)};addItemsSelectedToSection=e=>{const{e:t,target:s,callBackHandle:n}=e;d&&(i().close(),"function"==typeof n&&(n(h),h=[]))}}const m="edit-course-curriculum",g=new p;class f{constructor(){this.courseId=null,this.elCurriculumSections=null,this.sectionIdSelected=null}static selectors={elSectionListItems:".section-list-items",elItemClone:".section-item.clone",elSectionItem:".section-item",elBtnSelectItemType:".lp-btn-select-item-type",elAddItemTypeClone:".lp-add-item-type.clone",elSectionActions:".section-actions",elAddItemType:".lp-add-item-type",elAddItemTypeTitleInput:".lp-add-item-type-title-input",elBtnAddItemCancel:".lp-btn-add-item-cancel",elBtnAddItem:".lp-btn-add-item",elItemTitleInput:".lp-item-title-input",elBtnUpdateItemTitle:".lp-btn-update-item-title",elBtnCancelUpdateTitle:".lp-btn-cancel-update-item-title",elBtnDeleteItem:".lp-btn-delete-item",elBtnSetPreviewItem:".lp-btn-set-preview-item"};init(){this.elEditCurriculum=document.querySelector(`${w.selectors.idElEditCurriculum}`),this.elCurriculumSections=this.elEditCurriculum.querySelector(`${w.selectors.elCurriculumSections}`);const e=this.elEditCurriculum.closest(`${w.selectors.LPTarget}`),t=window.lpAJAXG.getDataSetCurrent(e);this.courseId=t.args.course_id,this.events(),this.sortAbleItem(),g.init()}events(){f._loadedEvents||(f._loadedEvents=this,e.eventHandlers("click",[{selector:f.selectors.elBtnSelectItemType,class:this,callBack:this.addItemType.name},{selector:f.selectors.elBtnAddItem,class:this,callBack:this.addItemToSection.name},{selector:f.selectors.elBtnAddItemCancel,class:this,callBack:this.cancelAddItemType.name},{selector:f.selectors.elBtnUpdateItemTitle,class:this,callBack:this.updateTitle.name},{selector:f.selectors.elBtnCancelUpdateTitle,class:this,callBack:this.cancelUpdateTitle.name},{selector:f.selectors.elBtnDeleteItem,class:this,callBack:this.deleteItem.name},{selector:p.selectors.elBtnShowPopupItemsToSelect,class:this,callBack:this.handleShowPopupItemsToSelect.name},{selector:p.selectors.elBtnAddItemsSelected,class:g,callBack:g.addItemsSelectedToSection.name,callBackHandle:this.addItemsSelectedToSection.bind(this)},{selector:f.selectors.elBtnSetPreviewItem,class:this,callBack:this.updatePreviewItem.name}]),e.eventHandlers("keyup",[{selector:f.selectors.elItemTitleInput,class:this,callBack:this.changeTitle.name},{selector:f.selectors.elAddItemTypeTitleInput,class:this,callBack:this.changeTitleAddNew.name}]),e.eventHandlers("keydown",[{selector:f.selectors.elAddItemTypeTitleInput,class:this,callBack:this.addItemToSection.name,checkIsEventEnter:!0},{selector:f.selectors.elItemTitleInput,class:this,callBack:this.updateTitle.name,checkIsEventEnter:!0}]),e.eventHandlers("focusin",[{selector:f.selectors.elItemTitleInput,class:this,callBack:this.focusTitleInput.name}]),e.eventHandlers("focusout",[{selector:f.selectors.elItemTitleInput,class:this,callBack:this.focusTitleInput.name,focusIn:!1}]))}handleShowPopupItemsToSelect(e){const{e:t,target:s}=e;if(s.closest(".lp-edit-quiz-wrap"))return void(this.sectionIdSelected=null);const i=s.closest(b.selectors.elSection),n=s.closest("#lp-course-edit-curriculum")||s.closest(".lp-edit-curriculum-wrap");this.sectionIdSelected=i&&n?i.dataset.sectionId:null}addItemType(t){const{e:s,target:i}=t,n=i,o=n.dataset.itemType,a=n.dataset.placeholder,r=n.dataset.buttonAddText,l=n.closest(`${b.selectors.elSection}`).querySelector(`${f.selectors.elSectionActions}`),c=l.querySelector(`${f.selectors.elAddItemTypeClone}`).cloneNode(!0),d=c.querySelector(`${f.selectors.elAddItemTypeTitleInput}`),u=c.querySelector(`${f.selectors.elBtnAddItem}`);c.classList.remove("clone"),c.classList.add(o),e.lpShowHideEl(c,1),d.setAttribute("placeholder",a),d.dataset.itemType=o,u.textContent=r,l.insertAdjacentElement("beforebegin",c),d.focus()}cancelAddItemType(e){const{e:t,target:s}=e,i=s.closest(`${f.selectors.elAddItemType}`);i&&i.remove()}addItemToSection(t){const{e:s,target:i,callBackNest:o}=t;s.preventDefault();const a=i.closest(`${f.selectors.elAddItemType}`),r=a.closest(`${b.selectors.elSection}`),l=r.dataset.sectionId,c=a.querySelector(`${f.selectors.elAddItemTypeTitleInput}`),d=c.value.trim(),u=c.dataset.itemType,h=c.dataset.messEmptyTitle;if(0===d.length)return void n.W(h,"error");const p=r.querySelector(`${f.selectors.elItemClone}`),g=p.cloneNode(!0),v=g.querySelector(`${f.selectors.elItemTitleInput}`);g.classList.remove("clone"),g.classList.add(u),g.dataset.itemType=u,e.lpShowHideEl(g,1),e.lpSetLoadingEl(g,1),v.value=d,v.dataset.old=d,p.insertAdjacentElement("beforebegin",g),a.remove();const y={success:e=>{const{message:s,status:i,data:a}=e;if(n.W(s,i),"error"===i)g.remove();else if("success"===i){const{section_item:e,item_link:s}=a||{},i=e.item_id||0;g.dataset.itemId=i,g.querySelector(".edit-link").setAttribute("href",s||""),this.addPopupAttributesToItem(g,i,u),o&&"function"==typeof o.success&&(t.elItemNew=g,o.success(t))}},error:e=>{n.W(e,"error"),g.remove()},completed:()=>{e.lpSetLoadingEl(g,0),this.updateCountItems(r),o&&"function"==typeof o.completed&&(t.elItemNew=g,o.completed(t))}},w={course_id:this.courseId,action:"create_item_add_to_section",section_id:l,item_title:d,item_type:u,args:{id_url:m}};document.querySelector("#lp-course-builder")&&(w.is_course_builder=1),window.lpAJAXG.fetchAJAX(w,y)}changeTitle(e){const{target:t}=e,s=t.closest(`${f.selectors.elItemTitleInput}`);if(!s)return;const i=s.closest(`${f.selectors.elSectionItem}`);i&&(s.value.trim()===(s.dataset.old||"")?i.classList.remove("editing"):i.classList.add("editing"))}focusTitleInput(e){const{target:t,focusIn:s=!0}=e,i=t.closest(`${f.selectors.elItemTitleInput}`);if(!i)return;const n=i.closest(`${f.selectors.elSectionItem}`);n&&(s?n.classList.add("focus"):n.classList.remove("focus"))}changeTitleAddNew(e){const{target:t}=e,s=t.closest(`${f.selectors.elAddItemTypeTitleInput}`);if(!s)return;const i=s.closest(`${f.selectors.elAddItemType}`);if(!i)return;const n=i.querySelector(`${f.selectors.elBtnAddItem}`);n&&(0===s.value.trim().length?n.classList.remove("active"):n.classList.add("active"))}updateTitle(t){const{e:s,target:i}=t;s.preventDefault();const o=i.closest(`${f.selectors.elSectionItem}`);if(!o)return;const a=o.closest(`${b.selectors.elSection}`);if(!a)return;const r=o.querySelector(`${f.selectors.elItemTitleInput}`);if(!r)return;const l=o.dataset.itemId,c=o.dataset.itemType,d=r.value.trim(),u=r.dataset.old,h=r.dataset.messEmptyTitle;if(0===d.length)return void n.W(h,"error");if(d===u)return;r.blur(),e.lpSetLoadingEl(o,1);const p={success:e=>{const{message:t,status:s}=e;"success"===s?r.dataset.old=d:r.value=u,n.W(t,s)},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(o,0),o.classList.remove("editing")}},g={course_id:this.courseId,action:"update_item_of_section",section_id:a.dataset.sectionId,item_id:l,item_type:c,item_title:d,args:{id_url:m}};window.lpAJAXG.fetchAJAX(g,p)}cancelUpdateTitle(e){const{e:t,target:s}=e,i=s.closest(`${f.selectors.elBtnCancelUpdateTitle}`);if(!i)return;const n=i.closest(`${f.selectors.elSectionItem}`),o=n.querySelector(`${f.selectors.elItemTitleInput}`);o.value=o.dataset.old||"",n.classList.remove("editing")}deleteItem(t){const{e:s,target:o}=t,a=o.closest(`${f.selectors.elBtnDeleteItem}`);if(!a)return;const r=a.closest(`${f.selectors.elSectionItem}`);if(!r)return;const l=r.dataset.itemId,c=r.closest(`${b.selectors.elSection}`),d=c.dataset.sectionId;i().fire({title:a.dataset.title,text:a.dataset.content,icon:"warning",showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(r,1);const t={success:e=>{const{message:t,status:s}=e;n.W(t,s),"success"===s&&r.remove()},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(r,0),this.updateCountItems(c)}},s={course_id:this.courseId,action:"delete_item_from_section",section_id:d,item_id:l,args:{id_url:m}};window.lpAJAXG.fetchAJAX(s,t)}})}sortAbleItem(){const t=this.elCurriculumSections.querySelectorAll(`${f.selectors.elSectionListItems}`);let s,i=0,o=0,a=0;t.forEach(t=>{new c.Ay(t,{handle:".drag",animation:150,group:{name:"shared"},onEnd:t=>{const r=[],l=t.item;a=l.closest(`${b.selectors.elSection}`).dataset.sectionId;const c={course_id:this.courseId,args:{id_url:m},action:"update_item_section_and_position"};c.item_id_change=i,c.section_id_new_of_item=a,c.section_id_old_of_item=o;const d=this.elCurriculumSections.querySelector(`.section[data-section-id="${a}"]`);d.querySelectorAll(`${f.selectors.elSectionItem}`).forEach(e=>{const t=parseInt(e.dataset.itemId||0);0!==t&&r.push(t)}),c.items_position=r;const u={success:e=>{const{message:t,status:s}=e;n.W(t,s)},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(l,0),this.updateCountItems(d),o!==a&&this.updateCountItems(s)}};e.lpSetLoadingEl(l,1),window.lpAJAXG.fetchAJAX(c,u)},onMove:()=>{},onChoose:e=>{const t=e.item;i=t.dataset.itemId,s=t.closest(`${b.selectors.elSection}`),o=s.dataset.sectionId},onUpdate:()=>{}})})}addItemsSelectedToSection(t){if(!this.sectionIdSelected)return;const s=document.querySelector(`.section[data-section-id="${this.sectionIdSelected}"]`);if(!s)return;const o=s.querySelector(`${f.selectors.elItemClone}`),a=null!==document.querySelector("#lp-course-builder");t.forEach(t=>{const s=o.cloneNode(!0),i=s.querySelector(`${f.selectors.elItemTitleInput}`);s.dataset.itemId=t.id,s.classList.add(t.type),s.classList.remove("clone"),s.dataset.itemType=t.type,s.querySelector(".edit-link").setAttribute("href",t.editLink||""),i.value=t.titleSelected||"",e.lpSetLoadingEl(s,1),e.lpShowHideEl(s,1),o.insertAdjacentElement("beforebegin",s)}),i().close();const r={course_id:this.courseId,action:"add_items_to_section",section_id:this.sectionIdSelected,items:t,is_course_builder:a?1:0,args:{id_url:m}};window.lpAJAXG.fetchAJAX(r,{success:e=>{const{message:i,status:a,data:r}=e,{html:l}=r||"";n.W(i,a),t.forEach(e=>{const t=s.querySelector(`${f.selectors.elSectionItem}[data-item-id="${e.id}"]`);t&&t.remove()}),"success"===a&&l&&o.insertAdjacentHTML("beforebegin",l)},error:e=>{n.W(e,"error")},completed:()=>{this.updateCountItems(s)}})}updatePreviewItem(t){const{e:s,target:i}=t,o=i.closest(`${f.selectors.elBtnSetPreviewItem}`);if(!o)return;const a=o.closest(`${f.selectors.elSectionItem}`);if(!a)return;const r=o.querySelector("a");r.classList.toggle("lp-icon-eye"),r.classList.toggle("lp-icon-eye-slash");const l=!r.classList.contains("lp-icon-eye-slash"),c=a.dataset.itemId,d=a.dataset.itemType;e.lpSetLoadingEl(a,1);const u={success:e=>{const{message:t,status:s}=e;n.W(t,s),"error"===s&&(r.classList.toggle("lp-icon-eye"),r.classList.toggle("lp-icon-eye-slash"))},error:e=>{n.W(e,"error"),r.classList.toggle("lp-icon-eye"),r.classList.toggle("lp-icon-eye-slash")},completed:()=>{e.lpSetLoadingEl(a,0)}},h={course_id:this.courseId,action:"update_item_preview",item_id:c,item_type:d,enable_preview:l?1:0,args:{id_url:m}};window.lpAJAXG.fetchAJAX(h,u)}updateCountItems(e){const t=this.elEditCurriculum,s=t.querySelector(".total-items"),i=t.querySelectorAll(`${f.selectors.elSectionItem}:not(.clone)`).length;s.dataset.count=i,s.querySelector(".count").textContent=i;const n=e.querySelector(".section-items-counts"),o=e.querySelectorAll(`${f.selectors.elSectionItem}:not(.clone)`).length;n.dataset.count=o,n.querySelector(".count").textContent=o}addPopupAttributesToItem(e,t,s){if(null===document.querySelector("#lp-course-builder")||!t)return;const i=s.replace(/^lp_/,""),n=`#lp-tmpl-builder-popup-curriculum-${i}-course-${this.courseId}`;if(!i||!document.querySelector(n))return;const o=e.querySelector(".item-actions .edit-link");if(!o)return;const a=o.closest("li");a&&("lp_lesson"===s?a.setAttribute("data-popup-lesson",t):"lp_quiz"===s&&a.setAttribute("data-popup-quiz",t),a.classList.add("lp-btn-edit-item-popup"),o.removeAttribute("target"),o.removeAttribute("href"),o.classList.add("edit-popup-link"),a.setAttribute("data-course-id",this.courseId),a.setAttribute("data-popup-type",i),a.setAttribute("data-popup-id",t),a.setAttribute("data-template",n))}}class b{constructor(){this.courseId=null,this.elEditCurriculum=null,this.elCurriculumSections=null,this.editSectionItem=new f}static selectors={elSection:".section",elDivAddNewSection:".add-new-section",elSectionClone:".section.clone",elSectionTitleNewInput:".lp-section-title-new-input",elSectionTitleInput:".lp-section-title-input",etBtnEditTitle:".lp-btn-edit-section-title",elSectionDesInput:".lp-section-description-input",elBtnAddSection:".lp-btn-add-section",elBtnUpdateTitle:".lp-btn-update-section-title",elBtnUpdateDes:".lp-btn-update-section-description",elBtnCancelUpdateTitle:".lp-btn-cancel-update-section-title",elBtnCancelUpdateDes:".lp-btn-cancel-update-section-description",elBtnDeleteSection:".lp-btn-delete-section",elSectionDesc:".section-description",elSectionToggle:".section-toggle",elCountSections:".count-sections"};init(){this.elEditCurriculum=document.querySelector(`${w.selectors.idElEditCurriculum}`),this.elCurriculumSections=this.elEditCurriculum.querySelector(`${w.selectors.elCurriculumSections}`);const e=this.elEditCurriculum.closest(`${w.selectors.LPTarget}`),t=window.lpAJAXG.getDataSetCurrent(e);this.courseId=t.args.course_id,this.editSectionItem.init(),this.events(),this.sortAbleSection()}events(){b._loadedEvents||(b._loadedEvents=this,e.eventHandlers("click",[{selector:b.selectors.elBtnAddSection,class:this,callBack:this.addSection.name},{selector:`${b.selectors.elBtnUpdateDes}`,class:this,callBack:this.updateSectionDescription.name},{selector:`${b.selectors.etBtnEditTitle}`,class:this,callBack:this.setFocusTitleInput.name},{selector:`${b.selectors.elSectionToggle}`,class:this,callBack:this.toggleSection.name},{selector:`${b.selectors.elBtnCancelUpdateDes}`,class:this,callBack:this.cancelSectionDescription.name},{selector:`${b.selectors.elBtnDeleteSection}`,class:this,callBack:this.deleteSection.name},{selector:`${b.selectors.elBtnUpdateTitle}`,class:this,callBack:this.updateSectionTitle.name},{selector:`${b.selectors.elBtnCancelUpdateTitle}`,class:this,callBack:this.cancelSectionTitle.name},{selector:w.selectors.elToggleAllSections,class:this,callBack:this.toggleSectionAll.name}]),e.eventHandlers("keyup",[{selector:b.selectors.elSectionTitleNewInput,class:this,callBack:this.changeTitleBeforeAdd.name},{selector:b.selectors.elSectionTitleInput,class:this,callBack:this.changeTitle.name},{selector:b.selectors.elSectionDesInput,class:this,callBack:this.changeDescription.name}]),e.eventHandlers("keydown",[{selector:b.selectors.elSectionTitleNewInput,class:this,callBack:this.addSection.name,checkIsEventEnter:!0},{selector:b.selectors.elSectionDesInput,class:this,callBack:this.updateSectionDescription.name,checkIsEventEnter:!0},{selector:b.selectors.elSectionTitleInput,class:this,callBack:this.updateSectionTitle.name,checkIsEventEnter:!0}]),e.eventHandlers("focusin",[{selector:b.selectors.elSectionTitleNewInput,class:this,callBack:this.focusTitleNewInput.name},{selector:b.selectors.elSectionTitleInput,class:this,callBack:this.focusTitleInput.name}]),e.eventHandlers("focusout",[{selector:b.selectors.elSectionTitleNewInput,class:this,callBack:this.focusTitleNewInput.name,focusIn:!1},{selector:`${b.selectors.elSectionTitleInput}`,class:this,callBack:this.focusTitleInput.name,focusIn:!1}]))}changeTitleBeforeAdd(e){const{e:t,target:s}=e,i=s,n=i.closest(`${b.selectors.elDivAddNewSection}`);if(!n)return;const o=n.querySelector(`${b.selectors.elBtnAddSection}`);0===i.value.trim().length?o.classList.remove("active"):o.classList.add("active")}focusTitleNewInput(e){const{e:t,target:s,focusIn:i=!0}=e,n=s.closest(`${b.selectors.elDivAddNewSection}`);n&&(i?n.classList.add("focus"):n.classList.remove("focus"))}addSection(t){const{e:s,target:i,callBackNest:o}=t,a=i.closest(`${b.selectors.elDivAddNewSection}`);if(!a)return;s.preventDefault();const r=a.querySelector(`${b.selectors.elSectionTitleNewInput}`),l=r.value.trim(),c=r.dataset.messEmptyTitle;if(0===l.length)return void n.W(c,"error");r.value="",r.blur();const d=this.elCurriculumSections.querySelector(`${b.selectors.elSectionClone}`).cloneNode(!0);d.classList.remove("clone"),e.lpShowHideEl(d,1),e.lpSetLoadingEl(d,1),d.querySelector(`${b.selectors.elSectionTitleInput}`).value=l,this.elCurriculumSections.insertAdjacentElement("beforeend",d);const u={success:e=>{const{message:s,status:i,data:a}=e;if("error"===i)throw d.remove(),s;if("success"===i){const{section:s}=a;d.dataset.sectionId=s.section_id||"",this.editSectionItem.sortAbleItem(),o&&"function"==typeof o.success&&(t.elSection=d,t.response=e,o.success(t))}n.W(s,i)},error:e=>{d.remove(),n.W(e,"error"),o&&"function"==typeof o.error&&(t.error=e,o.error(t))},completed:()=>{e.lpSetLoadingEl(d,0),d.classList.remove(`${w.selectors.elCollapse}`),d.querySelector(`${b.selectors.elSectionDesInput}`).focus(),this.updateCountSections(this.elEditCurriculum),o&&"function"==typeof o.completed&&(t.elSection=d,o.completed(t))}},h=JSON.parse(r.dataset.send);h.section_name=l,window.lpAJAXG.fetchAJAX(h,u)}deleteSection(t){const{e:s,target:o}=t,a=o,r=a.closest(`${w.selectors.idElEditCurriculum}`);i().fire({title:a.dataset.title,text:a.dataset.content,icon:"warning",showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){const t=a.closest(".section"),s=t.dataset.sectionId;e.lpSetLoadingEl(t,1);const i={success:e=>{const{message:t,status:s}=e;n.W(t,s)},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(t,0),t.remove(),this.editSectionItem.updateCountItems(t),this.updateCountSections(r)}},o=JSON.parse(a.dataset.send);o.section_id=s,window.lpAJAXG.fetchAJAX(o,i)}})}focusTitleInput(e){const{e:t,target:s,focusIn:i=!0}=e,n=s.closest(`${b.selectors.elSection}`);n&&(i?n.classList.add("focus"):n.classList.remove("focus"))}setFocusTitleInput(e){const{e:t,target:s}=e,i=s.closest(`${b.selectors.elSection}`);if(!i)return;const n=i.querySelector(`${b.selectors.elSectionTitleInput}`);n.setSelectionRange(n.value.length,n.value.length),n.focus()}changeTitle(e){const{e:t,target:s}=e,i=s,n=i.closest(`${b.selectors.elSection}`);i.value.trim()===(i.dataset.old||"")?n.classList.remove("editing"):n.classList.add("editing")}updateSectionTitle(t){const{e:s,target:i}=t,o=i.closest(`${b.selectors.elSection}`);if(!o)return;s.preventDefault();const a=o.querySelector(`${b.selectors.elSectionTitleInput}`);if(!a)return;const r=o.dataset.sectionId,l=a.value.trim(),c=a.dataset.old||"",d=a.dataset.messEmptyTitle;if(0===l.length)return void n.W(d,"error");if(l===c)return;a.blur(),e.lpSetLoadingEl(o,1);const u={success:e=>{const{message:t,status:s}=e;n.W(t,s),"success"===s&&(a.dataset.old=l)},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(o,0),o.classList.remove("editing")}},h=JSON.parse(a.dataset.send);h.section_id=r,h.section_name=l,window.lpAJAXG.fetchAJAX(h,u)}cancelSectionTitle(e){const{e:t,target:s}=e,i=s.closest(`${b.selectors.elBtnCancelUpdateTitle}`);if(!i)return;const n=i.closest(`${b.selectors.elSection}`),o=n.querySelector(`${b.selectors.elSectionTitleInput}`);o.value=o.dataset.old||"",n.classList.remove("editing")}updateSectionDescription(t){const{e:s,target:i,callBackNest:o}=t,a=i.closest(`${b.selectors.elSectionDesc}`);if(!a)return;const r=a.querySelector(`${b.selectors.elSectionDesInput}`);if(!r)return;s.preventDefault();const l=r.closest(`${b.selectors.elSection}`),c=l.dataset.sectionId,d=r.value.trim(),u=r.dataset.old||"";if(d===u)return;e.lpSetLoadingEl(l,1);const h={success:e=>{const{message:s,status:i}=e;o&&"function"==typeof o.success&&(t.elSection=l,t.response=e,o.success(t)),n.W(s,i)},error:e=>{n.W(e,"error"),o&&"function"==typeof o.error&&o.error(l,e)},completed:()=>{e.lpSetLoadingEl(l,0),r.closest(`${b.selectors.elSectionDesc}`).classList.remove("editing"),r.dataset.old=d,o&&"function"==typeof o.completed&&o.completed(l)}},p=JSON.parse(r.dataset.send);p.section_id=c,p.section_description=d,window.lpAJAXG.fetchAJAX(p,h)}cancelSectionDescription(e){const{e:t,target:s}=e,i=s.closest(`${b.selectors.elSectionDesc}`),n=i.querySelector(`${b.selectors.elSectionDesInput}`);n.value=n.dataset.old||"",i.classList.remove("editing")}changeDescription(e){const{e:t,target:s}=e,i=s.closest(`${b.selectors.elSectionDesInput}`);if(!i)return;const n=i.closest(`${b.selectors.elSectionDesc}`);i.value.trim()===(i.dataset.old||"")?n.classList.remove("editing"):n.classList.add("editing")}toggleSectionAll(e){const{e:t,target:s}=e,i=s.closest(`${w.selectors.elToggleAllSections}`);if(!i)return;const n=i.closest(`${w.selectors.idElEditCurriculum}`).querySelectorAll(`${b.selectors.elSection}:not(.clone)`);i.classList.toggle(`${w.selectors.elCollapse}`),n.forEach(e=>{const t=i.classList.contains(`${w.selectors.elCollapse}`);e.classList.toggle(`${w.selectors.elCollapse}`,t)})}toggleSection(e){const{e:t,target:s}=e,i=s.closest(`${b.selectors.elSection}`);i.closest(`${w.selectors.elCurriculumSections}`)&&(i.classList.toggle(`${w.selectors.elCollapse}`),this.checkAllSectionsCollapsed())}checkAllSectionsCollapsed(){const e=this.elEditCurriculum.querySelectorAll(`${b.selectors.elSection}:not(.clone)`),t=this.elEditCurriculum.querySelector(`${w.selectors.elToggleAllSections}`);let s=!0;e.forEach(e=>{if(e.classList.contains(`${w.selectors.elCollapse}`))return s=!1,!1}),s?t.classList.remove(`${w.selectors.elCollapse}`):t.classList.add(`${w.selectors.elCollapse}`)}sortAbleSection(){let t,s=0;new c.Ay(this.elCurriculumSections,{handle:".drag",animation:150,onEnd:i=>{const o=i.item;if(!s)return;const a=o.closest(`${b.selectors.elSection}`),r=this.elCurriculumSections.querySelectorAll(`${b.selectors.elSection}`),l=[];r.forEach(e=>{const t=e.dataset.sectionId;l.push(t)});const c={success:e=>{const{message:t,status:s}=e;n.W(t,s)},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(a,0),s=0}},d={action:"course_update_section_position",course_id:this.courseId,new_position:l,args:{id_url:"course-update-section-position"}};clearTimeout(t),t=setTimeout(()=>{e.lpSetLoadingEl(a,1),window.lpAJAXG.fetchAJAX(d,c)},1e3)},onMove:e=>{clearTimeout(t)},onUpdate:e=>{s=1}})}updateCountSections(e){const t=e.querySelector(`${b.selectors.elCountSections}`),s=e.querySelectorAll(`${b.selectors.elSection}:not(.clone)`).length;t.dataset.count=s,t.querySelector(".count").textContent=s}}const v=new b,y=new f;class w{constructor(){this.init()}static selectors={idElEditCurriculum:"#lp-course-edit-curriculum",elCurriculumSections:".curriculum-sections",elToggleAllSections:".course-toggle-all-sections",LPTarget:".lp-target",elCollapse:"lp-collapse"};init(){e.lpOnElementReady(`${w.selectors.idElEditCurriculum}`,e=>{v.init(),y.init()})}}class _{constructor(){this.init()}static selectors={elExtraMetaboxAdd:".lp_course_extra_meta_box__add",elExtraMetaboxContent:".lp_course_extra_meta_box__content",elExtraMetaboxFields:".lp_course_extra_meta_box__fields",elExtraMetaboxField:".lp_course_extra_meta_box__field",elExtraMetaboxDelete:".lp_course_extra_meta_box__fields a.delete",elFaqMetaboxAdd:".lp_course_faq_meta_box__add",elFaqMetaboxContent:".lp_course_faq_meta_box__content",elFaqMetaboxFields:".lp_course_faq_meta_box__fields",elFaqMetaboxField:".lp_course_faq_meta_box__field",elFaqMetaboxDelete:".lp_course_faq_meta_box__fields a.delete"};init(){this.initSortable(),this.events()}events(){_._loadedEvents||(_._loadedEvents=!0,e.eventHandlers("click",[{selector:_.selectors.elExtraMetaboxAdd,class:this,callBack:this.handleExtraMetaboxAdd.name},{selector:_.selectors.elExtraMetaboxDelete,class:this,callBack:this.handleExtraMetaboxDelete.name},{selector:_.selectors.elFaqMetaboxAdd,class:this,callBack:this.handleFaqMetaboxAdd.name},{selector:_.selectors.elFaqMetaboxDelete,class:this,callBack:this.handleFaqMetaboxDelete.name}]))}handleExtraMetaboxAdd(e){const{e:t,target:s}=e;t.preventDefault();const i=s.closest(_.selectors.elExtraMetaboxContent);if(!i)return;const n=i.querySelector(_.selectors.elExtraMetaboxFields),o=s.dataset.add;if(n&&o){n.insertAdjacentHTML("beforeend",o);const e=n.querySelector(`${_.selectors.elExtraMetaboxField}:last-child`);if(e){const t=e.querySelector("input");t&&setTimeout(()=>t.focus(),100)}}return!1}handleExtraMetaboxDelete(e){const{e:t,target:s}=e;t.preventDefault();const i=s.closest(_.selectors.elExtraMetaboxField);return i&&i.remove(),!1}handleFaqMetaboxAdd(e){const{e:t,target:s}=e;t.preventDefault();const i=s.closest(_.selectors.elFaqMetaboxContent);if(!i)return;const n=i.querySelector(_.selectors.elFaqMetaboxFields),o=s.dataset.add;return n&&o&&n.insertAdjacentHTML("beforeend",o),!1}handleFaqMetaboxDelete(e){const{e:t,target:s}=e;t.preventDefault();const i=s.closest(_.selectors.elFaqMetaboxField);return i&&i.remove(),!1}initSortable(){document.querySelectorAll(".lp_course_extra_meta_box__fields").forEach(e=>{new c.Ay(e,{animation:150,handle:".sort",draggable:".lp_course_extra_meta_box__field",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",forceFallback:!1,scrollSensitivity:40,onStart:e=>{e.item.classList.add("is-dragging")},onEnd:e=>{e.item.classList.remove("is-dragging")}})}),document.querySelectorAll(".lp_course_faq_meta_box__fields").forEach(e=>{new c.Ay(e,{animation:150,handle:".sort",draggable:".lp_course_faq_meta_box__field",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",forceFallback:!1,scrollSensitivity:40,onStart:e=>{e.item.classList.add("is-dragging")},onEnd:e=>{e.item.classList.remove("is-dragging")}})})}}class x{constructor(){this.hasUnsavedChanges=!1,this.formElements=[],this.originalValues=new Map,this.init()}init(){this.bindEvents(),this.captureOriginalValues()}captureOriginalValues(){document.querySelectorAll(".cb-section__course-edit, .lp-cb-tab-content").forEach(e=>{e.querySelectorAll("input, textarea, select").forEach(e=>{const t=e.name||e.id;t&&this.originalValues.set(t,this.getInputValue(e))})})}getInputValue(e){return"checkbox"===e.type?e.checked:"radio"===e.type?e.checked?e.value:null:e.value}bindEvents(){document.addEventListener("input",this.handleFormChange.bind(this)),document.addEventListener("change",this.handleFormChange.bind(this)),this.bindTinyMCEChanges(),document.addEventListener("click",this.handleTabClick.bind(this)),window.addEventListener("beforeunload",this.handleBeforeUnload.bind(this)),document.addEventListener("lp-course-builder-saved",this.resetState.bind(this))}bindTinyMCEChanges(){"undefined"!=typeof tinymce&&tinymce.on("AddEditor",e=>{e.editor.on("change",()=>{this.markAsChanged()}),e.editor.on("keyup",()=>{this.markAsChanged()})})}handleFormChange(e){const t=e.target;t.closest("#lp-course-edit-curriculum")||t.closest(".lp-form-setting-question")||t.closest(".lp-form-setting-lesson")||t.closest(".lp-quiz-questions-list")||t.closest(".lp-edit-quiz-wrap")||(t.closest(".cb-section__course-edit")||t.closest(".lp-cb-tab-content")||t.closest(".lp-form-setting-course")||t.closest(".lp-form-setting-quiz")||t.closest(".cb-section__quiz-edit"))&&this.markAsChanged()}markAsChanged(){this.hasUnsavedChanges||(this.hasUnsavedChanges=!0,this.updateSaveButtonState())}updateSaveButtonState(){document.querySelectorAll(".cb-btn-update, .lp-cb-save-btn, .cb-btn-main-action").forEach(e=>{this.hasUnsavedChanges?e.classList.add("has-changes"):e.classList.remove("has-changes")})}handleTabClick(e){const t=e.target.closest(".lp-cb-tabs__item, .lp-cb-sidebar__item a");if(t&&!t.hasAttribute("data-tab-section")&&"#"!==t.getAttribute("href")&&!t.classList.contains("is-active")&&!t.closest(".is-active")&&this.hasUnsavedChanges&&!confirm(wp?.i18n?.__("You have unsaved changes. Are you sure you want to leave this page?","learnpress")||"You have unsaved changes. Are you sure you want to leave this page?"))return e.preventDefault(),e.stopPropagation(),!1}handleBeforeUnload(e){if(this.hasUnsavedChanges)return e.preventDefault(),e.returnValue="",""}resetState(){this.hasUnsavedChanges=!1,this.updateSaveButtonState(),this.captureOriginalValues()}hasChanges(){return this.hasUnsavedChanges}setChanged(e=!0){this.hasUnsavedChanges=e,this.updateSaveButtonState()}}let S=null;const C=()=>(S||(S=new x),S);class k{constructor(){document.querySelector(".cb-section__course-edit")&&this.init()}static selectors={elCBContent:".lp-cb-content",elTabLinks:".lp-meta-box__course-tab__tabs li a",elTabItems:".lp-meta-box__course-tab__tabs li",elTabPanels:".lp-meta-box-course-panels",elDataCourse:".cb-section__course-edit",elBtnUpdateCourse:".cb-btn-update",elBtnHeaderSave:".lp-cb-save-btn",elBtnDraftCourse:".cb-btn-darft",elBtnPublishCourse:".cb-btn-publish",elBtnPendingCourse:".cb-btn-pending",elBtnDropdownAction:".cb-dropdown-item[data-status]",elBtnMainAction:".cb-btn-main-action",elBtnDuplicateCourse:".cb-btn-duplicate-course",elBtnTrashCourse:".cb-btn-trash",elBtnSaveSettings:".cb-btn-save-settings",elDropdownToggle:".cb-btn-dropdown-toggle",elDropdownMenu:".cb-dropdown-menu",elHeaderActionsDropdown:".cb-header-actions-dropdown",elTitleInput:"#title",elTitleCharCount:".cb-course-edit-title__char-count",elDescEditor:"#course_description_editor",elDescWordCount:".cb-course-edit-desc__word-count",elStatus:".course-status",elFormSetting:".lp-form-setting-course",elCategoryTabs:"#course_category-tabs li a",elCategoryPanels:"#taxonomy-course_category .tabs-panel",elBtnToggleAddCategory:"#course_category-add-toggle",elFormCategoryWrapper:"#course_category-add",elInputNewCategory:"#newcourse_category",elSelectParentCategory:"#newcourse_category_parent",elBtnSubmitCategory:"#course_category-add-submit",elCategoryChecklist:"#course_categorychecklist",elBtnAddCategoryNew:".cb-course-edit-category__btn-add-new",elFormCategoryAddNew:".cb-course-edit-terms__form-add-category",elInputAddCategory:".cb-course-edit-category__input",elSelectAddCategoryParent:".cb-course-edit-category__select-parent",elBtnSaveCategory:".cb-course-edit-category__btn-save",elBtnCancelCategoryNew:".cb-course-edit-category__btn-cancel",elCategorySearchInput:".cb-course-edit-category__search-input",elBtnToggleTermsSearch:".cb-terms-header__btn-search",elTermsSearchToolbar:".cb-terms-search-toolbar",elWrapperCheckBoxTag:".cb-course-edit-tags__checkbox-wrapper",elFormTagAddNew:".cb-course-edit-terms__form-add-tag",elBtnAddTagNew:".cb-course-edit-tag__btn-add-new",elBtnCancelTagNew:".cb-course-edit-tag__btn-cancel",elBtnSaveTag:".cb-course-edit-tags__btn-save",elInputAddTag:".cb-course-edit-tags__input",elTagsWrapper:".cb-course-edit-tags__wrapper",elTagChip:".cb-tag-chip",elTagSearchInput:".cb-course-edit-tags__search-input",elTagEmptyState:".cb-course-edit-tags__empty",elBtnRemoveFeatured:".cb-remove-featured-image",elBtnSetFeatured:".cb-featured-image-dropzone:not(.has-image)",elBtnChangeFeatured:".cb-change-featured-image",elFeaturedImageDropzone:".cb-featured-image-dropzone",elFeaturedImageLink:".cb-featured-image-link",elThumbnailInput:"#course_thumbnail_id",elFeaturedImageContainer:".cb-featured-image-container",elPublishPanel:".cb-course-edit-publish",elPublishStatusSelect:"#cb-course-publish-status",elPublishVisibilitySelect:"#cb-course-publish-visibility",elPublishPasswordRow:".cb-course-edit-publish__password-row",elPublishPasswordInput:"#cb-course-publish-password",elPublishDateLabel:"#cb-course-publish-date-label",elPublishDateInput:"#cb-course-publish-date",elPriceCourseData:"#price_course_data",elSaleDatesFields:".lp_sale_dates_fields",elSalePriceScheduleBtn:".lp_sale_price_schedule",elCancelSaleScheduleBtn:".lp_cancel_sale_schedule",elRegularPriceInput:"#_lp_regular_price",elSalePriceInput:"#_lp_sale_price",elPriceInput:"#_lp_price",elFormField:".form-field",elTipFloating:".learn-press-tip-floating",elCategoryDiv:"#taxonomy-course_category",elCourseResultRadio:'input[type="radio"][name="_lp_course_result"]',elPassingConditionField:"._lp_passing_condition_field",elBtnGetFinalQuiz:".lp-metabox-get-final-quiz",elFinalQuizMessage:".lp-metabox-evaluate-final_quiz",elExtraMetaInput:".lp_course_extra_meta_box__input",elFaqMetaInput:".lp_course_faq_meta_box__field input",elCBHorizontalTabs:".lp-cb-tabs__item",elCBTabPanels:".lp-cb-tab-panel",elPermalinkDisplay:".cb-permalink-display",elPermalinkEditor:".cb-permalink-editor",elPermalinkEditBtn:".cb-permalink-edit-btn",elPermalinkOkBtn:".cb-permalink-ok-btn",elPermalinkCancelBtn:".cb-permalink-cancel-btn",elPermalinkSlugInput:".cb-permalink-slug-input",elPermalinkUrl:".cb-permalink-url",elPermalinkBaseUrl:"#cb-permalink-base-url",elBtnPreview:".cb-button.cb-btn-preview",elAdminLink:".lp-cb-admin-link"};init(){this.isSavingCourse=!1;const e=new w,t=new _;e.init(),t.init(),this.initTabs(),this.initTabTitles(),this.initCategoryTabs(),this.initCategoryTree(),this.applyCategorySearch(),this.initTagManagement(),this.initSalePriceLayout(),this.initAssessmentMetaboxFeatures(),this.initTitleCharCount(),this.initDescWordCount(),this.syncPublishStatusOptions(),this.syncPublishDateLabel(),this.syncPublishVisibilityControls(!1),this.initHeaderActionsDropdown(),this.bindAiFeaturedImageListener(),this.events()}bindAiFeaturedImageListener(){k._boundAiFeaturedImageListener||(document.addEventListener("lp-course-builder/ai-featured-image-applied",e=>{this.handleAiFeaturedImageApplied(e)}),k._boundAiFeaturedImageListener=!0)}handleAiFeaturedImageApplied(e){const t=parseInt(e?.detail?.attachmentId||0,10),s=e?.detail?.imageSrc||"";t&&s&&this.setFeaturedImage({id:t,url:s,sizes:{medium:{url:s}}})}events(){k._loadedEvents||(k._loadedEvents=!0,e.eventHandlers("click",[{selector:k.selectors.elTabLinks,class:this,callBack:this.handleTabClick.name},{selector:k.selectors.elCategoryTabs,class:this,callBack:this.handleCategoryTabClick.name},{selector:k.selectors.elCBHorizontalTabs,class:this,callBack:this.handleCBHorizontalTabClick.name},{selector:k.selectors.elBtnToggleAddCategory,class:this,callBack:this.toggleAddCategoryForm.name},{selector:k.selectors.elBtnSubmitCategory,class:this,callBack:this.addNewCategory.name},{selector:k.selectors.elBtnAddCategoryNew,class:this,callBack:this.toggleCustomAddCategoryForm.name},{selector:k.selectors.elBtnToggleTermsSearch,class:this,callBack:this.toggleTermsSearchToolbar.name},{selector:k.selectors.elBtnCancelCategoryNew,class:this,callBack:this.toggleCustomAddCategoryForm.name},{selector:k.selectors.elBtnSaveCategory,class:this,callBack:this.addNewCategoryCustom.name},{selector:k.selectors.elBtnMainAction,class:this,callBack:this.updateCourse.name},{selector:k.selectors.elBtnHeaderSave,class:this,callBack:this.updateCourse.name},{selector:k.selectors.elBtnDropdownAction,class:this,callBack:this.updateCourse.name},{selector:k.selectors.elBtnDuplicateCourse,class:this,callBack:this.duplicateCourse.name},{selector:k.selectors.elBtnTrashCourse,class:this,callBack:this.trashCourse.name},{selector:k.selectors.elBtnSaveSettings,class:this,callBack:this.saveSettings.name},{selector:k.selectors.elBtnGetFinalQuiz,class:this,callBack:this.getFinalQuiz.name},{selector:k.selectors.elBtnAddTagNew,class:this,callBack:this.toggleAddTagForm.name},{selector:k.selectors.elBtnCancelTagNew,class:this,callBack:this.toggleAddTagForm.name},{selector:k.selectors.elBtnSaveTag,class:this,callBack:this.addNewTag.name},{selector:k.selectors.elBtnSetFeatured,class:this,callBack:this.openMediaUploader.name},{selector:k.selectors.elFeaturedImageLink,class:this,callBack:this.openMediaUploader.name},{selector:k.selectors.elBtnChangeFeatured,class:this,callBack:this.openMediaUploader.name},{selector:k.selectors.elBtnRemoveFeatured,class:this,callBack:this.removeFeaturedImage.name},{selector:k.selectors.elSalePriceScheduleBtn,class:this,callBack:this.handleScheduleClick.name},{selector:k.selectors.elCancelSaleScheduleBtn,class:this,callBack:this.handleCancelSchedule.name},{selector:k.selectors.elPermalinkEditBtn,class:this,callBack:this.handlePermalinkEdit.name},{selector:k.selectors.elPermalinkOkBtn,class:this,callBack:this.handlePermalinkOk.name},{selector:k.selectors.elPermalinkCancelBtn,class:this,callBack:this.handlePermalinkCancel.name}]),e.eventHandlers("change",[{selector:".lp-meta-box input, .forminp input",class:this,callBack:this.showHideOptionsDependency.name},{selector:'#course_category-pop input[type="checkbox"]',class:this,callBack:this.handleMostUsedChange.name},{selector:'input[name="course_tags[]"]',class:this,callBack:this.handleTagSelectionChange.name},{selector:k.selectors.elCourseResultRadio,class:this,callBack:this.handleCourseResultChange.name},{selector:k.selectors.elPublishVisibilitySelect,class:this,callBack:this.handlePublishVisibilityChange.name},{selector:k.selectors.elPublishStatusSelect,class:this,callBack:this.handlePublishStatusChange.name},{selector:k.selectors.elPublishDateInput,class:this,callBack:this.handlePublishDateChange.name}]),e.eventHandlers("input",[{selector:k.selectors.elPriceCourseData,class:this,callBack:this.validateSalePrice.name},{selector:k.selectors.elTitleInput,class:this,callBack:this.handleTitleInput.name},{selector:k.selectors.elTagSearchInput,class:this,callBack:this.handleTagSearchInput.name},{selector:k.selectors.elCategorySearchInput,class:this,callBack:this.handleCategorySearchInput.name}]),e.eventHandlers("keydown",[{selector:k.selectors.elInputNewCategory,class:this,callBack:this.addNewCategory.name,checkIsEventEnter:!0},{selector:k.selectors.elInputAddCategory,class:this,callBack:this.addNewCategoryCustom.name,checkIsEventEnter:!0},{selector:k.selectors.elInputAddTag,class:this,callBack:this.addNewTag.name,checkIsEventEnter:!0},{selector:k.selectors.elExtraMetaInput,class:this,callBack:this.preventEnterSubmitInMetaInput.name,checkIsEventEnter:!0},{selector:k.selectors.elFaqMetaInput,class:this,callBack:this.preventEnterSubmitInMetaInput.name,checkIsEventEnter:!0}]))}initAssessmentMetaboxFeatures(){this.updatePassingConditionVisibility()}handleCourseResultChange(){this.updatePassingConditionVisibility()}updatePassingConditionVisibility(){const e=document.querySelector(`${k.selectors.elCourseResultRadio}:checked`),t=!!e&&["evaluate_final_quiz","evaluate_final_assignment"].includes(e.value);document.querySelectorAll(k.selectors.elPassingConditionField).forEach(e=>{e.style.display=t?"none":""})}preventEnterSubmitInMetaInput(e){const{e:t,target:s}=e;t.preventDefault(),s?.blur&&s.blur()}async getFinalQuiz(e){const{e:t,target:s}=e;t.preventDefault();const i=s.closest(k.selectors.elBtnGetFinalQuiz);if(!i||"yes"===i.dataset.loadingState)return;const o=i.textContent,a=i.dataset.loading||o,r=i.parentNode?.querySelector(k.selectors.elFinalQuizMessage)||document.querySelector(k.selectors.elFinalQuizMessage);r&&r.remove(),i.dataset.loadingState="yes",i.textContent=a;try{const e=await this.requestFinalQuiz(i.dataset.postid||""),t=e?.data||e?.message||"";i.textContent=o;const s=document.createElement("div");s.className="lp-metabox-evaluate-final_quiz",s.innerHTML=t,i.parentNode.insertBefore(s,i.nextSibling)}catch(e){i.textContent=o,e?.message&&n.W(e.message,"error")}finally{delete i.dataset.loadingState}}async requestFinalQuiz(e=""){if("undefined"!=typeof wp&&"function"==typeof wp.apiFetch)return wp.apiFetch({path:"lp/v1/admin/course/get_final_quiz",method:"POST",data:{courseId:e,isCourseBuilder:!0}});const t=window.lpGlobalSettings?.rest||window.lpData?.lp_rest_url||"/wp-json/",s=window.lpGlobalSettings?.nonce||window.lpData?.nonce||"",i=t.endsWith("/")?t:`${t}/`,n=await fetch(`${i}lp/v1/admin/course/get_final_quiz`,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json",...s?{"X-WP-Nonce":s}:{}},body:JSON.stringify({courseId:e,isCourseBuilder:!0})});let o={};try{o=await n.json()}catch(e){throw new Error("Cannot parse final quiz response")}if(!n.ok)throw new Error(o?.message||`Request failed (${n.status})`);return o}initTagManagement(){this.syncTagManagement()}getTagManagementElements(){const e=document.querySelector(k.selectors.elTagsWrapper);return e?{wrapper:e,searchInput:e.querySelector(k.selectors.elTagSearchInput),list:e.querySelector(k.selectors.elWrapperCheckBoxTag),emptyState:e.querySelector(k.selectors.elTagEmptyState)}:null}getTagChipName(e){return e.dataset.tagName||e.querySelector(".cb-tag-chip__name")?.textContent?.trim()?.toLowerCase()||""}updateTagEmptyState(e,t="",s=0){if(!e)return;const i=e.dataset.emptyDefault||"",n=e.dataset.emptySearch||i;e.textContent=t?n:i,e.classList.toggle("lp-hidden",s>0)}syncTagManagement(){const e=this.getTagManagementElements();if(!e||!e.list)return;const t=e.searchInput?.value?.trim().toLowerCase()||"",s=Array.from(e.wrapper.querySelectorAll(k.selectors.elTagChip)).sort((e,t)=>{const s=e.querySelector('input[name="course_tags[]"]')?.checked?1:0,i=t.querySelector('input[name="course_tags[]"]')?.checked?1:0;return s!==i?i-s:this.getTagChipName(e).localeCompare(this.getTagChipName(t))});let i=0;s.forEach(s=>{const n=!t||this.getTagChipName(s).includes(t);s.classList.toggle("lp-hidden",!n),e.list.appendChild(s),n&&(i+=1)}),this.updateTagEmptyState(e.emptyState,t,i)}handleTagSelectionChange(){this.syncTagManagement()}handleTagSearchInput(){this.syncTagManagement()}handleCategorySearchInput(){this.applyCategorySearch()}toggleTermsSearchToolbar(e){const{e:t,target:s}=e;t&&t.preventDefault();const i=s?.closest(k.selectors.elBtnToggleTermsSearch);if(!i)return;const n=i.dataset.toggleTarget||"",o=n?document.querySelector(n):null;if(!o)return;const a=!o.classList.contains("is-open");o.classList.toggle("is-open",a),i.setAttribute("aria-expanded",a?"true":"false");const r=o.querySelector('input[type="search"]');a?r&&setTimeout(()=>r.focus(),220):(r&&(r.value=""),r?.matches(k.selectors.elCategorySearchInput)?this.applyCategorySearch():r?.matches(k.selectors.elTagSearchInput)&&this.syncTagManagement())}getDirectChildByTagName(e,t){return Array.from(e?.children||[]).find(e=>e.tagName===t)}getCategoryLabelText(e){const t=this.getDirectChildByTagName(e,"LABEL");return t?.textContent?.trim()?.toLowerCase()||""}filterCategoryItem(e,t){const s=Array.from(e.children).find(e=>"UL"===e.tagName&&e.classList.contains("children")),i=s?Array.from(s.children).filter(e=>"LI"===e.tagName):[],n=!t||this.getCategoryLabelText(e).includes(t),o=i.some(e=>this.filterCategoryItem(e,t)),a=!t||n||o;return e.classList.toggle("lp-hidden",!a),t&&s&&e.classList.toggle("children-visible",n||o),a}applyCategorySearch(){const e=document.querySelector(k.selectors.elCategoryDiv),t=document.querySelector(k.selectors.elCategorySearchInput);if(!e||!t)return;const s=t.value.trim().toLowerCase();e.querySelectorAll(".tabs-panel").forEach(e=>{const t=Array.from(e.children).filter(e=>"UL"===e.tagName).reduce((e,t)=>e.concat(Array.from(t.children).filter(e=>"LI"===e.tagName)),[]);t.length&&t.forEach(e=>this.filterCategoryItem(e,s))}),s||this.expandCheckedCategories(e)}initCategoryTabs(){const e=document.querySelector('#course_category-tabs a[href="#course_category-all"]');if(e){e.closest("li").classList.add("tabs");const t=document.querySelector("#course_category-all");t&&(t.style.display="block")}}handleCategoryTabClick(e){const{e:t,target:s}=e;t.preventDefault();const i=s.closest("a");if(!i)return;const n=document.querySelector(k.selectors.elCategoryDiv),o=n.querySelectorAll(".category-tabs li"),a=n.querySelectorAll(".tabs-panel"),r=i.getAttribute("href");o.forEach(e=>e.classList.remove("tabs","active")),a.forEach(e=>e.style.display="none"),i.closest("li").classList.add("tabs");const l=n.querySelector(r);l&&(l.style.display="block"),"#course_category-pop"===r&&this.syncMostUsedTabs(),this.applyCategorySearch()}syncMostUsedTabs(){const e=document.querySelector("#course_category-all"),t=document.querySelector("#course_category-pop");e&&t&&t.querySelectorAll('input[type="checkbox"]').forEach(t=>{const s=t.value,i=e.querySelector(`input[value="${s}"]`);i&&(t.checked=i.checked)})}handleMostUsedChange(e){const{target:t}=e,s=t.value,i=t.checked,n=document.querySelector(`#course_category-all input[value="${s}"]`);if(n&&(n.checked=i,i)){const e=n.closest("li");e&&e.classList.add("children-visible");let t=e;for(;t&&t.parentElement.closest("li");)t=t.parentElement.closest("li"),t.classList.add("children-visible")}}toggleAddCategoryForm(e){const{e:t}=e;t&&t.preventDefault();const s=document.querySelector(k.selectors.elFormCategoryWrapper),i=document.querySelector(k.selectors.elInputNewCategory);s&&("none"===window.getComputedStyle(s).display?(s.style.display="block",i&&setTimeout(()=>{i.focus(),i.value=""},100)):s.style.display="none")}initCategoryTree(){const e=document.querySelector(k.selectors.elCategoryDiv);e&&(e.querySelectorAll("ul.children").forEach(e=>{const t=e.parentElement;t&&"LI"===t.tagName&&this.addToggleBtnToLi(t)}),k._treeEventAttached||(e.addEventListener("click",e=>{e.target.classList.contains("lp-cat-toggle")&&(e.preventDefault(),e.stopPropagation(),e.target.closest("li").classList.toggle("children-visible"))}),e.addEventListener("change",e=>{if("checkbox"===e.target.type){const t=e.target.closest("li");t&&e.target.checked&&t.classList.add("children-visible")}}),k._treeEventAttached=!0),this.expandCheckedCategories(e))}expandCheckedCategories(e){e.querySelectorAll('input[type="checkbox"]:checked').forEach(e=>{let t=e.closest("li");for(;t;){const e=t.closest("ul");if(e&&e.classList.contains("children")){const s=e.closest("li");s?(s.classList.add("children-visible"),t=s):t=null}else t=null}})}addToggleBtnToLi(e){const t=e.querySelector("label");if(!t||t.querySelector(".lp-cat-toggle"))return;const s=document.createElement("span");s.className="lp-cat-toggle",s.title="Toggle sub-categories",t.appendChild(s)}addNewCategory(t){const{e:s}=t;s&&s.preventDefault();const i=document.querySelector(k.selectors.elInputNewCategory),o=document.querySelector(k.selectors.elSelectParentCategory),a=document.querySelector(k.selectors.elBtnSubmitCategory),r=i?.value?.trim();if(!r)return void n.W("Please enter category name","error");const l=o?parseInt(o.value):0;e.lpSetLoadingEl(a,1);const c={action:"add_course_category",args:{id_url:"add-course-category"},name:r,parent:l},d={success:e=>{const{status:t,message:s,data:a}=e;if(n.W(s,t),a?.html){const e=document.querySelector(k.selectors.elCategoryChecklist);if(a.parent&&a.parent>0){const t=e.querySelector(`input[value="${a.parent}"]`);if(t){const e=t.closest("li");e.classList.add("children-visible");let s=e.querySelector(":scope > ul.children");s||(s=document.createElement("ul"),s.className="children",e.appendChild(s),this.addToggleBtnToLi(e)),s.insertAdjacentHTML("beforeend",a.html)}else e.insertAdjacentHTML("afterbegin",a.html)}else e.insertAdjacentHTML("afterbegin",a.html);i.value="",o&&(o.value="0"),this.applyCategorySearch()}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(c,d)}toggleCustomAddCategoryForm(e){const{target:t}=e,s=document.querySelector(k.selectors.elBtnAddCategoryNew),i=document.querySelector(k.selectors.elFormCategoryAddNew),n=t.closest(k.selectors.elBtnAddCategoryNew);if(i)if(n){i.style.display="flex",s&&(s.style.display="none");const e=i.querySelector(k.selectors.elInputAddCategory);e&&setTimeout(()=>e.focus(),100)}else i.style.display="none",s&&(s.style.display="inline-flex")}addNewCategoryCustom(t){const{e:s}=t;s&&s.preventDefault();const i=document.querySelector(k.selectors.elInputAddCategory),o=document.querySelector(k.selectors.elSelectAddCategoryParent),a=document.querySelector(k.selectors.elBtnSaveCategory),r=i?.value?.trim();if(!r)return void n.W("Please enter category name","error");const l=o?parseInt(o.value):0;e.lpSetLoadingEl(a,1);const c={action:"add_course_category",args:{id_url:"add-course-category"},name:r,parent:l},d={success:e=>{const{status:t,message:s,data:a}=e;if(n.W(s,t),a?.html){const e=document.querySelector(k.selectors.elCategoryChecklist);if(e)if(a.parent&&a.parent>0){const t=e.querySelector(`input[value="${a.parent}"]`);if(t){const e=t.closest("li");e.classList.add("children-visible");let s=e.querySelector(":scope > ul.children");s||(s=document.createElement("ul"),s.className="children",e.appendChild(s),this.addToggleBtnToLi(e)),s.insertAdjacentHTML("beforeend",a.html)}else e.insertAdjacentHTML("afterbegin",a.html)}else e.insertAdjacentHTML("afterbegin",a.html);if(a.term_id&&o){const e=document.createElement("option");e.value=a.term_id,e.textContent=r,o.appendChild(e)}i.value="",o&&(o.value="0"),this.applyCategorySearch();const t=document.querySelector(k.selectors.elBtnCancelCategoryNew);t&&t.click()}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(c,d)}initSalePriceLayout(){const e=document.querySelector(k.selectors.elPriceCourseData);if(!e)return;const t=e.querySelectorAll(k.selectors.elSaleDatesFields),s=e.querySelector(k.selectors.elSalePriceScheduleBtn),i=e.querySelector(k.selectors.elCancelSaleScheduleBtn);let n=!1;e.querySelectorAll(`${k.selectors.elSaleDatesFields} input`).forEach(e=>{e.value&&""!==e.value.trim()&&(n=!0)}),n?(s&&(s.style.display="none"),i&&(i.style.display="inline-block"),t.forEach(e=>e.style.display="block")):(s&&(s.style.display="inline-block"),i&&(i.style.display="none"),t.forEach(e=>e.style.display="none"))}handleScheduleClick(e){const{e:t,target:s}=e;t.preventDefault();const i=s.closest(k.selectors.elSalePriceScheduleBtn),n=i.closest(k.selectors.elPriceCourseData);if(!n)return;const o=n.querySelector(k.selectors.elCancelSaleScheduleBtn),a=n.querySelectorAll(k.selectors.elSaleDatesFields);i.style.display="none",o&&(o.style.display="inline-block"),a.forEach(e=>e.style.display="block")}handleCancelSchedule(e){const{e:t,target:s}=e;t.preventDefault();const i=s.closest(k.selectors.elCancelSaleScheduleBtn),n=i.closest(k.selectors.elPriceCourseData);if(!n)return;const o=n.querySelector(k.selectors.elSalePriceScheduleBtn),a=n.querySelectorAll(k.selectors.elSaleDatesFields),r=n.querySelectorAll(`${k.selectors.elSaleDatesFields} input`);i.style.display="none",o&&(o.style.display="inline-block"),a.forEach(e=>e.style.display="none"),r.forEach(e=>e.value="")}validateSalePrice(e){const{target:t}=e,s=t.closest(k.selectors.elPriceCourseData);if(!s)return;const i=s.querySelector(k.selectors.elRegularPriceInput),n=s.querySelector(k.selectors.elSalePriceInput);if(s.querySelectorAll(k.selectors.elTipFloating).forEach(e=>e.remove()),!i||!n)return;const o=parseFloat(i.value)||0,a=parseFloat(n.value)||0;if(""!==n.value&&a>o){const e=t.getAttribute("id"),s=t.closest(k.selectors.elFormField),i="undefined"!=typeof lpAdminCourseEditorSettings&&lpAdminCourseEditorSettings.i18n?lpAdminCourseEditorSettings.i18n:{notice_price:"Regular price must be greater than sale price.",notice_sale_price:"Sale price must be less than regular price."},n=document.createElement("div");n.className="learn-press-tip-floating",e===k.selectors.elPriceInput?n.innerHTML=i.notice_price:e===k.selectors.elSalePriceInput&&(n.innerHTML=i.notice_sale_price),s&&n.innerHTML&&s.appendChild(n)}}showHideOptionsDependency(e){const{target:t}=e;if("INPUT"===t.tagName)if(t.closest(".forminp ")){const e=t.name.replace("learn_press_",""),s=document.querySelectorAll(`.show_if_${e}`);s&&s.forEach(e=>{e.classList.toggle("lp-option-disabled")})}else if(t.closest(".lp-meta-box")){const e=t.closest(".lp-meta-box"),s=t.name,i=e.querySelectorAll(`[data-dependency="${s}"]`);i&&i.forEach(e=>{e.classList.toggle("lp-option-disabled")})}}initTabs(){const e=document.querySelectorAll(k.selectors.elTabLinks);e.length>0&&this.activateTab(e[0])}handleTabClick(e){const{e:t,target:s}=e;t.preventDefault();const i=s.closest("a");i&&this.activateTab(i)}activateTab(e){const t=document.querySelectorAll(k.selectors.elTabItems),s=document.querySelectorAll(k.selectors.elTabPanels),i=e.getAttribute("href").substring(1),n=document.getElementById(i);n&&(t.forEach(e=>e.classList.remove("active")),s.forEach(e=>e.style.display="none"),e.parentElement.classList.add("active"),n.style.display="block")}handleCBHorizontalTabClick(t){const{e:s,target:i}=t;s.preventDefault();const n=i.closest(k.selectors.elCBHorizontalTabs);if(!n)return;const o=n.dataset.tabSection;if(!o)return;document.querySelectorAll(k.selectors.elCBHorizontalTabs).forEach(e=>e.classList.remove("is-active")),n.classList.add("is-active");const a=new URL(window.location.href);a.searchParams.set("tab",o),window.history.replaceState({},"",a),document.querySelectorAll(k.selectors.elCBTabPanels).forEach(t=>{const s=t.dataset.section===o;e.lpShowHideEl(t,s?1:0)})}getCourseDataForUpdate(){const e={},t=document.querySelector(k.selectors.elDataCourse);e.course_id=t&&parseInt(t.dataset.courseId)||0;const s=document.querySelector(k.selectors.elTitleInput);e.course_title=s?s.value:"";const i=document.querySelector(k.selectors.elDescEditor);if(e.course_description=i?i.value:"","undefined"!=typeof tinymce){const t=tinymce.get("course_description_editor");t&&(e.course_description=t.getContent())}e.course_categories=[],document.querySelectorAll('#taxonomy-course_category input[name*="course_category"]:checked').forEach(t=>e.course_categories.push(t.value)),e.course_tags=[],document.querySelectorAll('input[name="course_tags[]"]:checked').forEach(t=>e.course_tags.push(t.value));const n=document.querySelector(k.selectors.elThumbnailInput);e.course_thumbnail_id=n?n.value:"0";const o=document.querySelector(k.selectors.elPermalinkSlugInput);o&&o.value&&(e.course_permalink=o.value);const a=document.querySelector(k.selectors.elFormSetting);a&&(e.course_settings=!0,a.querySelectorAll("input, select, textarea").forEach(t=>{const s=t.name||t.id;if(!s)return;if("learnpress_meta_box_nonce"===s||"_wp_http_referer"===s)return;const i=s.endsWith("[]"),n=s.replace("[]","");"checkbox"===t.type?i?(e[n]||(e[n]=[]),t.checked&&e[n].push(t.value)):e[n]=t.checked?"yes":"no":"radio"===t.type?t.checked&&(e[n]=t.value):"file"===t.type?t.files&&t.files.length>0&&(e[n]=t.files):i?(e.hasOwnProperty(n)||(e[n]=[]),Array.isArray(e[n])&&e[n].push(t.value)):e.hasOwnProperty(n)||(e[n]=t.value)}));const r=["course_categories","course_tags"];return Object.keys(e).forEach(t=>{Array.isArray(e[t])&&!r.includes(t)&&(e[t]=e[t].join(","))}),e}updateCourse(t){if(!document.querySelector(k.selectors.elDataCourse))return;if(this.isSavingCourse)return;const{e:s,target:i}=t;s&&s.preventDefault();const o=i.closest(k.selectors.elBtnMainAction),a=i.closest(k.selectors.elBtnHeaderSave),r=i.closest(k.selectors.elBtnDropdownAction);let l="publish",c=null;if(o)l=o.dataset.status||"publish",c=o;else if(r)l=r.dataset.status||"publish",c=r;else if(a){const e=document.querySelector(k.selectors.elBtnMainAction);l=e?.dataset.status||"publish",c=a}if(!c)return;(o||a)&&(l=this.getStatusFromPublishPanel(l));const d=document.querySelector(k.selectors.elPublishVisibilitySelect),u=document.querySelector(k.selectors.elPublishPasswordInput),h=d?.value||"",p=u?.value?.trim?.()||"";if("password"===h&&!p)return n.W("Password is required when visibility is password protected.","error"),void u?.focus?.();if("draft"===l){const e=document.querySelector(k.selectors.elStatus);if(e&&e.classList.contains("publish")){const e=c.dataset.confirmUnpublish||"Saving as draft will unpublish this item. Are you sure?";if(!confirm(e))return}}const m=t=>{const s=[],i=document.querySelector(k.selectors.elBtnHeaderSave),n=document.querySelector(k.selectors.elBtnMainAction),o=document.querySelector(k.selectors.elDropdownToggle);i&&s.push(i),n&&s.push(n),o&&s.push(o),c&&s.push(c),[...new Set(s.filter(Boolean))].forEach(s=>{e.lpSetLoadingEl(s,t?1:0),s.classList.toggle("lp-loading",Boolean(t)),t?s.setAttribute("aria-disabled","true"):s.removeAttribute("aria-disabled")}),t&&o&&o.setAttribute("aria-expanded","false")};this.isSavingCourse=!0,m(!0);const g=this.getCourseDataForUpdate(),f={...g,course_status:l,action:"cb_save_course",args:{id_url:"cb-save-course"}};"undefined"!=typeof lpCourseBuilder&&lpCourseBuilder.nonce&&(f.nonce=lpCourseBuilder.nonce),g.course_categories&&(f.course_categories=Array.isArray(g.course_categories)?g.course_categories.join(","):g.course_categories),g.course_tags&&(f.course_tags=Array.isArray(g.course_tags)?g.course_tags.join(","):g.course_tags),g.course_thumbnail_id&&(f.course_thumbnail_id=g.course_thumbnail_id),h&&(f.course_visibility=h,f.course_password="password"===h?p:"");const b=document.querySelector(k.selectors.elPublishDateInput);b&&b.value&&(f.course_post_date=b.value);const v={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),"success"===t&&(this.updateHeaderTitle(g.course_title),document.dispatchEvent(new CustomEvent("lp-course-builder-saved")),i?.html)){const e=o.closest(k.selectors.elCBContent),t=(new DOMParser).parseFromString(i.html,"text/html");if(e){const s=[".lp-cb-header",".cb-course-edit-column--left"];for(const i of s){const s=e.querySelector(i);s&&(s.innerHTML=t.querySelector(i).innerHTML)}}}i?.redirect_url&&(window.location.href=i.redirect_url)},error:e=>{n.W(e.message||e,"error")},completed:()=>{this.isSavingCourse=!1,m(!1)}};window.lpAJAXG.fetchAJAX(f,v)}resolveStatusForUIAfterSave(e,t){const s="string"==typeof e?e.trim().toLowerCase():"",i="string"==typeof t?t.trim().toLowerCase():"",n=document.querySelector(k.selectors.elHeaderActionsDropdown),o=(n?.dataset?.reviewOnlyCourse||"").toLowerCase();return["yes","true","1"].includes(o)&&["publish","private","future"].includes(i)?"pending":s||i||"draft"}getStatusFromPublishPanel(e="publish"){const t=document.querySelector(k.selectors.elPublishStatusSelect),s=document.querySelector(k.selectors.elPublishVisibilitySelect);let i=t?.value||e||"publish";const n=s?.value||"public";return"private"===n&&"pending"!==i&&(i="private"),["public","password"].includes(n)&&"private"===i&&(i="publish"),["publish","future","draft","pending","private"].includes(i)?i:"publish"}syncPublishPanelStatus(e,t=""){const s=document.querySelector(k.selectors.elPublishStatusSelect),i=document.querySelector(k.selectors.elPublishVisibilitySelect);if(!s&&!i)return;const n=(e||"").toString().toLowerCase(),o=(s?.dataset?.primaryStatus||"").toString().toLowerCase();let a=["future","publish"].includes(o)?o:"publish";if("future"===n?a="future":["publish","private"].includes(n)&&(a="publish"),s&&(s.dataset.primaryStatus=a),s&&("private"===n?s.value="publish":["publish","future","draft","pending"].includes(n)&&(s.value=n)),this.syncPublishStatusOptions(n),i){let e=t||i.value||"public";"private"===n?e="private":"private"===e&&(e="public"),i.value=e}this.syncPublishVisibilityControls(),this.syncPublishDateLabel()}handlePublishVisibilityChange(){this.syncPublishVisibilityControls(!0)}handlePublishStatusChange(){this.syncPublishStatusOptions(),this.syncPublishDateLabel()}handlePublishDateChange(){this.syncPublishDateLabel()}syncPublishVisibilityControls(e=!1){const t=document.querySelector(k.selectors.elPublishVisibilitySelect),s=document.querySelector(k.selectors.elPublishPasswordRow),i=document.querySelector(k.selectors.elPublishPasswordInput);if(!t||!s)return;const n="password"===t.value;s.classList.toggle("lp-hidden",!n),e&&n&&i&&i.focus()}syncPublishDateLabel(){const e=document.querySelector(k.selectors.elPublishDateInput),t=document.querySelector(k.selectors.elPublishDateLabel);if(!t)return;const s=(e?.value||"").toString().trim();let i=!1;if(s){const e=new Date(s);Number.isNaN(e.getTime())||(i=e.getTime()>Date.now())}t.textContent=i?"Scheduled for":"Published on"}syncPublishStatusOptions(e=""){const t=document.querySelector(k.selectors.elPublishStatusSelect);if(!t)return;const s=t.dataset.publishLabel||"Published",i=t.dataset.futureLabel||"Scheduled",n=(e||t.value||"").toLowerCase(),o=(t.dataset.primaryStatus||"").toLowerCase(),a=t.querySelector('option[value="draft"]')?.textContent||"Draft",r=t.querySelector('option[value="pending"]')?.textContent||"Pending Review",l=!!t.querySelector('option[value="future"]'),c=!!t.querySelector('option[value="publish"]');let d="publish";["future","publish"].includes(n)?d=n:["future","publish"].includes(o)?d=o:l&&!c&&(d="future");const u="future"===d?i:s,h=["draft","pending","future","publish"].includes(n)?n:d;t.dataset.primaryStatus=d,t.innerHTML="",[{value:d,label:u},{value:"draft",label:a},{value:"pending",label:r}].forEach(e=>{const s=document.createElement("option");s.value=e.value,s.textContent=e.label,t.appendChild(s)}),t.value=h}formatStatusLabel(e){const t=(e||"").toString().toLowerCase();return"future"===t?"scheduled":t}updateActionButtons(e){const t=document.querySelector(k.selectors.elHeaderActionsDropdown);if(!t)return;const s=t.querySelector(".cb-btn-main-action"),i=t.querySelector(k.selectors.elDropdownMenu);if(!s)return;if(t.classList.contains("cb-header-actions-dropdown--single")||!i)return s.className="cb-btn-update cb-btn-primary cb-btn-main-action",s.dataset.status=this.getStatusFromPublishPanel("publish"),s.textContent=s.dataset.titleUpdate||"Update",void(t.dataset.currentStatus=e);const n=(t.dataset.reviewOnlyCourse||"").toLowerCase(),o=["yes","true","1"].includes(n),a={publish:{mainLabel:s.dataset.titleUpdate||"Update",mainClass:"cb-btn-update",mainStatus:"publish",dropdownLabel:s.dataset.titleDraft||"Save Draft",dropdownClass:"cb-btn-darft",dropdownStatus:"draft",dropdownIcon:"dashicons-media-default"},draft:{mainLabel:s.dataset.titleDraft||"Save Draft",mainClass:"cb-btn-darft",mainStatus:"draft",dropdownLabel:s.dataset.titlePublish||"Publish",dropdownClass:"cb-btn-publish",dropdownStatus:"publish",dropdownIcon:"dashicons-visibility"},pending:{mainLabel:s.dataset.titlePublish||"Publish",mainClass:"cb-btn-publish",mainStatus:"publish",dropdownLabel:s.dataset.titleDraft||"Save Draft",dropdownClass:"cb-btn-darft",dropdownStatus:"draft",dropdownIcon:"dashicons-media-default"},trash:{mainLabel:s.dataset.titleDraft||"Save Draft",mainClass:"cb-btn-darft",mainStatus:"draft",dropdownLabel:s.dataset.titlePublish||"Publish",dropdownClass:"cb-btn-publish",dropdownStatus:"publish",dropdownIcon:"dashicons-visibility"}},r={publish:{mainLabel:s.dataset.titleUpdate||"Update",mainClass:"cb-btn-update",mainStatus:"publish",dropdownLabel:s.dataset.titleDraft||"Save Draft",dropdownClass:"cb-btn-darft",dropdownStatus:"draft",dropdownIcon:"dashicons-media-default"},draft:{mainLabel:s.dataset.titleDraft||"Save Draft",mainClass:"cb-btn-darft",mainStatus:"draft",dropdownLabel:s.dataset.titleSubmitReview||"Submit for Review",dropdownClass:"cb-btn-pending",dropdownStatus:"pending",dropdownIcon:"dashicons-clock"},pending:{mainLabel:s.dataset.titleSubmitReview||"Submit for Review",mainClass:"cb-btn-pending",mainStatus:"pending",dropdownLabel:s.dataset.titleDraft||"Save Draft",dropdownClass:"cb-btn-darft",dropdownStatus:"draft",dropdownIcon:"dashicons-media-default"},"auto-draft":{mainLabel:s.dataset.titleSubmitReview||"Submit for Review",mainClass:"cb-btn-pending",mainStatus:"pending",dropdownLabel:s.dataset.titleDraft||"Save Draft",dropdownClass:"cb-btn-darft",dropdownStatus:"draft",dropdownIcon:"dashicons-media-default"},trash:{mainLabel:s.dataset.titleDraft||"Save Draft",mainClass:"cb-btn-darft",mainStatus:"draft",dropdownLabel:s.dataset.titleSubmitReview||"Submit for Review",dropdownClass:"cb-btn-pending",dropdownStatus:"pending",dropdownIcon:"dashicons-clock"},private:{mainLabel:s.dataset.titleSubmitReview||"Submit for Review",mainClass:"cb-btn-pending",mainStatus:"pending",dropdownLabel:s.dataset.titleDraft||"Save Draft",dropdownClass:"cb-btn-darft",dropdownStatus:"draft",dropdownIcon:"dashicons-media-default"}},l=o?r[e]||r.draft:a[e]||a.draft;s.className=`${l.mainClass} cb-btn-primary cb-btn-main-action`,s.dataset.status=l.mainStatus,s.textContent=l.mainLabel;const c=i.querySelectorAll(".cb-dropdown-item:not(.cb-btn-trash)");if(c.length>0){const e=c[0];e.className=`cb-dropdown-item ${l.dropdownClass}`,e.dataset.status=l.dropdownStatus,e.innerHTML=`<span class="dashicons ${l.dropdownIcon}"></span>${l.dropdownLabel}`}t.dataset.currentStatus=l.mainStatus}toggleTrashElements(e){const t=document.querySelector(k.selectors.elBtnPreview),s=document.querySelector(k.selectors.elAdminLink),i="trash"===e;t&&(t.style.display=i?"none":""),s&&(s.style.display=i?"none":"")}async duplicateCourse(t){if(!document.querySelector(k.selectors.elDataCourse))return;const{target:s}=t,o=s.closest(k.selectors.elBtnDuplicateCourse);if(!o)return;const r=this.getCourseDataForUpdate(),l=parseInt(r?.course_id,10)||0;if(!l)return;if(!(await i().fire({title:o.dataset.title||"Are you sure?",text:o.dataset.content||"Are you sure you want to duplicate this course?",iconHtml:a,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0})).isConfirmed)return;e.lpSetLoadingEl(o,1);const c={action:"duplicate_course",args:{id_url:"duplicate-course"},course_id:l},d={success:e=>{const{status:t,message:s,data:i}=e;n.W(s||"Duplicated successfully!",t),"success"===t&&i?.redirect_url&&(window.location.href=i.redirect_url)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(o,0)}};window.lpAJAXG.fetchAJAX(c,d)}trashCourse(t){if(!document.querySelector(k.selectors.elDataCourse))return;const{target:s}=t,i=s.closest(k.selectors.elBtnTrashCourse);e.lpSetLoadingEl(i,1);const o={action:"move_trash_course",args:{id_url:"move-trash-course"},course_id:this.getCourseDataForUpdate().course_id},a={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),i?.button_title){const e=document.querySelector(k.selectors.elBtnUpdateCourse);e&&(e.textContent=i.button_title)}if(i?.status){const e=document.querySelector(k.selectors.elStatus);e&&(e.className="course-status "+i.status,e.textContent=this.formatStatusLabel(i.status)),this.syncPublishPanelStatus(i.status),this.toggleTrashElements(i.status),this.updateActionButtons(i.status)}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(i,0)}};window.lpAJAXG.fetchAJAX(o,a)}saveSettings(t){const{target:s}=t,i=s.closest(k.selectors.elBtnSaveSettings);e.lpSetLoadingEl(i,1);const o={...this.getCourseDataForUpdate(),action:"save_course_settings",args:{id_url:"save-course-settings"}};"undefined"!=typeof lpCourseBuilder&&lpCourseBuilder.nonce&&(o.nonce=lpCourseBuilder.nonce);const a={success:e=>{const{status:t,message:s}=e;n.W(s,t)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(i,0)}};window.lpAJAXG.fetchAJAX(o,a)}toggleAddTagForm(e){const{target:t}=e,s=document.querySelector(k.selectors.elBtnAddTagNew),i=document.querySelector(k.selectors.elFormTagAddNew),n=t.closest(k.selectors.elBtnAddTagNew);if(i)if(n){i.style.display="flex",s&&(s.style.display="none");const e=i.querySelector(k.selectors.elInputAddTag);e&&setTimeout(()=>e.focus(),100)}else i.style.display="none",s&&(s.style.display="inline-flex")}addNewTag(t){var s;const{e:i}=t,o=document.querySelector(k.selectors.elInputAddTag),a=document.querySelector(k.selectors.elBtnSaveTag),r=null!==(s=o?.value?.trim())&&void 0!==s?s:"";if(!r)return void n.W("Please enter tag name","error");e.lpSetLoadingEl(a,1);const l={action:"add_course_tag",args:{id_url:"add-course-tag"},name:r},c={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),i?.html){document.querySelector(k.selectors.elWrapperCheckBoxTag).insertAdjacentHTML("beforeend",i.html),this.syncTagManagement(),o.value="";const e=document.querySelector(k.selectors.elBtnCancelTagNew);e&&e.click()}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(l,c)}openMediaUploader(e){if("undefined"==typeof wp||void 0===wp.media)return;const t=wp.media({title:"Select Featured Image",button:{text:"Use this image"},multiple:!1,library:{type:"image"}});t.on("select",()=>{const e=t.state().get("selection").first().toJSON();this.setFeaturedImage(e)}),t.open()}setFeaturedImage(e){const t=document.querySelector(k.selectors.elFeaturedImageDropzone),s=document.querySelector(k.selectors.elThumbnailInput),i=document.querySelector(".cb-featured-image-actions");if(!t||!s)return;s.value=e.id,C().markAsChanged();const n=e.sizes?.medium?.url||e.sizes?.thumbnail?.url||e.url;t.innerHTML="";const o=document.createElement("img");o.src=n,o.className="cb-featured-image-preview__img",o.alt=e.alt||"",t.appendChild(o),t.classList.add("has-image"),i&&(i.innerHTML=`\n\t\t\t\t<button type="button" class="cb-remove-featured-image"><svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_5385_4628)"><path d="M11.9 1.66699C12.2498 1.66708 12.5907 1.77723 12.8744 1.98183C13.1581 2.18643 13.3703 2.47512 13.4808 2.80699L13.9333 4.16699H16.6667C16.8877 4.16699 17.0996 4.25479 17.2559 4.41107C17.4122 4.56735 17.5 4.77931 17.5 5.00033C17.5 5.22134 17.4122 5.4333 17.2559 5.58958C17.0996 5.74586 16.8877 5.83366 16.6667 5.83366L16.6642 5.89283L15.9417 16.012C15.8966 16.6425 15.6143 17.2325 15.1517 17.6633C14.6891 18.0941 14.0805 18.3336 13.4483 18.3337H6.55167C5.91955 18.3336 5.31092 18.0941 4.84831 17.6633C4.38569 17.2325 4.10342 16.6425 4.05833 16.012L3.33583 5.89199C3.33433 5.87258 3.33349 5.85313 3.33333 5.83366C3.11232 5.83366 2.90036 5.74586 2.74408 5.58958C2.5878 5.4333 2.5 5.22134 2.5 5.00033C2.5 4.77931 2.5878 4.56735 2.74408 4.41107C2.90036 4.25479 3.11232 4.16699 3.33333 4.16699H6.06667L6.51917 2.80699C6.62975 2.47498 6.84203 2.1862 7.12592 1.98159C7.4098 1.77697 7.75089 1.66691 8.10083 1.66699H11.9ZM14.9975 5.83366H5.0025L5.72083 15.8928C5.73579 16.103 5.82981 16.2997 5.98397 16.4433C6.13812 16.587 6.34096 16.6669 6.55167 16.667H13.4483C13.659 16.6669 13.8619 16.587 14.016 16.4433C14.1702 16.2997 14.2642 16.103 14.2792 15.8928L14.9975 5.83366ZM8.33333 8.33366C8.53744 8.33369 8.73445 8.40862 8.88698 8.54425C9.03951 8.67989 9.13695 8.86678 9.16083 9.06949L9.16667 9.16699V13.3337C9.16643 13.5461 9.0851 13.7504 8.93929 13.9048C8.79349 14.0592 8.59421 14.1522 8.38217 14.1646C8.17014 14.1771 7.96135 14.1081 7.79847 13.9718C7.6356 13.8354 7.53092 13.6421 7.50583 13.4312L7.5 13.3337V9.16699C7.5 8.94598 7.5878 8.73402 7.74408 8.57774C7.90036 8.42146 8.11232 8.33366 8.33333 8.33366ZM11.6667 8.33366C11.8877 8.33366 12.0996 8.42146 12.2559 8.57774C12.4122 8.73402 12.5 8.94598 12.5 9.16699V13.3337C12.5 13.5547 12.4122 13.7666 12.2559 13.9229C12.0996 14.0792 11.8877 14.167 11.6667 14.167C11.4457 14.167 11.2337 14.0792 11.0774 13.9229C10.9211 13.7666 10.8333 13.5547 10.8333 13.3337V9.16699C10.8333 8.94598 10.9211 8.73402 11.0774 8.57774C11.2337 8.42146 11.4457 8.33366 11.6667 8.33366ZM11.9 3.33366H8.1L7.8225 4.16699H12.1775L11.9 3.33366Z" fill="currentColor"/></g><defs><clipPath id="clip0_5385_4628"><rect width="20" height="20" fill="white"/></clipPath></defs></svg></button>\n\t\t\t\t<button type="button" class="cb-change-featured-image">${window.lpCourseBuilder?.i18n?.replace_image||"Replace"}</button>\n\t\t\t`)}removeFeaturedImage(e){const{e:t}=e;t&&t.preventDefault();const s=document.querySelector(k.selectors.elFeaturedImageDropzone),i=document.querySelector(k.selectors.elThumbnailInput),n=document.querySelector(".cb-featured-image-actions");s&&(s.innerHTML=`\n\t\t\t<div class="cb-featured-image-upload-content">\n\t\t\t\t<span class="cb-featured-image-icon"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.29095 14.5488C3.29099 14.8637 3.33747 15.1785 3.44915 15.5527L3.48138 15.6592C3.95542 17.0735 5.26094 18.0234 6.72845 18.0234H20.0361L19.2099 20.6787C18.9761 21.5815 18.1423 22.1942 17.2294 22.1943C17.0513 22.1942 16.8735 22.1714 16.7011 22.126L2.5263 18.2881C1.43276 17.9832 0.78131 16.8383 1.06732 15.7344L3.29095 8.22949V14.5488ZM20.7079 1.80469C21.9711 1.80474 22.9998 2.84505 22.9999 4.12207V14.3164C22.9999 15.5936 21.9712 16.6337 20.7079 16.6338H6.95794C5.69489 16.6338 4.66595 15.5936 4.66595 14.3164V4.12207C4.66604 2.84502 5.69495 1.80469 6.95794 1.80469H20.7079ZM6.95794 3.65918C6.70507 3.65918 6.49903 3.86625 6.49896 4.12207V12.8701L9.02923 10.3135C9.65534 9.67964 10.6757 9.67964 11.3027 10.3135L12.412 11.4316L15.8163 7.2998C16.1206 6.93103 16.5663 6.71857 17.041 6.71582C17.5185 6.72681 17.9633 6.92104 18.2704 7.28516L21.166 10.7012V4.12207C21.1659 3.8663 20.961 3.65923 20.7079 3.65918H6.95794ZM9.24896 4.58496C10.2601 4.58496 11.0829 5.4172 11.0829 6.43945C11.0827 7.4615 10.26 8.29297 9.24896 8.29297C8.23818 8.29274 7.4162 7.46132 7.41595 6.43945C7.41595 5.41738 8.23798 4.58519 9.24896 4.58496Z" fill="#CFCFCF"/></svg></span>\n\t\t\t\t<p class="cb-featured-image-text"><a href="#" class="cb-featured-image-link">${window.lpCourseBuilder?.i18n?.click_to_upload||"Click to upload"}</a></p>\n\t\t\t\t<p class="cb-featured-image-hint">${window.lpCourseBuilder?.i18n?.image_hint||"JPG, JPEG, PNG less than 1MB"}</p>\n\t\t\t</div>\n\t\t`,s.classList.remove("has-image"),i&&(i.value="",C().markAsChanged()),n&&(n.innerHTML=""))}buildPermalinkDisplayUrl(e="",t="",s=""){const i="string"==typeof e?e:"",n="string"==typeof t?t.trim():"";return i&&n?`${i}${n}`:"string"==typeof s?s:""}handlePermalinkEdit(e){const{e:t}=e;t&&t.preventDefault();const s=document.querySelector(k.selectors.elPermalinkDisplay),i=document.querySelector(k.selectors.elPermalinkEditor),n=document.querySelector(k.selectors.elPermalinkSlugInput);s&&i&&n&&(n.dataset.originalValue=n.value,s.classList.add("lp-hidden"),i.classList.remove("lp-hidden"),n.focus(),n.select())}handlePermalinkOk(e){const{e:t}=e;t&&t.preventDefault();const s=document.querySelector(k.selectors.elPermalinkDisplay),i=document.querySelector(k.selectors.elPermalinkEditor),n=document.querySelector(k.selectors.elPermalinkSlugInput),o=document.querySelector(k.selectors.elPermalinkUrl),a=document.querySelector(k.selectors.elPermalinkBaseUrl);if(!(s&&i&&n&&o))return;let r=n.value.trim();r||(r=n.dataset.originalValue||"course"),n.value=r;const l=a?a.value:"",c=this.buildPermalinkDisplayUrl(l,r,o.textContent||"");o.textContent=c,i.classList.add("lp-hidden"),s.classList.remove("lp-hidden"),r!==n.dataset.originalValue&&C().markAsChanged()}handlePermalinkCancel(e){const{e:t}=e;t&&t.preventDefault();const s=document.querySelector(k.selectors.elPermalinkDisplay),i=document.querySelector(k.selectors.elPermalinkEditor),n=document.querySelector(k.selectors.elPermalinkSlugInput);s&&i&&n&&(n.value=n.dataset.originalValue||"",i.classList.add("lp-hidden"),s.classList.remove("lp-hidden"))}initTabTitles(){document.querySelectorAll(k.selectors.elTabLinks).forEach(e=>{const t=e.querySelector("span"),s=t?t.textContent.trim():e.textContent.trim(),i=e.getAttribute("href");if(!i)return;const n=i.substring(1),o=document.getElementById(n);o&&o.setAttribute("data-tab-title",s)})}initTitleCharCount(){const e=document.querySelector(k.selectors.elTitleInput);e&&this.updateTitleCharCount(e.value)}updateTitleCharCount(e){const t=document.querySelector(k.selectors.elTitleCharCount);if(!t)return;const s=e.length,i=1===s?"character":"characters";t.textContent=`${s} ${i}`}handleTitleInput(e){const{target:t}=e;this.updateTitleCharCount(t.value)}initDescWordCount(){if("undefined"!=typeof tinymce){tinymce.on("AddEditor",e=>{"course_description_editor"===e.editor.id&&e.editor.on("init",()=>{this.updateDescWordCount(e.editor),e.editor.on("keyup change input NodeChange",()=>{this.updateDescWordCount(e.editor)})})});const e=tinymce.get("course_description_editor");e&&(this.updateDescWordCount(e),e.on("keyup change input NodeChange",()=>{this.updateDescWordCount(e)}))}}updateDescWordCount(e){const t=document.querySelector(k.selectors.elDescWordCount);if(!t)return;const s=e.plugins.wordcount;let i=0;if(s&&void 0!==s.body)i=s.body.getWordCount();else if(s&&void 0!==s.getCount)i=s.getCount();else{const t=e.getContent({format:"text"});i=this.countWords(t)}const n=1===i?"word":"words";t.textContent=`${i} ${n}`}updateHeaderTitle(e){const t=document.querySelector(".lp-cb-header__title");t&&e&&(t.textContent=e)}countWords(e){const t=e.replace(/<[^>]*>/g,"").trim();return 0===t.length?0:t.split(/\s+/).filter(e=>e.length>0).length}initHeaderActionsDropdown(){const e=document.querySelector(k.selectors.elHeaderActionsDropdown);if(!e)return;const t=e.querySelector(k.selectors.elDropdownToggle),s=e.querySelector(k.selectors.elDropdownMenu);t&&s&&(t.addEventListener("click",e=>{e.stopPropagation(),s.classList.contains("is-open")?this.closeHeaderDropdown(t,s):this.openHeaderDropdown(t,s)}),document.addEventListener("click",i=>{e.contains(i.target)||this.closeHeaderDropdown(t,s)}),document.addEventListener("keydown",e=>{"Escape"===e.key&&this.closeHeaderDropdown(t,s)}),s.querySelectorAll(".cb-dropdown-item").forEach(e=>{e.addEventListener("click",()=>{setTimeout(()=>{this.closeHeaderDropdown(t,s)},100)})}))}openHeaderDropdown(e,t){t.classList.add("is-open"),e.setAttribute("aria-expanded","true")}closeHeaderDropdown(e,t){t.classList.remove("is-open"),e.setAttribute("aria-expanded","false")}}let A,E=!1;const T=JSON.parse(localStorage.getItem("lp_course_ai_setting"))||{};class L{constructor(e={}){this.options={autoInsertButton:!0,isCourseBuilder:!1,redirectDelayMs:2e3,...e},this.init()}static selectors={elGenerateDataAiWrap:".lp-generate-data-ai-wrap"};init(){this.options.autoInsertButton&&(lpData?.enable_open_ai?e.lpOnElementReady(".page-title-action",e=>{e.insertAdjacentHTML("afterend",`<button type="button" class="lp-btn-generate-course-with-ai lp-btn-ai-style">\n\t\t\t\t\t\t<i class="lp-ico-ai"></i>\n\t\t\t\t\t\t<span>${lpData.i18n.generate_with_ai}</span>\n\t\t\t\t\t</button>`)}):e.lpOnElementReady(".page-title-action",e=>{e.insertAdjacentHTML("afterend",`<button type="button" class="lp-btn-warning-enable-ai lp-btn-ai-style">\n\t\t\t\t\t\t<i class="lp-ico-ai"></i>\n\t\t\t\t\t\t<span>${lpData.i18n.generate_with_ai}</span>\n\t\t\t\t\t</button>`)})),this.events()}events(){L._loadedEvents||(L._loadedEvents=!0,e.eventHandlers("click",[{selector:".lp-btn-warning-enable-ai",class:this,callBack:this.showPopupEnableAI.name},{selector:".lp-btn-generate-course-with-ai",class:this,callBack:this.showPopupCreateFullCourse.name},{selector:".lp-btn-step",class:this,callBack:this.showStep.name},{selector:".lp-btn-generate-prompt",class:this,callBack:this.generatePrompt.name},{selector:".lp-btn-call-open-ai",class:this,callBack:this.generateDataCourse.name},{selector:".lp-btn-create-course",class:this,callBack:this.createCourse.name},{selector:".lp-btn-close-ai-popup",callBack:e=>{const{e:t,target:s}=e,n=lpData?.i18n?.confirm_close_ai||"Are you sure you want to close? Generate data will stop.";E?confirm(n)&&i().close():i().close()}}]))}showPopupEnableAI(){const e=document.querySelector("#lp-tmpl-must-enable-ai");e?i().fire({html:e.innerHTML,width:"420px",showCloseButton:!1,showConfirmButton:!1}):console.error("Enable OpenAI Modal Template not found!")}showPopupCreateFullCourse(){const e=document.querySelector("#lp-tmpl-create-course-ai");e?i().fire({html:e.innerHTML,width:"60%",showCloseButton:!1,showConfirmButton:!1,allowOutsideClick:!1,allowEscapeKey:!1,didOpen:()=>{const e=i().getPopup();e.click();const t=e.querySelector('select[name="target_audience"]');t&&T?.target_audience&&t.tomselect.setValue(T.target_audience);const s=e.querySelector('select[name="tone"]');s&&T?.tone&&s.tomselect.setValue(T.tone);const n=e.querySelector('select[name="language"]');n&&T?.language&&n.tomselect.setValue(T.language),t.addEventListener("change",e=>{T.target_audience=t.tomselect.getValue(),localStorage.setItem("lp_course_ai_setting",JSON.stringify(T))}),s.addEventListener("change",e=>{T.tone=s.tomselect.getValue(),localStorage.setItem("lp_course_ai_setting",JSON.stringify(T))}),n.addEventListener("change",e=>{const t=n.tomselect.getValue();T.language=t?[t]:[],localStorage.setItem("lp_course_ai_setting",JSON.stringify(T))})}}).then(e=>{e.isDismissed&&E&&(E=!1)}):console.error("AI Create Full Course Modal Template not found!")}showStep(t){const{e:s,target:i}=t;s.preventDefault();const n=i.closest(".button-actions"),o=n.closest(L.selectors.elGenerateDataAiWrap);let a=parseInt(n.dataset.step);const r=i.dataset.action;"next"===r?a++:"prev"===r&&a--,n.dataset.step=a;const l=i.closest("form"),c=l.querySelector(`.step-content[data-step="${a}"]`),d=o.querySelector(`.step-item[data-step="${a}"]`);l.querySelectorAll(".step-content").forEach(e=>e.classList.remove("active")),c.classList.add("active"),o.querySelectorAll(".step-item").forEach(e=>e.classList.remove("active")),d.classList.add("active"),i.closest("form").querySelectorAll("button[data-step-show]").forEach(t=>{t.dataset.stepShow.split(",").map(e=>parseInt(e.trim())).includes(a)?e.lpShowHideEl(t,1):e.lpShowHideEl(t,0)})}generatePrompt(t){const{e:s,target:i}=t;s.preventDefault(),e.lpSetLoadingEl(i,!0);const o=i.closest("form");let a=JSON.parse(i.dataset.send);a=e.mergeDataWithDatForm(o,a);const r={success:e=>{const{message:t,status:s,data:i}=e;n.W(t,s),"success"===s&&(o.querySelector(".lp-btn-step[data-action=next]").click(),o.querySelector("textarea[name=lp-openai-prompt-generated-field]").value=i)},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(i,!1)}};window.lpAJAXG.fetchAJAX(a,r)}generateDataCourse(t){const{e:s,target:i}=t;s.preventDefault(),e.lpSetLoadingEl(i,!0);const o=i.closest("form");let a=JSON.parse(i.dataset.send);a=e.mergeDataWithDatForm(o,a);const r=o.querySelector(".lp-btn-step[data-action=prev]");e.lpShowHideEl(r,0);const l={success:e=>{const{message:t,status:s,data:i}=e;E&&n.W(t,s),"success"===s&&(A=i.lp_structure_course,o.querySelector(".lp-ai-generated-results").innerHTML=i.lp_html_preview,o.querySelector(".lp-btn-step[data-action=next]").click())},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(i,!1),e.lpShowHideEl(r,1),E=!1}};E=!0,window.lpAJAXG.fetchAJAX(a,l)}createCourse(t){const{e:s,target:o}=t;s.preventDefault(),e.lpSetLoadingEl(o,!0);const a=JSON.parse(o.dataset.send);a.lp_structure_course=A,this.options.isCourseBuilder&&(a.is_course_builder=1);const r=o.closest("form").querySelector(".lp-btn-step[data-action=prev]");let l;e.lpShowHideEl(r,0),l=window.outerWidth<768?"90%":"30%";const c=document.querySelector("#lp-tmpl-creating-course-ai");i().fire({html:c.innerHTML,showCloseButton:!1,showConfirmButton:!1,allowOutsideClick:!1,width:l});const d={success:t=>{const{message:s,status:o,data:a}=t;i().close(),n.W(s,o),"success"===o?setTimeout(()=>{window.location.href=a.edit_course_url},this.options.redirectDelayMs):e.lpShowHideEl(r,1)},error:t=>{n.W(t,"error"),e.lpShowHideEl(r,1)},completed:()=>{e.lpSetLoadingEl(o,!1)}};window.lpAJAXG.fetchAJAX(a,d)}}let I,D=null,q=!1;const B=JSON.parse(localStorage.getItem("lp_course_ai_setting"))||{};let P,M,O,z=!1;class ${constructor(e={}){this.options={autoInsertButtons:!0,isCourseBuilder:!1,titleInputSelector:"input[name=post_title]",courseBuilderTitleInputSelector:"input[name=course_title]",editorIdClassic:"content",editorIdCourseBuilder:"course_description_editor",...e},this.init()}static selectors={elBtnGenerateWithAi:".lp-btn-generate-with-ai",elGenerateDataAiWrap:".lp-generate-data-ai-wrap"};init(){lpData?.enable_open_ai&&(this.options.autoInsertButtons&&(e.lpOnElementReady("#titlewrap",e=>{e.insertAdjacentHTML("afterend",`<button type="button"\n\t\t\t\t\tstyle="margin-left: 5px"\n\t\t\t\t\tclass="lp-btn-generate-with-ai lp-btn-ai-style"\n\t\t\t\t\tdata-template="#lp-tmpl-edit-title-ai">\n\t\t\t\t\t<i class="lp-ico-ai"></i><span>${lpData.i18n.generate_with_ai}</span>\n\t\t\t\t</button>`)}),e.lpOnElementReady("#wp-content-media-buttons",e=>{e.insertAdjacentHTML("beforeend",'<button type="button"\n\t\t\t\t\tstyle="padding: 5px 10px; justify-content: center;"\n\t\t\t\t\tclass="lp-btn-generate-with-ai lp-btn-ai-style"\n\t\t\t\t\tdata-template="#lp-tmpl-edit-description-ai">\n\t\t\t\t\t<i class="lp-ico-ai"></i><span>Generate description with AI</span>\n\t\t\t\t</button>')}),e.lpOnElementReady("#postimagediv",e=>{e.querySelector(".postbox-header").insertAdjacentHTML("afterend",`<button type="button"\n\t\t\t\t\tstyle="padding: 5px 10px; justify-content: center;"\n\t\t\t\t\tclass="lp-btn-generate-with-ai lp-btn-ai-style"\n\t\t\t\t\tdata-template="#lp-tmpl-edit-image-ai">\n\t\t\t\t\t<i class="lp-ico-ai"></i><span>${lpData.i18n.generate_with_ai}</span>\n\t\t\t\t</button>`)}),wp.data&&wp.data.select("core/editor")&&(z=!0,P=wp.data.select,M=wp.data.dispatch,O=P("core/editor"),e.lpOnElementReady(".editor-document-bar",e=>{e.insertAdjacentHTML("afterend",`<button type="button"\n\t\t\t\t\t\tstyle="margin-left: 5px"\n\t\t\t\t\t\tclass="lp-btn-generate-with-ai"\n\t\t\t\t\t\tdata-template="#lp-tmpl-edit-title-ai">\n\t\t\t\t\t\t<i class="lp-ico-ai"></i><span>${lpData.i18n.generate_with_ai}</span>\n\t\t\t\t\t</button>`)}),e.lpOnElementReady(".editor-post-featured-image",e=>{e.insertAdjacentHTML("beforebegin",'<button type="button"\n\t\t\t\t\t\tstyle="padding: 5px 10px; justify-content: center;"\n\t\t\t\t\t\tclass="lp-btn-generate-with-ai"\n\t\t\t\t\t\tdata-template="#lp-tmpl-edit-description-ai">\n\t\t\t\t\t\t<i class="lp-ico-ai"></i><span>Generate description with AI</span>\n\t\t\t\t\t</button>')}),e.lpOnElementReady(".editor-post-featured-image",e=>{e.insertAdjacentHTML("afterend",`<button type="button"\n\t\t\t\t\t\tstyle="padding: 5px 10px; justify-content: center;"\n\t\t\t\t\t\tclass="lp-btn-generate-with-ai"\n\t\t\t\t\t\tdata-template="#lp-tmpl-edit-image-ai">\n\t\t\t\t\t\t<i class="lp-ico-ai"></i><span>${lpData.i18n.generate_with_ai}</span>\n\t\t\t\t\t</button>`)}))),this.events())}getTitleInputSelector(){return this.options.isCourseBuilder?this.options.courseBuilderTitleInputSelector:this.options.titleInputSelector}getEditorId(){return this.options.isCourseBuilder?this.options.editorIdCourseBuilder:this.options.editorIdClassic}setCourseBuilderPostId(e){if(!this.options.isCourseBuilder||!e)return;const t=e.querySelector('[name="post-id"]');if(!t)return;const s=document.querySelector(".cb-section__course-edit[data-course-id]"),i=s?.dataset?.courseId||"";i&&(t.value=i)}extractImageSourceFromHtml(e){if(!e)return"";const t=document.createElement("div");return t.innerHTML=e,t.querySelector("img")?.getAttribute("src")||""}applyCourseBuilderFeaturedImage(e,t){return!(!e||!t||(document.dispatchEvent(new CustomEvent("lp-course-builder/ai-featured-image-applied",{detail:{attachmentId:e,imageSrc:t}})),0))}events(){e.eventHandlers("click",[{selector:$.selectors.elBtnGenerateWithAi,class:this,callBack:this.showPopup.name},{selector:".lp-btn-step",class:this,callBack:this.showStep.name},{selector:".lp-btn-generate-prompt",class:this,callBack:this.generatePrompt.name},{selector:".lp-btn-call-open-ai",class:this,callBack:this.generateData.name},{selector:".lp-btn-copy",class:this,callBack:this.copyGeneratedData.name},{selector:".lp-btn-apply",class:this,callBack:this.applyGeneratedData.name},{selector:".lp-btn-ai-apply-image",class:this,callBack:this.applyImageData.name},{selector:".lp-btn-close-ai-popup",callBack:e=>{const{e:t,target:s}=e,n=lpData.i18n.confirm_close_ai;q?confirm(n)&&i().close():i().close()}}])}showPopup(t){const{e:s,target:n}=t,o=n.dataset.template||n.closest(".lp-btn-generate-with-ai").dataset.template||n.closest(".lp-generate-data-ai-wrap").dataset.template||"",a=document.querySelector(o);a?i().fire({html:a.innerHTML,width:"60%",showCloseButton:!1,showConfirmButton:!1,allowOutsideClick:!1,allowEscapeKey:!1,didOpen:()=>{D=i().getPopup(),D.click();const t=document.querySelector(this.getTitleInputSelector());let s="";if(t)s=t.value;else if(z){const e=document.querySelector(".editor-post-card-panel__title-name");e&&(s=e.textContent)}let n="";if(z)n=O.getEditedPostContent().replace(/(<([^>]+)>)/gi,"");else{const e=this.getEditorId();if(window.tinymce&&window.tinymce.get(e))n=window.tinymce.get(e).getContent({format:"text"});else{const t=document.querySelector(`#${e}`);n=t?t.value:""}}const o=D.querySelector("form");this.setCourseBuilderPostId(o);const a=o.querySelector("[name=post-title]");if(a&&(a.value=s,!s)){const t=a.closest(".form-group").querySelector(".lp-ai-warning-refer");t&&e.lpShowHideEl(t,1)}const r=o.querySelector("[name=post-content]");if(r&&(r.value=n,n.length<2)){const t=r.closest(".form-group").querySelector(".lp-ai-warning-refer");t&&e.lpShowHideEl(t,1)}const l=D.querySelector('select[name="target_audience"]');l&&(B?.target_audience&&l.tomselect.setValue(B.target_audience),l.addEventListener("change",e=>{B.target_audience=l.tomselect.getValue(),localStorage.setItem("lp_course_ai_setting",JSON.stringify(B))}));const c=D.querySelector('select[name="tone"]');c&&(B?.tone&&c.tomselect.setValue(B.tone),c.addEventListener("change",e=>{B.tone=c.tomselect.getValue(),localStorage.setItem("lp_course_ai_setting",JSON.stringify(B))}));const d=D.querySelector('select[name="language"]');d&&(B?.language&&d.tomselect.setValue(B.language),d.addEventListener("change",e=>{const t=d.tomselect.getValue();B.language=t?[t]:[],localStorage.setItem("lp_course_ai_setting",JSON.stringify(B))}))}}).then(e=>{e.isDismissed&&q&&(q=!1)}):console.error(`Template ${o} not found!`)}showStep(t){const{e:s,target:i}=t;s.preventDefault();const n=i.closest(".button-actions"),o=n.closest($.selectors.elGenerateDataAiWrap);let a=parseInt(n.dataset.step);const r=i.dataset.action;"next"===r?a++:"prev"===r&&a--,n.dataset.step=a;const l=i.closest("form"),c=l.querySelector(`.step-content[data-step="${a}"]`),d=o.querySelector(`.step-item[data-step="${a}"]`);l.querySelectorAll(".step-content").forEach(e=>e.classList.remove("active")),c.classList.add("active"),o.querySelectorAll(".step-item").forEach(e=>e.classList.remove("active")),d.classList.add("active"),i.closest("form").querySelectorAll("button[data-step-show]").forEach(t=>{t.dataset.stepShow.split(",").map(e=>parseInt(e.trim())).includes(a)?e.lpShowHideEl(t,1):e.lpShowHideEl(t,0)})}generatePrompt(t){const{e:s,target:i}=t;s.preventDefault(),e.lpSetLoadingEl(i,!0);const o=i.closest("form");let a=JSON.parse(i.dataset.send);a=e.mergeDataWithDatForm(o,a);const r={success:e=>{const{message:t,status:s,data:i}=e;n.W(t,s),"success"===s&&(o.querySelector("textarea[name=lp-openai-prompt-generated-field]").value=i,o.querySelector(".lp-btn-step[data-action=next]").click())},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(i,!1)}};window.lpAJAXG.fetchAJAX(a,r)}generateData(t){const{e:s,target:i}=t;s.preventDefault(),e.lpSetLoadingEl(i,!0);const o=i.closest("form");let a=JSON.parse(i.dataset.send);a=e.mergeDataWithDatForm(o,a);const r=o.querySelector(".lp-btn-step[data-action=prev]");e.lpShowHideEl(r,0);const l={success:e=>{const{message:t,status:s,data:i}=e;q&&n.W(t,s),"success"===s&&(I=i.lp_structure_course,o.querySelector(".lp-ai-generated-results").innerHTML=i.lp_html_preview,o.querySelector(".lp-btn-step[data-action=next]").click())},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(i,!1),e.lpShowHideEl(r,1),q=!1}};q=!0,window.lpAJAXG.fetchAJAX(a,l)}applyGeneratedData(e){const{e:t,target:s}=e;t.preventDefault();const n=s.dataset.apply,o=s.dataset.target;if(o)if(z)"set-wp-editor-content"===o?M("core/editor").editPost({content:n}):"set-wp-title"===o&&M("core/editor").editPost({title:n});else if("set-wp-editor-content"===o)this.setWPEditorContent(n);else if("set-wp-title"===o){const e=document.querySelector(this.getTitleInputSelector());e&&(e.value=n,e.dispatchEvent(new Event("input",{bubbles:!0})))}D&&i().close()}copyGeneratedData(e){const{e:t,target:s}=e;t.preventDefault();const i=s.dataset.copy;if(navigator.clipboard)navigator.clipboard.writeText(i).then(()=>{n.W("Copied to clipboard!","success")}).catch(e=>{n.W("Failed to copy text: "+e,"error")});else{const e=document.createElement("textarea");e.value=i,e.style.position="fixed",e.style.left="-9999px",document.body.appendChild(e),e.select();try{const e=document.execCommand("copy");n.W(e?"Copied to clipboard!":"Failed to copy text",e?"success":"error")}catch(e){n.W("Failed to copy text: "+e,"error")}document.body.removeChild(e)}}setWPEditorContent(e){const t=this.getEditorId(),s=window.tinymce?.get(t);if(s)return void s.setContent(e);const i=document.querySelector(`#${t}`);i&&(i.value=e,i.dispatchEvent(new Event("input",{bubbles:!0})))}applyImageData(t){const{e:s,target:o}=t;let a=JSON.parse(o.dataset.send);a=e.mergeDataWithDatForm(o.closest("form"),a),e.lpSetLoadingEl(o,!0);const r={success:e=>{const{message:t,status:s,data:o}=e;if(n.W(t,s),"success"===s){if(this.options.isCourseBuilder){const e=parseInt(o?.attachment_id||0,10),t=this.extractImageSourceFromHtml(o?.html_image||"");if(!this.applyCourseBuilderFeaturedImage(e,t))return void n.W("Failed to apply image to course featured image.","error")}else z?M("core/editor").editPost({featured_media:o.attachment_id}):document.querySelector("#postimagediv .inside").outerHTML=o.html_image;D&&i().close()}},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(o,!1)}};window.lpAJAXG.fetchAJAX(a,r)}}class F{constructor(){this.init()}static selectors={elLessonItem:".lesson-item",elLessonExpandedItems:".lesson-action-expanded__items",elLessonDuplicate:".lesson-action-expanded__duplicate",elLessonTrash:".lesson-action-expanded__trash",elLessonRestore:".lesson-action-expanded__restore",elLessonPublish:".lesson-action-expanded__publish",elLessonDelete:".lesson-action-expanded__delete",elLessonActionExpanded:".lesson-action-expanded",elLessonStatus:".lesson-status",elLessonPreview:".lesson__preview.lp-btn-set-preview-item"};init(){this.events()}events(){F._loadedEvents||(F._loadedEvents=!0,e.eventHandlers("click",[{selector:F.selectors.elLessonDuplicate,class:this,callBack:this.duplicateLesson.name},{selector:F.selectors.elLessonTrash,class:this,callBack:this.trashLesson.name},{selector:F.selectors.elLessonPublish,class:this,callBack:this.publishLesson.name},{selector:F.selectors.elLessonRestore,class:this,callBack:this.restoreLesson.name},{selector:F.selectors.elLessonDelete,class:this,callBack:this.deleteLesson.name},{selector:F.selectors.elLessonActionExpanded,class:this,callBack:this.toggleExpandedAction.name},{selector:F.selectors.elLessonPreview,class:this,callBack:this.toggleLessonPreview.name}]),document.addEventListener("click",e=>{e.target.closest(F.selectors.elLessonActionExpanded)||this.closeAllExpanded()}),document.addEventListener("lp-builder-popup-saved",e=>{const{type:t,id:s,data:i}=e.detail;if("lesson"!==t||!i?.list_item_html)return;const n=document.querySelector(`.lesson-item[data-lesson-id="${s}"]`);n&&this.replaceItemHtml(n.closest(".lesson"),i.list_item_html)}),document.addEventListener("lp-builder-popup-trashed",e=>{const{type:t,id:s,data:i}=e.detail;if("lesson"!==t||!i?.html)return;const n=document.querySelector(`.lesson-item[data-lesson-id="${s}"]`);n&&this.replaceItemHtml(n.closest(".lesson"),i.html)}))}duplicateLesson(t){const{target:s}=t,o=s.closest(F.selectors.elLessonDuplicate),r=o.closest(F.selectors.elLessonItem);if(!r)return;const l=r.querySelector(F.selectors.elLessonActionExpanded),c=r.dataset.lessonId||"";i().fire({title:o.dataset.title||"Duplicate Lesson",text:o.dataset.content||"Are you sure you want to duplicate this lesson?",iconHtml:a,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(l,1);const t={action:"duplicate_lesson",args:{id_url:"duplicate-lesson"},lesson_id:c},s={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s||"Duplicated successfully!",t),i?.html){const e=o.closest(".lesson"),t=e.closest(".lessons-list")||e.parentElement;if(t){t.insertAdjacentHTML("afterbegin",i.html);const e=t.firstElementChild;e&&(e.scrollIntoView({behavior:"smooth",block:"nearest"}),e.classList.add("highlight-new-lesson"),setTimeout(()=>{e.classList.remove("highlight-new-lesson")},1500))}}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(l,0)}};window.lpAJAXG.fetchAJAX(t,s)}})}trashLesson(t){const{target:s}=t,a=s.closest(F.selectors.elLessonTrash),r=a.closest(F.selectors.elLessonItem);if(!r)return;const l=r.querySelector(F.selectors.elLessonActionExpanded),c=r.dataset.lessonId||"";i().fire({title:a.dataset.title||"Trash Lesson",text:a.dataset.content||"Are you sure? Moving it to the trash will cause this item to be removed from the course.",iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(l,1);const t={action:"move_trash_lesson",args:{id_url:"move-trash-lesson"},lesson_id:c},s={success:e=>{const{status:t,message:s,data:i}=e;n.W(s,t),i?.html&&this.replaceItemHtml(a.closest(".lesson"),i.html)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(l,0)}};window.lpAJAXG.fetchAJAX(t,s)}})}publishLesson(t){const{target:s}=t,i=s.closest(F.selectors.elLessonPublish),o=i.closest(F.selectors.elLessonItem);if(!o)return;const a=o.querySelector(F.selectors.elLessonActionExpanded);e.lpSetLoadingEl(a,1);const r={action:"move_trash_lesson",args:{id_url:"move-trash-lesson"},lesson_id:o.dataset.lessonId||"",status:"publish"},l={success:e=>{const{status:t,message:s,data:o}=e;n.W(s,t),o?.html&&this.replaceItemHtml(i.closest(".lesson"),o.html)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(r,l)}restoreLesson(t){const{target:s}=t,i=s.closest(F.selectors.elLessonRestore),o=i.closest(F.selectors.elLessonItem);if(!o)return;const a=o.querySelector(F.selectors.elLessonActionExpanded);e.lpSetLoadingEl(a,1);const r={action:"move_trash_lesson",args:{id_url:"move-trash-lesson"},lesson_id:o.dataset.lessonId||"",status:"draft"},l={success:e=>{const{status:t,message:s,data:o}=e;n.W(s,t),o?.html&&this.replaceItemHtml(i.closest(".lesson"),o.html)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(r,l)}deleteLesson(t){const{target:s}=t,o=s.closest(F.selectors.elLessonDelete),a=o.closest(F.selectors.elLessonItem);if(!a)return;const l=a.querySelector(F.selectors.elLessonActionExpanded),c=a.dataset.lessonId||"";c&&i().fire({title:o.dataset.title||"Delete Lesson",text:o.dataset.content||"Are you sure you want to permanently delete this lesson?",iconHtml:r,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(l,1);const t={action:"move_trash_lesson",args:{id_url:"move-trash-lesson"},lesson_id:c,status:"delete"},s={success:e=>{const{status:t,message:s}=e;if(n.W(s,t),"success"===t){const e=o.closest(".lesson");e.style.transition="opacity 0.4s ease-out, transform 0.4s ease-out",e.style.opacity="0",e.style.transform="translateX(160px)",setTimeout(()=>{e.remove()},400)}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(l,0)}};window.lpAJAXG.fetchAJAX(t,s)}})}toggleExpandedAction(e){const{target:t}=e,s=t.closest(F.selectors.elLessonActionExpanded);if(!s)return;const i=s.closest(F.selectors.elLessonItem);if(!i)return;const n=i.querySelector(F.selectors.elLessonExpandedItems);n&&(this.closeAllExpanded(n),n.classList.contains("active")?(n.classList.remove("active"),n.classList.remove("is-dropup"),s.classList.remove("active")):(n.classList.add("active"),s.classList.add("active"),this.setExpandedDirection(n)))}closeAllExpanded(e=null){document.querySelectorAll(`${F.selectors.elLessonExpandedItems}.active`).forEach(t=>{if(t===e)return;t.classList.remove("active"),t.classList.remove("is-dropup");const s=t.closest(F.selectors.elLessonItem);if(!s)return;const i=s.querySelector(F.selectors.elLessonActionExpanded);i&&i.classList.remove("active")})}setExpandedDirection(e){if(!e)return;e.classList.remove("is-dropup");const t=e.closest(".lesson");t&&t.matches(":last-child")&&e.classList.add("is-dropup")}toggleLessonPreview(t){const{target:s}=t,i=s.closest(F.selectors.elLessonPreview);if(!i)return;if(i.classList.contains("loading")||i.classList.contains("lp-loading"))return;const o=i.closest(F.selectors.elLessonItem);if(!o)return;const a=i.querySelector("a");if(!a)return;const r=o.dataset.lessonId||i.dataset.id||"";if(!r)return;a.classList.toggle("lp-icon-eye"),a.classList.toggle("lp-icon-eye-slash");const l=a.classList.contains("lp-icon-eye");e.lpSetLoadingEl(i,1),i.classList.add("lp-loading");const c={action:"builder_update_lesson",args:{id_url:"builder-update-lesson"},lesson_id:r,lesson_settings:!0,_lp_preview:l?"yes":""},d={success:e=>{const{status:t,message:s}=e;n.W(s,t),"error"===t&&(a.classList.toggle("lp-icon-eye"),a.classList.toggle("lp-icon-eye-slash"))},error:e=>{n.W(e.message||e,"error"),a.classList.toggle("lp-icon-eye"),a.classList.toggle("lp-icon-eye-slash")},completed:()=>{e.lpSetLoadingEl(i,0),i.classList.remove("lp-loading")}};window.lpAJAXG.fetchAJAX(c,d)}replaceItemHtml(e,t){if(!e||!t)return;const s=document.createElement("div");s.innerHTML=t;const i=s.firstElementChild;i&&e.replaceWith(i)}}class H{constructor(){this.init()}static selectors={elDataLesson:".cb-section__lesson-edit",elBtnMainAction:".cb-btn-main-action",elBtnUpdate:".cb-btn-update, .cb-btn-publish",elBtnDraft:'.cb-btn-darft, .cb-dropdown-item[data-status="draft"]',elBtnTrash:".cb-btn-trash",elLessonStatus:".lesson-status",idTitle:"title",idDescEditor:"lesson_description_editor",elFormSetting:".lp-form-setting-lesson",elPermalinkDisplay:".cb-permalink-display",elPermalinkEditor:".cb-permalink-editor",elPermalinkEditBtn:".cb-permalink-edit-btn",elPermalinkOkBtn:".cb-permalink-ok-btn",elPermalinkCancelBtn:".cb-permalink-cancel-btn",elPermalinkSlugInput:".cb-permalink-slug-input",elPermalinkUrl:".cb-permalink-url",elPermalinkBaseUrl:"#cb-permalink-base-url",elPermalinkRoot:".cb-item-edit-permalink, .cb-course-edit-permalink",elPermalinkPlaceholder:".cb-item-edit-permalink__placeholder",elCBHorizontalTabs:".lp-cb-tabs__item",elCBTabPanels:".lp-cb-tab-panel",elDropdownToggle:".cb-btn-dropdown-toggle",elDropdownMenu:".cb-dropdown-menu",elHeaderActionsDropdown:".cb-header-actions-dropdown"};init(){this.initTabs(),this.initHeaderActionsDropdown(),this.events()}initHeaderActionsDropdown(){document.addEventListener("click",e=>{const t=document.querySelector(H.selectors.elHeaderActionsDropdown);if(t&&!t.contains(e.target)){const e=t.querySelector(H.selectors.elDropdownMenu),s=t.querySelector(H.selectors.elDropdownToggle);e&&e.classList.remove("is-open"),s&&s.setAttribute("aria-expanded","false")}})}handleDropdownToggle(e){const{target:t}=e,s=t.closest(H.selectors.elDropdownToggle);if(!s)return;const i=s.closest(H.selectors.elHeaderActionsDropdown);if(!i)return;const n=i.querySelector(H.selectors.elDropdownMenu);if(n){n.classList.toggle("is-open");const e=n.classList.contains("is-open");s.setAttribute("aria-expanded",e?"true":"false")}}initTabs(){const e=document.querySelectorAll(H.selectors.elCBHorizontalTabs);if(0!==e.length&&!document.querySelector(`${H.selectors.elCBHorizontalTabs}.is-active`)&&e.length>0){e[0].classList.add("is-active");const t=e[0].getAttribute("data-tab-section");if(t){const e=document.querySelector(`${H.selectors.elCBTabPanels}[data-section="${t}"]`);e&&e.classList.remove("lp-hidden")}}}handleTabClick(e){const{e:t,target:s}=e,i=s.closest(H.selectors.elCBHorizontalTabs);if(!i)return;t.preventDefault();const n=i.getAttribute("data-tab-section");n&&(document.querySelectorAll(H.selectors.elCBHorizontalTabs).forEach(e=>e.classList.remove("is-active")),i.classList.add("is-active"),document.querySelectorAll(H.selectors.elCBTabPanels).forEach(e=>{e.getAttribute("data-section")===n?e.classList.remove("lp-hidden"):e.classList.add("lp-hidden")}))}events(){H._loadedEvents||(H._loadedEvents=!0,e.eventHandlers("click",[{selector:H.selectors.elBtnMainAction,class:this,callBack:this.updateLesson.name},{selector:H.selectors.elBtnDraft,class:this,callBack:this.saveDraftLesson.name},{selector:H.selectors.elBtnTrash,class:this,callBack:this.trashLesson.name},{selector:H.selectors.elCBHorizontalTabs,class:this,callBack:this.handleTabClick.name},{selector:H.selectors.elDropdownToggle,class:this,callBack:this.handleDropdownToggle.name},{selector:H.selectors.elPermalinkEditBtn,class:this,callBack:this.handlePermalinkEdit.name},{selector:H.selectors.elPermalinkOkBtn,class:this,callBack:this.handlePermalinkOk.name},{selector:H.selectors.elPermalinkCancelBtn,class:this,callBack:this.handlePermalinkCancel.name}]))}validateTitleBeforeUpdate(){const e=document.getElementById(H.selectors.idTitle);return!e||(!!e.value.trim()||(n.W("Lesson title is required.","error"),e.focus(),!1))}updateActionButtons(e){const t=document.querySelector(H.selectors.elBtnMainAction);if(!t)return;const s=t.getAttribute("data-title-update")||"Update",i=t.getAttribute("data-title-publish")||"Publish";t.textContent="publish"===e?s:i}isLessonContext(){return!!document.querySelector(H.selectors.elDataLesson)}slugify(e){return(e||"").toString().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"D").toLowerCase().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,"")}buildPermalinkDisplayUrl(e="",t="",s=""){const i="string"==typeof e?e:"",n="string"==typeof t?t.trim():"";return i&&n?`${i}${n}`:"string"==typeof s?s:""}getPermalinkRoot(e=null){if(e?.closest){const t=e.closest(H.selectors.elPermalinkRoot);if(t)return t}return document.querySelector(`.cb-section__lesson-edit ${H.selectors.elPermalinkRoot}`)}isDescriptionEditorInCodeMode(){const e=H.selectors.idDescEditor,t=document.getElementById(`wp-${e}-wrap`)||document.getElementById(`${e}-wrap`);if(t?.classList.contains("html-active"))return!0;const s="undefined"!=typeof tinymce?tinymce.get(e):null;return!(!s?.isHidden||!s.isHidden())}getDescriptionContentForUpdate(){const e=H.selectors.idDescEditor,t=document.getElementById(e);if(this.isDescriptionEditorInCodeMode())return t?t.value:"";if("undefined"!=typeof tinymce){const t=tinymce.get(e);if(t)return t.getContent()}return t?t.value:""}showPermalinkUnavailable(e,t=""){if(!e)return;const s=e.querySelector(".cb-item-edit-permalink__label")||e.querySelector(".cb-permalink-label"),i=e.querySelector(H.selectors.elPermalinkDisplay),n=e.querySelector(H.selectors.elPermalinkEditor);let o=e.querySelector(H.selectors.elPermalinkPlaceholder);o||(o=document.createElement("span"),o.className="cb-item-edit-permalink__placeholder",s?s.insertAdjacentElement("afterend",o):e.prepend(o)),o.textContent=t||"Permalink is only available if the item is already assigned to a course.",o.classList.remove("lp-hidden"),i&&i.classList.add("lp-hidden"),n&&n.classList.add("lp-hidden")}getLessonDataForUpdate(){const e={},t=document.querySelector(H.selectors.elDataLesson);e.lesson_id=t&&parseInt(t.dataset.lessonId)||0;const s=document.getElementById(H.selectors.idTitle);e.lesson_title=s?s.value:"",e.lesson_description=this.getDescriptionContentForUpdate();const i=document.querySelector(`input[name="lesson_permalink"], #lesson_permalink, ${H.selectors.elPermalinkSlugInput}`);i&&i.value&&(e.lesson_permalink=i.value);const n=document.querySelector(H.selectors.elFormSetting);return n&&(e.lesson_settings=!0,n.querySelectorAll("input, select, textarea").forEach(t=>{const s=t.name||t.id;if(s&&"learnpress_meta_box_nonce"!==s&&"_wp_http_referer"!==s)if("checkbox"===t.type){const i=s.replace("[]","");e.hasOwnProperty(i)||(e[i]=t.checked?"yes":"no")}else if("radio"===t.type){if(t.checked){const i=s.replace("[]","");e[i]=t.value}}else if("file"===t.type){const i=s.replace("[]","");t.files&&t.files.length>0&&(e[i]=t.files)}else{const i=s.replace("[]","");s.endsWith("[]")?(e.hasOwnProperty(i)||(e[i]=[]),Array.isArray(e[i])&&e[i].push(t.value)):e.hasOwnProperty(i)||(e[i]=t.value)}}),Object.keys(e).forEach(t=>{Array.isArray(e[t])&&(e[t]=e[t].join(","))})),e}updatePermalinkUIAfterSave(e={}){const t=this.getPermalinkRoot();if(!t)return;const s=t.querySelector(H.selectors.elPermalinkSlugInput),i=t.querySelector(H.selectors.elPermalinkUrl),n=t.querySelector(H.selectors.elPermalinkBaseUrl),o=t.querySelector(H.selectors.elPermalinkDisplay),a=t.querySelector(H.selectors.elPermalinkPlaceholder),r=this.buildPermalinkDisplayUrl(n?n.value:"",e?.lesson_slug,e?.lesson_permalink);s&&e?.lesson_slug&&(s.value=e.lesson_slug,s.dataset.originalValue=e.lesson_slug),!1!==e?.permalink_available&&"draft"!==e?.status&&"trash"!==e?.status&&e?.lesson_permalink?(a&&a.classList.add("lp-hidden"),o&&o.classList.remove("lp-hidden"),i&&e?.lesson_permalink?(i.href=e.lesson_permalink,i.textContent=r||e.lesson_permalink):i&&r&&(i.textContent=r)):this.showPermalinkUnavailable(t,e?.permalink_notice)}handlePermalinkEdit(e){if(!this.isLessonContext())return;const{e:t,target:s}=e;t&&t.preventDefault();const i=s?.closest(H.selectors.elPermalinkEditBtn),n=i?.closest(H.selectors.elDataLesson)||document.querySelector(H.selectors.elDataLesson);if(!n)return;const o=n.querySelector(H.selectors.elPermalinkDisplay),a=n.querySelector(H.selectors.elPermalinkEditor),r=n.querySelector(H.selectors.elPermalinkSlugInput);o&&a&&r&&(r.dataset.originalValue=r.value,o.classList.add("lp-hidden"),a.classList.remove("lp-hidden"),r.focus(),r.select())}handlePermalinkOk(e){if(!this.isLessonContext())return;const{e:t,target:s}=e;t&&t.preventDefault();const i=s?.closest(H.selectors.elPermalinkOkBtn),n=i?.closest(H.selectors.elDataLesson)||document.querySelector(H.selectors.elDataLesson);if(!n)return;const o=n.querySelector(H.selectors.elPermalinkDisplay),a=n.querySelector(H.selectors.elPermalinkEditor),r=n.querySelector(H.selectors.elPermalinkSlugInput),l=n.querySelector(H.selectors.elPermalinkUrl),c=n.querySelector(H.selectors.elPermalinkBaseUrl);if(!(o&&a&&r&&l))return;let d=this.slugify(r.value.trim());d||(d=r.dataset.originalValue||"lesson"),r.value=d;const u=c?c.value:"",h=this.buildPermalinkDisplayUrl(u,d,l.textContent||"");l.textContent=h,a.classList.add("lp-hidden"),o.classList.remove("lp-hidden")}handlePermalinkCancel(e){if(!this.isLessonContext())return;const{e:t,target:s}=e;t&&t.preventDefault();const i=s?.closest(H.selectors.elPermalinkCancelBtn),n=i?.closest(H.selectors.elDataLesson)||document.querySelector(H.selectors.elDataLesson);if(!n)return;const o=n.querySelector(H.selectors.elPermalinkDisplay),a=n.querySelector(H.selectors.elPermalinkEditor),r=n.querySelector(H.selectors.elPermalinkSlugInput);o&&a&&r&&(r.value=r.dataset.originalValue||"",a.classList.add("lp-hidden"),o.classList.remove("lp-hidden"))}updateLesson(t){if(!this.isLessonContext())return;const{target:s}=t,i=s.closest(H.selectors.elBtnMainAction);if(!i)return;if(!this.validateTitleBeforeUpdate())return;e.lpSetLoadingEl(i,1);const o=this.getLessonDataForUpdate(),a=i.dataset.status||"publish",r={...o,action:"builder_update_lesson",args:{id_url:"builder-update-lesson"},lesson_status:a};"undefined"!=typeof lpLessonBuilder&&lpLessonBuilder.nonce&&(r.nonce=lpLessonBuilder.nonce);const l={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),"success"===t){if(this.updateActionButtons(a),i?.lesson_id_new){const e=window.location.href;window.location.href=e.replace(/post-new\/?/,`${i.lesson_id_new}/`)}if(i?.status){const e=document.querySelector(H.selectors.elLessonStatus);if(e&&(e.className="lesson-status "+i.status,e.textContent=i.status),"trash"===i.status||"draft"===i.status){const e=document.querySelector(`.lesson-item[data-lesson-id="${o.lesson_id}"]`);if(e){const t=e.closest(".lesson");t&&t.remove()}}}this.updatePermalinkUIAfterSave(i),document.dispatchEvent(new CustomEvent("lp-course-builder-saved"))}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(i,0)}};window.lpAJAXG.fetchAJAX(r,l)}saveDraftLesson(t){if(!this.isLessonContext())return;const{target:s}=t,i=s.closest(H.selectors.elBtnDraft);if(!i)return;const o=document.querySelector(H.selectors.elLessonStatus);if(o&&o.classList.contains("publish")){const e=i.dataset.confirmUnpublish||"Saving as draft will unpublish this item. Are you sure?";if(!confirm(e))return}if(!this.validateTitleBeforeUpdate())return;e.lpSetLoadingEl(i,1);const a=this.getLessonDataForUpdate(),r={...a,action:"builder_update_lesson",args:{id_url:"builder-update-lesson"},lesson_status:"draft"};"undefined"!=typeof lpLessonBuilder&&lpLessonBuilder.nonce&&(r.nonce=lpLessonBuilder.nonce);const l={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),"success"===t){if(this.updateActionButtons("draft"),i?.lesson_id_new){const e=window.location.href;window.location.href=e.replace(/post-new\/?/,`${i.lesson_id_new}/`)}if(i?.status){const e=document.querySelector(H.selectors.elLessonStatus);if(e&&(e.className="lesson-status "+i.status,e.textContent=i.status),"trash"===i.status||"draft"===i.status){const e=document.querySelector(`.lesson-item[data-lesson-id="${a.lesson_id}"]`);if(e){const t=e.closest(".lesson");t&&t.remove()}}}this.updatePermalinkUIAfterSave(i),document.dispatchEvent(new CustomEvent("lp-course-builder-saved"))}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(i,0)}};window.lpAJAXG.fetchAJAX(r,l)}trashLesson(t){if(!this.isLessonContext())return;const{target:s}=t,i=s.closest(H.selectors.elBtnTrash);if(!i)return;if(!confirm("Are you sure you want to trash this lesson?"))return;e.lpSetLoadingEl(i,1);const o=this.getLessonDataForUpdate(),a={action:"move_trash_lesson",args:{id_url:"move-trash-lesson"},lesson_id:o.lesson_id},r={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),"success"===t){if(i?.redirect_url&&(window.location.href=i.redirect_url),i?.status){const e=document.querySelector(H.selectors.elLessonStatus);if(e&&(e.className="lesson-status "+i.status,e.textContent=i.status),"trash"===i.status||"draft"===i.status){const e=document.querySelector(`.lesson-item[data-lesson-id="${o.lesson_id}"]`);if(e){const t=e.closest(".lesson");t&&t.remove()}}}this.updatePermalinkUIAfterSave(i)}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(i,0)}};window.lpAJAXG.fetchAJAX(a,r)}}class Q{constructor(){this.init()}static selectors={elQuizItem:".quiz-item",elQuizExpandedItems:".quiz-action-expanded__items",elQuizDuplicate:".quiz-action-expanded__duplicate",elQuizTrash:".quiz-action-expanded__trash",elQuizRestore:".quiz-action-expanded__restore",elQuizPublish:".quiz-action-expanded__publish",elQuizDelete:".quiz-action-expanded__delete",elQuizActionExpanded:".quiz-action-expanded",elQuizStatus:".quiz-status",elBtnEditQuiz:".btn-edit-quiz"};init(){this.events()}events(){Q._loadedEvents||(Q._loadedEvents=!0,e.eventHandlers("click",[{selector:Q.selectors.elQuizDuplicate,class:this,callBack:this.duplicateQuiz.name},{selector:Q.selectors.elQuizTrash,class:this,callBack:this.trashQuiz.name},{selector:Q.selectors.elQuizPublish,class:this,callBack:this.publishQuiz.name},{selector:Q.selectors.elQuizRestore,class:this,callBack:this.restoreQuiz.name},{selector:Q.selectors.elQuizDelete,class:this,callBack:this.deleteQuiz.name},{selector:Q.selectors.elQuizActionExpanded,class:this,callBack:this.toggleExpandedAction.name},{selector:Q.selectors.elBtnEditQuiz,class:this,callBack:this.editQuiz.name}]),document.addEventListener("click",e=>{e.target.closest(Q.selectors.elQuizActionExpanded)||this.closeAllExpanded()}))}editQuiz(t){const{target:s}=t,i=s.closest(Q.selectors.elBtnEditQuiz);i&&e.lpSetLoadingEl(i,1)}duplicateQuiz(t){const{target:s}=t,o=s.closest(Q.selectors.elQuizDuplicate),r=o.closest(Q.selectors.elQuizItem);if(!r)return;const l=r.querySelector(Q.selectors.elQuizActionExpanded),c=r.dataset.quizId||"";i().fire({title:o.dataset.title||"Duplicate Quiz",text:o.dataset.content||"Are you sure you want to duplicate this quiz?",iconHtml:a,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(l,1);const t={action:"duplicate_quiz",args:{id_url:"duplicate-quiz"},quiz_id:c},s={success:e=>{const{status:t,message:s,data:i}=e;n.W(s||"Duplicated successfully!",t),"success"===t&&i?.redirect_url&&(window.location.href=i.redirect_url)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(l,0)}};window.lpAJAXG.fetchAJAX(t,s)}})}trashQuiz(t){const{target:s}=t,a=s.closest(Q.selectors.elQuizTrash),r=a.closest(Q.selectors.elQuizItem);if(!r)return;const l=r.querySelector(Q.selectors.elQuizActionExpanded),c=r.dataset.quizId||"";i().fire({title:a.dataset.title||"Trash Quiz",text:a.dataset.content||"Are you sure you want to move this quiz to trash?",iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(l,1);const t={action:"move_trash_quiz",args:{id_url:"move-trash-quiz"},quiz_id:c},s={success:e=>{const{status:t,message:s,data:i}=e;n.W(s,t),i?.html&&this.replaceItemHtml(a.closest(".quiz"),i.html)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(l,0)}};window.lpAJAXG.fetchAJAX(t,s)}})}publishQuiz(t){const{target:s}=t,i=s.closest(Q.selectors.elQuizPublish),o=i.closest(Q.selectors.elQuizItem);if(!o)return;const a=o.querySelector(Q.selectors.elQuizActionExpanded);e.lpSetLoadingEl(a,1);const r={action:"move_trash_quiz",args:{id_url:"move-trash-quiz"},quiz_id:o.dataset.quizId||"",status:"publish"},l={success:e=>{const{status:t,message:s,data:o}=e;n.W(s,t),o?.html&&this.replaceItemHtml(i.closest(".quiz"),o.html)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(r,l)}restoreQuiz(t){const{target:s}=t,i=s.closest(Q.selectors.elQuizRestore),o=i.closest(Q.selectors.elQuizItem);if(!o)return;const a=o.querySelector(Q.selectors.elQuizActionExpanded);e.lpSetLoadingEl(a,1);const r={action:"move_trash_quiz",args:{id_url:"move-trash-quiz"},quiz_id:o.dataset.quizId||"",status:"draft"},l={success:e=>{const{status:t,message:s,data:o}=e;n.W(s,t),o?.html&&this.replaceItemHtml(i.closest(".quiz"),o.html)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(r,l)}deleteQuiz(t){const{target:s}=t,o=s.closest(Q.selectors.elQuizDelete),a=o.closest(Q.selectors.elQuizItem);if(!a)return;const l=a.querySelector(Q.selectors.elQuizActionExpanded),c=a.dataset.quizId||"";c&&i().fire({title:o.dataset.title||"Delete Quiz",text:o.dataset.content||"Are you sure you want to permanently delete this quiz?",iconHtml:r,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(l,1);const t={action:"move_trash_quiz",args:{id_url:"move-trash-quiz"},quiz_id:c,status:"delete"},s={success:e=>{const{status:t,message:s}=e;if(n.W(s,t),"success"===t){const e=o.closest(".quiz");e.style.transition="opacity 0.4s ease-out, transform 0.4s ease-out",e.style.opacity="0",e.style.transform="translateX(160px)",setTimeout(()=>{e.remove()},400)}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(l,0)}};window.lpAJAXG.fetchAJAX(t,s)}})}toggleExpandedAction(e){const{target:t}=e,s=t.closest(Q.selectors.elQuizActionExpanded);if(!s)return;const i=s.closest(Q.selectors.elQuizItem);if(!i)return;const n=i.querySelector(Q.selectors.elQuizExpandedItems);n&&(this.closeAllExpanded(n),n.classList.contains("active")?(n.classList.remove("active"),n.classList.remove("is-dropup"),s.classList.remove("active")):(n.classList.add("active"),s.classList.add("active"),this.setExpandedDirection(n)))}closeAllExpanded(e=null){document.querySelectorAll(`${Q.selectors.elQuizExpandedItems}.active`).forEach(t=>{if(t===e)return;t.classList.remove("active"),t.classList.remove("is-dropup");const s=t.closest(Q.selectors.elQuizItem);if(!s)return;const i=s.querySelector(Q.selectors.elQuizActionExpanded);i&&i.classList.remove("active")})}setExpandedDirection(e){if(!e)return;e.classList.remove("is-dropup");const t=e.closest(".quiz");t&&t.matches(":last-child")&&e.classList.add("is-dropup")}replaceItemHtml(e,t){if(!e||!t)return;const s=document.createElement("div");s.innerHTML=t;const i=s.firstElementChild;i&&e.replaceWith(i)}}var N=s(345);class R{constructor(){this.elEditQuizWrap=null,this.elEditListQuestions=null,this.quizID=null,this.lpPopupSelectItemToAdd=null,this.sortableInstance=null,this.sortableAnswerInstances=[],this.editQuestion=null,this.initPromise=null,this.tinyMCEInitToken=null,this.isInitialized=!1}static selectors={elEditQuizWrap:".lp-edit-quiz-wrap",elQuestionEditMain:".lp-question-edit-main",elEditListQuestions:".lp-edit-list-questions",elQuestionItem:".lp-question-item",elQuestionToggle:".lp-question-toggle",elQuestionToggleAll:".lp-question-toggle-all",elBtnAddQuestion:".lp-btn-add-question",elBtnRemoveQuestion:".lp-btn-remove-question",elBtnUpdateQuestionTitle:".lp-btn-update-question-title",elBtnCancelUpdateQuestionTitle:".lp-btn-cancel-update-question-title",elQuestionTitleNewInput:".lp-question-title-new-input",elQuestionTitleInput:".lp-question-title-input",elQuestionTypeNew:".lp-question-type-new",elAddNewQuestion:"add-new-question",LPTarget:".lp-target",elCollapse:"lp-collapse",elAnswersConfig:".lp-answers-config",elQuestionTinymce:".lp-question-edit-main .lp-editor-tinymce"};init(e=null){this.initQuizQuestionsTab(e),this.events()}reinit(e=null){this.cleanup(),this.events(),this.initQuizQuestionsTabAsync(e).catch(e=>{console.debug("BuilderEditQuiz: Quiz questions tab not found",e.message)})}cleanup(){if(this.initPromise&&"object"==typeof this.initPromise&&(this.initPromise.cancelled=!0),this.initPromise=null,this.tinyMCEInitToken=null,this.elEditQuizWrap=null,this.elEditListQuestions=null,this.quizID=null,this.isInitialized=!1,this.sortableInstance?.destroy){try{this.sortableInstance.destroy()}catch(e){console.warn("Error destroying sortable instance:",e)}this.sortableInstance=null}this.sortableAnswerInstances.forEach(e=>{if(e?.destroy)try{e.destroy()}catch(e){console.warn("Error destroying answer sortable:",e)}}),this.sortableAnswerInstances=[]}initQuizQuestionsTab(e=null){const t=(e||document).querySelector(R.selectors.elEditQuizWrap);t&&this._initQuizQuestionsTabElement(t)}initQuizQuestionsTabAsync(e=null,t=50,s=200){return this.initPromise&&"object"==typeof this.initPromise&&(this.initPromise.cancelled=!0),this.initPromise=new Promise((i,n)=>{let o=0;const a=e||document,r=()=>{if(this.initPromise&&this.initPromise.cancelled)return void n(new Error("Init cancelled"));o++;const e=a.querySelector(R.selectors.elEditQuizWrap);e?(this._initQuizQuestionsTabElement(e),i(e)):o>=t?n(new Error(`Quiz questions tab not found after ${t} attempts`)):setTimeout(r,s)};r()}),this.initPromise.cancelled=!1,this.initPromise}_initQuizQuestionsTabElement(e){e&&(this.isInitialized&&this.elEditQuizWrap===e||(this.elEditQuizWrap=e,this.elEditListQuestions=e.querySelector(R.selectors.elEditListQuestions),this._getQuizID(e),this.lpPopupSelectItemToAdd||(this.lpPopupSelectItemToAdd=new p,this.lpPopupSelectItemToAdd.init()),this.sortAbleQuestion(),this._initAnswerSortables(e),this._initEditQuestion(e),this._initTinyMCEAsync(e),this.isInitialized=!0))}_getQuizID(e){const t=e.closest(R.selectors.LPTarget);if(t&&window.lpAJAXG)try{const e=window.lpAJAXG.getDataSetCurrent(t);this.quizID=e?.args?.quiz_id||0}catch(e){console.warn("Error getting quiz ID from lpAJAXG:",e)}if(!this.quizID){const t=e.closest(".lp-builder-popup");this.quizID=t?.dataset.quizId||0}if(!this.quizID){const t=e.closest("[data-quiz-id]");this.quizID=t?.dataset.quizId||0}}_initEditQuestion(e){if(e&&(this.editQuestion||(this.editQuestion=new N.f),e.querySelectorAll(R.selectors.elQuestionEditMain).forEach(e=>{if(e&&this.editQuestion?.sortAbleQuestionAnswer)try{this.editQuestion.sortAbleQuestionAnswer(e)}catch(e){console.warn("Error initializing answer sortable:",e)}}),!N.f._loadedEvents&&this.editQuestion?.events))try{this.editQuestion.events()}catch(e){console.warn("Error registering EditQuestion events:",e)}}_initAnswerSortables(e){e&&e.querySelectorAll(R.selectors.elQuestionEditMain).forEach(e=>{e&&this._sortAbleQuestionAnswer(e)})}_sortAbleQuestionAnswer(e){if(!e)return;const t=e.querySelector(R.selectors.elAnswersConfig);if(t)try{const e=new c.Ay(t,{handle:".drag",animation:150,onEnd:e=>{if(!e?.item)return;const t=e.item.querySelector(".lp-auto-save-question-answer");t&&t.dispatchEvent(new Event("change",{bubbles:!0}))}});this.sortableAnswerInstances.push(e)}catch(e){console.warn("Error creating answer sortable:",e)}}_initTinyMCEAsync(e){if(!e)return;const t=Array.from(e.querySelectorAll(`${R.selectors.elQuestionItem}:not(.${R.selectors.elCollapse}) ${R.selectors.elQuestionTinymce}`));if(!t.length)return;let s=0;const i={};this.tinyMCEInitToken=i;const n=e=>{window.requestIdleCallback?window.requestIdleCallback(()=>e(),{timeout:100}):setTimeout(()=>e(),50)},o=(e=0)=>{this.tinyMCEInitToken===i&&(void 0!==window.tinymce?(t.slice(s,s+2).forEach(e=>{e?.id&&this._reInitTinymce(e.id)}),s+=2,s<t.length&&n(o)):e<20&&setTimeout(()=>o(e+1),100))};n(o)}_reInitTinymce(e){if(!window.tinymce||!e)return;const t=document.getElementById(e);if(t?.closest(".lp-question-edit-main"))if(this.editQuestion?.reInitTinymce)try{this.editQuestion.reInitTinymce(e)}catch(t){console.warn("TinyMCE reinit via EditQuestion error:",t),this._manualReInitTinymce(e)}else this._manualReInitTinymce(e)}_manualReInitTinymce(e){try{window.tinymce.execCommand("mceRemoveEditor",!0,e),window.tinymce.execCommand("mceAddEditor",!0,e),this.editQuestion?.setDefaultEditorTab?.(e)}catch(e){console.warn("Manual TinyMCE init error:",e)}}reinitQuestionHandlers(e){if(e&&(this._sortAbleQuestionAnswer(e),this._initQuestionTinymce(e.closest(R.selectors.elQuestionItem)),this.editQuestion?.sortAbleQuestionAnswer))try{this.editQuestion.sortAbleQuestionAnswer(e)}catch(e){console.warn("Error initializing answer sortable:",e)}}_initQuestionTinymce(e){e&&!e.classList.contains(R.selectors.elCollapse)&&e.querySelectorAll(R.selectors.elQuestionTinymce).forEach(e=>{e?.id&&this._reInitTinymce(e.id)})}events(){R._loadedEvents||(R._loadedEvents=!0,e.eventHandlers("click",[{selector:R.selectors.elQuestionToggleAll,class:this,callBack:this.toggleQuestionAll.name},{selector:R.selectors.elBtnAddQuestion,class:this,callBack:this.addQuestion.name},{selector:R.selectors.elBtnRemoveQuestion,class:this,callBack:this.removeQuestion.name},{selector:R.selectors.elBtnUpdateQuestionTitle,class:this,callBack:this.updateQuestionTitle.name},{selector:R.selectors.elBtnCancelUpdateQuestionTitle,class:this,callBack:this.cancelChangeTitleQuestion.name},{selector:p.selectors.elBtnShowPopupItemsToSelect,class:this,callBack:this.handleShowPopupQuestionBank.name},{selector:p.selectors.elBtnAddItemsSelected,class:this,callBack:this.handleAddItemsSelected.name}]),e.eventHandlers("keydown",[{selector:R.selectors.elQuestionTitleInput,class:this,callBack:this.updateQuestionTitle.name,checkIsEventEnter:!0},{selector:R.selectors.elQuestionTitleNewInput,class:this,callBack:this.addQuestion.name,checkIsEventEnter:!0}]),e.eventHandlers("keyup",[{selector:R.selectors.elQuestionTitleInput,class:this,callBack:this.changeTitleQuestion.name},{selector:`${R.selectors.elQuestionTitleNewInput}, ${R.selectors.elQuestionTypeNew}`,class:this,callBack:this.checkCanAddQuestion.name}]),e.eventHandlers("change",[{selector:R.selectors.elQuestionTypeNew,class:this,callBack:this.checkCanAddQuestion.name}]),document.addEventListener("click",t=>{const s=t.target;e.toggleCollapse(t,s,R.selectors.elQuestionToggle,[],e=>{this._initQuestionTinymce(e),this.checkAllQuestionsCollapsed()})}))}handleShowPopupQuestionBank(e){const{target:t}=e,s=t.closest(R.selectors.elEditQuizWrap),i=t.closest(".lp-builder-popup");s||i?(R._isQuizPopupContext=!0,s&&(this.elEditQuizWrap=s,this._getQuizID(s),this.elEditListQuestions=s.querySelector(R.selectors.elEditListQuestions))):R._isQuizPopupContext=!1}handleAddItemsSelected(e){const{target:t}=e;if(!R._isQuizPopupContext)return;const s=i().getPopup();if(!s)return;const n=[],o=s.querySelector(".list-items");o&&o.querySelectorAll('input[type="checkbox"]:checked').forEach(e=>{n.push({...e.dataset})});const a=s.querySelector(".list-items-selected");if(a&&a.querySelectorAll(".li-item-selected:not(.clone)").forEach(e=>{const t={...e.dataset};n.some(e=>e.id===t.id)||n.push(t)}),0===n.length){const e=s.querySelector(".lp-target");if(e&&window.lpAJAXG)try{const t=window.lpAJAXG.getDataSetCurrent(e);t?.args?.item_selecting&&Array.isArray(t.args.item_selecting)&&n.push(...t.args.item_selecting)}catch(e){console.warn("Error getting item_selecting:",e)}}0!==n.length?(i().close(),R._isQuizPopupContext=!1,this.addQuestionsSelectedToQuiz(n)):console.warn("BuilderEditQuiz: No items selected")}addQuestionsSelectedToQuiz(t){if(!t||0===t.length)return void console.warn("BuilderEditQuiz: No items to add");if(!this.elEditQuizWrap){const e=document.querySelector(".lp-builder-popup");e&&(this.elEditQuizWrap=e.querySelector(R.selectors.elEditQuizWrap)),this.elEditQuizWrap||(this.elEditQuizWrap=document.querySelector(R.selectors.elEditQuizWrap))}if(!this.elEditQuizWrap)return void console.error("BuilderEditQuiz: elEditQuizWrap not found");if(this.quizID||this._getQuizID(this.elEditQuizWrap),!this.quizID)return void console.error("BuilderEditQuiz: quizID not found");if(this.elEditListQuestions||(this.elEditListQuestions=this.elEditQuizWrap.querySelector(R.selectors.elEditListQuestions)),!this.elEditListQuestions)return void console.error("BuilderEditQuiz: elEditListQuestions not found");const s=[],i=[];if(t.forEach(t=>{const n=this.elEditQuizWrap.querySelector(`${R.selectors.elQuestionItem}.clone`);if(!n)return void console.error("BuilderEditQuiz: Question clone element not found");s.push(t.id);const o=n.cloneNode(!0),a=o.querySelector(R.selectors.elQuestionTitleInput);o.classList.remove("clone"),o.dataset.questionId=t.id;const r=t.title||"";a&&(a.value=r),e.lpSetLoadingEl(o,1),e.lpShowHideEl(o,1),n.insertAdjacentElement("beforebegin",o),i.push(o)}),0===s.length)return void console.warn("BuilderEditQuiz: No questions to add");const o={success:e=>{const{message:t,status:s,data:i}=e;if("success"!==s)throw new Error(t||"Failed to add questions");n.W(t,s);const{html_edit_question:o}=i;if(!o||"object"!=typeof o)throw new Error("Invalid response: missing html_edit_question");Object.entries(o).forEach(([e,t])=>{if(!t)return void console.warn(`Empty HTML for question ${e}`);const s=this.elEditQuizWrap.querySelector(`${R.selectors.elQuestionItem}[data-question-id="${e}"]`);if(!s)return void console.warn(`Placeholder not found for question ${e}`);s.outerHTML=t;const i=this.elEditQuizWrap.querySelector(`${R.selectors.elQuestionItem}[data-question-id="${e}"]`);if(i){const e=i.querySelector(R.selectors.elQuestionEditMain);this.reinitQuestionHandlers(e)}}),this.updateCountItems()},error:e=>{console.error("Error adding questions:",e),i.forEach(e=>{e&&e.parentNode&&e.remove()}),n.W(e?.message||e||"Failed to add questions","error")},completed:()=>{s.forEach(t=>{const s=this.elEditQuizWrap.querySelector(`${R.selectors.elQuestionItem}[data-question-id="${t}"]`);s&&e.lpSetLoadingEl(s,0)})}},a={action:"add_questions_to_quiz",quiz_id:this.quizID,question_ids:s,args:{id_url:"edit-quiz-questions"}};window.lpAJAXG.fetchAJAX(a,o)}toggleQuestionAll(e){const{target:t}=e,s=t.closest(R.selectors.elQuestionToggleAll);if(!s||!this.elEditQuizWrap)return;const i=this.elEditQuizWrap.querySelectorAll(`${R.selectors.elQuestionItem}:not(.clone)`);s.classList.toggle(R.selectors.elCollapse);const n=s.classList.contains(R.selectors.elCollapse);i.forEach(e=>{e&&(e.classList.toggle(R.selectors.elCollapse,n),n||this._initQuestionTinymce(e))})}checkAllQuestionsCollapsed(){if(!this.elEditQuizWrap)return;const e=this.elEditQuizWrap.querySelectorAll(`${R.selectors.elQuestionItem}:not(.clone)`),t=this.elEditQuizWrap.querySelector(R.selectors.elQuestionToggleAll);if(!t)return;const s=Array.from(e).every(e=>e&&!e.classList.contains(R.selectors.elCollapse));t.classList.toggle(R.selectors.elCollapse,!s)}updateCountItems(){if(!this.elEditQuizWrap)return;const e=this.elEditQuizWrap.querySelector(".total-items"),t=this.elEditQuizWrap.querySelectorAll(`${R.selectors.elQuestionItem}:not(.clone)`).length;if(e){e.dataset.count=t;const s=e.querySelector(".count");s&&(s.textContent=t)}}addQuestion(t){const{e:s,target:i,callBackNest:o}=t;s.preventDefault();const a=i.closest(`.${R.selectors.elAddNewQuestion}`);if(!a||!this.elEditListQuestions)return;const r=a.querySelector(R.selectors.elQuestionTitleNewInput),l=r?.value?.trim();if(!l)return void n.W(r?.dataset?.messEmptyTitle||"Title is required","error");const c=a.querySelector(R.selectors.elQuestionTypeNew),d=c?.value;if(!d)return void n.W(c?.dataset?.messEmptyType||"Type is required","error");const u=this.elEditListQuestions.querySelector(`${R.selectors.elQuestionItem}.clone`);if(!u)return void n.W("Question template not found","error");const h=u.cloneNode(!0),p=h.querySelector(R.selectors.elQuestionTitleInput);p&&(p.value=l),r.value="",h.classList.remove("clone"),e.lpShowHideEl(h,1),u.insertAdjacentElement("beforebegin",h),e.lpSetLoadingEl(h,1);const m={success:e=>{const{message:t,status:s,data:i}=e;if("error"===s)throw new Error(t);if("success"===s&&i?.question){const{question:t,html_edit_question:s}=i;h.dataset.questionId=t.ID,h.dataset.questionType=t.meta_data?._lp_type||"",h.outerHTML=s;const n=this.elEditListQuestions.querySelector(`${R.selectors.elQuestionItem}[data-question-id="${t.ID}"]`);if(n){n.classList.remove(R.selectors.elCollapse),this.updateCountItems();const t=n.querySelector(R.selectors.elQuestionEditMain);this.reinitQuestionHandlers(t),o?.success&&o.success({response:e,elQuestionItemCreated:n})}}n.W(t,s)},error:e=>{h.remove(),n.W(e?.message||e||"Failed to add question","error"),o?.error&&o.error({error:e,newQuestionItem:h})},completed:()=>{e.lpSetLoadingEl(h,0),this.checkCanAddQuestion({e:s,target:r}),o?.completed&&o.completed({newQuestionItem:h})}};try{let e=JSON.parse(r.dataset.send||"{}");e={...e,question_title:l,question_type:d},window.lpAJAXG.fetchAJAX(e,m)}catch(s){console.error("Error adding question:",s),h.remove(),n.W("Failed to add question","error")}}checkCanAddQuestion(e){const{target:t}=e,s=t?.closest(R.selectors.elQuestionTitleNewInput)||t?.closest(R.selectors.elQuestionTypeNew);if(!s)return;const i=s.closest(`.${R.selectors.elAddNewQuestion}`),n=i?.querySelector(R.selectors.elBtnAddQuestion);if(!n)return;const o=i.querySelector(R.selectors.elQuestionTitleNewInput),a=i.querySelector(R.selectors.elQuestionTypeNew),r=o?.value?.trim(),l=a?.value;n.classList.toggle("active",!(!r||!l))}removeQuestion(t){const{target:s}=t,o=s.closest(R.selectors.elBtnRemoveQuestion);if(!o)return;const a=o.closest(R.selectors.elQuestionItem);if(!a)return;const r=a.dataset.questionId;if(!r)return;const l=window.lpDataAdmin?.i18n||window.lpData?.i18n||{cancel:"Cancel",yes:"Yes"};i().fire({title:o.dataset.title||"Are you sure?",text:o.dataset.content||"Do you want to remove this question?",icon:"warning",showCloseButton:!0,showCancelButton:!0,cancelButtonText:l.cancel,confirmButtonText:l.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(a,1);const t={success:e=>{const{message:t,status:s}=e;n.W(t,s),"success"===s&&(a.remove(),this.updateCountItems())},error:e=>{n.W(e?.message||e||"Failed to remove question","error")},completed:()=>{e.lpSetLoadingEl(a,0)}},s={quiz_id:this.quizID,action:"remove_question_from_quiz",question_id:r,args:{id_url:"edit-quiz-questions"}};window.lpAJAXG.fetchAJAX(s,t)}})}updateQuestionTitle(t){const{e:s,target:i}=t;if(!(i.closest(R.selectors.elBtnUpdateQuestionTitle)||i.closest(R.selectors.elQuestionTitleInput)&&"Enter"===s.key))return;s.preventDefault();const o=i.closest(R.selectors.elQuestionItem),a=o?.querySelector(R.selectors.elQuestionTitleInput);if(!a)return;const r=o.dataset.questionId,l=a.value.trim(),c=a.dataset.old;if(!l)return void n.W(a.dataset.messEmptyTitle||"Title is required","error");if(l===c)return;a.blur(),e.lpSetLoadingEl(o,1);const d={success:e=>{const{message:t,status:s}=e;"success"===s?a.dataset.old=l:a.value=c,n.W(t,s)},error:e=>{n.W(e?.message||e||"Failed to update title","error")},completed:()=>{e.lpSetLoadingEl(o,0),o.classList.remove("editing")}},u={quiz_id:this.quizID,action:"update_question",question_id:r,question_title:l,args:{id_url:"edit-quiz-questions"}};window.lpAJAXG.fetchAJAX(u,d)}changeTitleQuestion(e){const{target:t}=e,s=t.closest(R.selectors.elQuestionTitleInput);if(!s)return;const i=s.closest(R.selectors.elQuestionItem);if(!i)return;const n=s.value.trim(),o=s.dataset.old||"";i.classList.toggle("editing",n!==o)}cancelChangeTitleQuestion(e){const{target:t}=e,s=t.closest(R.selectors.elBtnCancelUpdateQuestionTitle);if(!s)return;const i=s.closest(R.selectors.elQuestionItem);if(!i)return;const n=i.querySelector(R.selectors.elQuestionTitleInput);n&&(n.value=n.dataset.old||""),i.classList.remove("editing")}sortAbleQuestion(){if(!this.elEditListQuestions)return;if(this.sortableInstance?.destroy){try{this.sortableInstance.destroy()}catch(e){console.warn("Error destroying sortable:",e)}this.sortableInstance=null}let t,s=0;try{this.sortableInstance=new c.Ay(this.elEditListQuestions,{handle:".drag",animation:150,onEnd:i=>{const o=i.item;s&&(clearTimeout(t),t=setTimeout(()=>{e.lpSetLoadingEl(o,1);const t=[];this.elEditListQuestions.querySelectorAll(`${R.selectors.elQuestionItem}:not(.clone)`).forEach(e=>{const s=e?.dataset?.questionId;s&&t.push(s)});const i={success:e=>{const{message:t,status:s}=e;if("success"!==s)throw new Error(t);n.W(t,s)},error:e=>{n.W(e?.message||e||"Failed to update order","error")},completed:()=>{e.lpSetLoadingEl(o,0),s=0}},a={quiz_id:this.quizID,action:"update_questions_position",question_ids:t,args:{id_url:"edit-quiz-questions"}};window.lpAJAXG.fetchAJAX(a,i)},1e3))},onMove:()=>{clearTimeout(t)},onUpdate:()=>{s=1}})}catch(e){console.error("Error creating sortable:",e)}}}class W{constructor(){this.builderEditQuiz=null,this.init()}static selectors={elDataQuiz:".cb-section__quiz-edit",elBtnMainAction:".cb-btn-main-action",elBtnUpdate:".cb-btn-update, .cb-btn-publish",elBtnDraft:'.cb-btn-darft, .cb-dropdown-item[data-status="draft"]',elBtnDuplicate:".cb-btn-duplicate-quiz",elBtnTrash:".cb-btn-trash",elQuizStatus:".quiz-status, .quizze-status",idTitle:"title",idDescEditor:"quiz_description_editor",elPublishStatusSelect:"#cb-quiz-publish-status",elFormSetting:".lp-form-setting-quiz",elPermalinkDisplay:".cb-permalink-display",elPermalinkEditor:".cb-permalink-editor",elPermalinkEditBtn:".cb-permalink-edit-btn",elPermalinkOkBtn:".cb-permalink-ok-btn",elPermalinkCancelBtn:".cb-permalink-cancel-btn",elPermalinkSlugInput:".cb-permalink-slug-input",elPermalinkUrl:".cb-permalink-url",elPermalinkBaseUrl:"#cb-permalink-base-url",elPermalinkRoot:".cb-item-edit-permalink, .cb-course-edit-permalink",elPermalinkPlaceholder:".cb-item-edit-permalink__placeholder",elCBHorizontalTabs:".lp-cb-tabs__item",elCBTabPanels:".lp-cb-tab-panel",elDropdownToggle:".cb-btn-dropdown-toggle",elDropdownMenu:".cb-dropdown-menu",elDropdownItem:".cb-dropdown-item",elHeaderActionsDropdown:".cb-header-actions-dropdown",elQuizActionExpanded:".course-action-expanded"};init(){this.initTabs(),this.initHeaderActionsDropdown(),this.initQuestionTabHandler(),this.syncHeaderActionWithPublishPanel(),this.events()}initQuestionTabHandler(){this.isQuizContext()&&"undefined"!=typeof wp&&wp.hooks&&wp.hooks.addAction("lp-ajax-completed","lp-course-builder",(e,t)=>{t?.callback?.method&&"render_edit_quiz"===t.callback.method&&this.initBuilderEditQuiz(e)})}initBuilderEditQuiz(e=null){this.builderEditQuiz||(this.builderEditQuiz=new R),this.builderEditQuiz.reinit(e)}initHeaderActionsDropdown(){document.addEventListener("click",e=>{const t=document.querySelector(W.selectors.elHeaderActionsDropdown);if(t&&!t.contains(e.target)){const e=t.querySelector(W.selectors.elDropdownMenu),s=t.querySelector(W.selectors.elDropdownToggle);e&&e.classList.remove("is-open"),s&&s.setAttribute("aria-expanded","false")}})}handleDropdownToggle(e){if(this.hasPublishDrivenSingleAction())return;const{target:t}=e,s=t.closest(W.selectors.elDropdownToggle);if(!s)return;const i=s.closest(W.selectors.elHeaderActionsDropdown);if(!i)return;const n=i.querySelector(W.selectors.elDropdownMenu);if(n){n.classList.toggle("is-open");const e=n.classList.contains("is-open");s.setAttribute("aria-expanded",e?"true":"false")}}handleDropdownItemClick(e){if(!this.isQuizContext())return;if(this.hasPublishDrivenSingleAction())return;const{target:t}=e,s=t.closest(W.selectors.elDropdownItem);if(!s)return;if(s.classList.contains("cb-btn-trash")||s.classList.contains("cb-btn-duplicate-quiz"))return;const i=s.dataset.status;if(!i)return;const n=s.closest(W.selectors.elDropdownMenu);n&&n.classList.remove("is-open"),this.saveQuizWithStatus(s,i)}async saveQuizWithStatus(t,s){if(!await this.confirmUnpublishIfNeeded(s,t))return;if(!this.validateTitleBeforeUpdate())return;e.lpSetLoadingEl(t,1);const i={...this.getQuizDataForUpdate(),action:"builder_update_quiz",args:{id_url:"builder-update-quiz"},quiz_status:s},o={success:e=>{const{status:t,message:i,data:o}=e;if(n.W(i,t),"success"===t){if(this.updateActionButtons(o?.status||s),this.syncPublishPanelStatus(o?.status||s),document.dispatchEvent(new CustomEvent("lp-course-builder-saved")),o?.quiz_id_new){const e=window.location.href;window.location.href=e.replace(/post-new\/?/,`${o.quiz_id_new}/`)}if(o?.status){const e=document.querySelector(W.selectors.elQuizStatus);e&&(e.className="quizze-status "+o.status,e.textContent=o.status)}this.updatePermalinkUIAfterSave(o)}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(t,0)}};window.lpAJAXG.fetchAJAX(i,o)}initTabs(){const e=document.querySelectorAll(W.selectors.elCBHorizontalTabs);if(0!==e.length&&!document.querySelector(`${W.selectors.elCBHorizontalTabs}.is-active`)&&e.length>0){e[0].classList.add("is-active");const t=e[0].getAttribute("data-tab-section");if(t){const e=document.querySelector(`${W.selectors.elCBTabPanels}[data-section="${t}"]`);e&&e.classList.remove("lp-hidden")}}}handleTabClick(e){const{e:t,target:s}=e,i=s.closest(W.selectors.elCBHorizontalTabs);if(!i)return;t.preventDefault();const n=i.getAttribute("data-tab-section");if(!n)return;document.querySelectorAll(W.selectors.elCBHorizontalTabs).forEach(e=>e.classList.remove("is-active")),i.classList.add("is-active");const o=new URL(window.location.href);o.searchParams.set("tab",n),window.history.replaceState({},"",o),document.querySelectorAll(W.selectors.elCBTabPanels).forEach(e=>{e.getAttribute("data-section")===n?e.classList.remove("lp-hidden"):e.classList.add("lp-hidden")})}events(){W._loadedEvents||(W._loadedEvents=!0,e.eventHandlers("click",[{selector:W.selectors.elBtnMainAction,class:this,callBack:this.updateQuiz.name},{selector:W.selectors.elBtnDuplicate,class:this,callBack:this.duplicateQuiz.name},{selector:W.selectors.elBtnTrash,class:this,callBack:this.trashQuiz.name},{selector:W.selectors.elCBHorizontalTabs,class:this,callBack:this.handleTabClick.name},{selector:W.selectors.elDropdownToggle,class:this,callBack:this.handleDropdownToggle.name},{selector:W.selectors.elDropdownItem,class:this,callBack:this.handleDropdownItemClick.name},{selector:W.selectors.elPermalinkEditBtn,class:this,callBack:this.handlePermalinkEdit.name},{selector:W.selectors.elPermalinkOkBtn,class:this,callBack:this.handlePermalinkOk.name},{selector:W.selectors.elPermalinkCancelBtn,class:this,callBack:this.handlePermalinkCancel.name}]),e.eventHandlers("change",[{selector:W.selectors.elPublishStatusSelect,class:this,callBack:this.handlePublishStatusChange.name}]))}handlePublishStatusChange(){this.syncHeaderActionWithPublishPanel(),C().markAsChanged()}validateTitleBeforeUpdate(){const e=document.getElementById(W.selectors.idTitle);return!e||(!!e.value.trim()||(n.W("Quiz title is required.","error"),e.focus(),!1))}getQuizDataForUpdate(){const e={},t=document.querySelector(W.selectors.elDataQuiz);e.quiz_id=t&&parseInt(t.dataset.quizId)||0;const s=document.getElementById(W.selectors.idTitle);e.quiz_title=s?s.value:"";const i=document.getElementById(W.selectors.idDescEditor);if(e.quiz_description=i?i.value:"","undefined"!=typeof tinymce){const t=tinymce.get(W.selectors.idDescEditor);t&&(e.quiz_description=t.getContent())}const n=document.querySelector(W.selectors.elPermalinkSlugInput);n&&n.value&&(e.quiz_permalink=n.value);const o=document.querySelector(W.selectors.elFormSetting);return o&&(e.quiz_settings=!0,o.querySelectorAll("input, select, textarea").forEach(t=>{const s=t.name||t.id;if(s&&"learnpress_meta_box_nonce"!==s&&"_wp_http_referer"!==s)if("checkbox"===t.type){const i=s.replace("[]","");e.hasOwnProperty(i)||(e[i]=t.checked?"yes":"no")}else if("radio"===t.type){if(t.checked){const i=s.replace("[]","");e[i]=t.value}}else if("file"===t.type){const i=s.replace("[]","");t.files&&t.files.length>0&&(e[i]=t.files)}else{const i=s.replace("[]","");s.endsWith("[]")?(e.hasOwnProperty(i)||(e[i]=[]),Array.isArray(e[i])&&e[i].push(t.value)):e.hasOwnProperty(i)||(e[i]=t.value)}}),Object.keys(e).forEach(t=>{Array.isArray(e[t])&&(e[t]=e[t].join(","))})),e}getStatusFromPublishPanel(e="publish"){const t=document.querySelector(W.selectors.elPublishStatusSelect);if(!t)return e;const s=t.value;return"publish"===s||"draft"===s?s:e}hasPublishDrivenSingleAction(){if(!document.querySelector(W.selectors.elPublishStatusSelect))return!1;const e=document.querySelector(W.selectors.elDataQuiz);return(e&&parseInt(e.dataset.quizId)||0)>0}syncHeaderActionWithPublishPanel(){if(!this.hasPublishDrivenSingleAction())return;const e=document.querySelector(W.selectors.elHeaderActionsDropdown);if(!e)return;const t=e.querySelector(".cb-btn-main-action");if(!t)return;const s=e.querySelector(W.selectors.elDropdownToggle),i=e.querySelector(W.selectors.elDropdownMenu),n=this.getStatusFromPublishPanel(t.dataset.status||"publish");t.classList.remove("cb-btn-darft","cb-btn-publish","cb-btn-pending"),t.classList.add("cb-btn-update","cb-btn-primary","cb-btn-main-action"),t.textContent=t.dataset.titleUpdate||"Update",t.dataset.status=n,e.dataset.currentStatus=n,e.classList.add("cb-header-actions-dropdown--single"),s&&(s.style.display="none"),i&&(i.style.display="none")}syncPublishPanelStatus(e){const t=document.querySelector(W.selectors.elPublishStatusSelect);t&&(t.value="publish"===e?"publish":"draft",this.syncHeaderActionWithPublishPanel())}updatePermalinkUIAfterSave(e={}){const t=this.getPermalinkRoot();if(!t)return;const{slugInput:s,urlLink:i,baseUrlInput:n,display:o,placeholder:a}=this.getPermalinkElements(t),r=this.buildPermalinkDisplayUrl(n?n.value:"",e?.quiz_slug,e?.quiz_permalink);s&&e?.quiz_slug&&(s.value=e.quiz_slug,s.dataset.originalValue=e.quiz_slug),!1!==e?.permalink_available&&"draft"!==e?.status&&"trash"!==e?.status&&e?.quiz_permalink?(a&&a.classList.add("lp-hidden"),o&&o.classList.remove("lp-hidden"),i&&e?.quiz_permalink?(i.href=e.quiz_permalink,i.textContent=r||e.quiz_permalink):i&&r&&(i.textContent=r)):this.showPermalinkUnavailable(t,e?.permalink_notice)}slugify(e){return(e||"").toString().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"D").toLowerCase().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,"")}buildPermalinkDisplayUrl(e="",t="",s=""){const i="string"==typeof e?e:"",n="string"==typeof t?t.trim():"";return i&&n?`${i}${n}`:"string"==typeof s?s:""}getPermalinkRoot(e=null){if(e?.closest){const t=e.closest(W.selectors.elPermalinkRoot);if(t)return t}return document.querySelector(`.cb-section__quiz-edit ${W.selectors.elPermalinkRoot}`)}getPermalinkElements(e){return e?{display:e.querySelector(W.selectors.elPermalinkDisplay),editor:e.querySelector(W.selectors.elPermalinkEditor),placeholder:e.querySelector(W.selectors.elPermalinkPlaceholder),input:e.querySelector(W.selectors.elPermalinkSlugInput),slugInput:e.querySelector(W.selectors.elPermalinkSlugInput),urlLink:e.querySelector(W.selectors.elPermalinkUrl),baseUrlInput:e.querySelector(W.selectors.elPermalinkBaseUrl)}:{}}showPermalinkUnavailable(e,t=""){if(!e)return;const s=e.querySelector(".cb-item-edit-permalink__label")||e.querySelector(".cb-permalink-label"),{display:i,editor:n}=this.getPermalinkElements(e);let o=e.querySelector(W.selectors.elPermalinkPlaceholder);o||(o=document.createElement("span"),o.className="cb-item-edit-permalink__placeholder",s?s.insertAdjacentElement("afterend",o):e.prepend(o)),o.textContent=t||"Permalink is only available if the item is already assigned to a course.",o.classList.remove("lp-hidden"),i&&i.classList.add("lp-hidden"),n&&n.classList.add("lp-hidden")}handlePermalinkEdit(e){if(!this.isQuizContext())return;const{e:t,target:s}=e;t&&t.preventDefault();const i=this.getPermalinkRoot(s),{display:n,editor:o,input:a}=this.getPermalinkElements(i);n&&o&&a&&(a.dataset.originalValue=a.value,n.classList.add("lp-hidden"),o.classList.remove("lp-hidden"),a.focus(),a.select())}handlePermalinkOk(e){if(!this.isQuizContext())return;const{e:t,target:s}=e;t&&t.preventDefault();const i=this.getPermalinkRoot(s),{display:n,editor:o,input:a,urlLink:r,baseUrlInput:l}=this.getPermalinkElements(i);if(!(n&&o&&a&&r))return;let c=this.slugify(a.value.trim());c||(c=a.dataset.originalValue||"quiz"),a.value=c;const d=l?l.value:"",u=this.buildPermalinkDisplayUrl(d,c,r.textContent||"");r.textContent=u,o.classList.add("lp-hidden"),n.classList.remove("lp-hidden"),c!==a.dataset.originalValue&&C().markAsChanged()}handlePermalinkCancel(e){if(!this.isQuizContext())return;const{e:t,target:s}=e;t&&t.preventDefault();const i=this.getPermalinkRoot(s),{display:n,editor:o,input:a}=this.getPermalinkElements(i);n&&o&&a&&(a.value=a.dataset.originalValue||"",o.classList.add("lp-hidden"),n.classList.remove("lp-hidden"))}updateActionButtons(e){const t=document.querySelector(W.selectors.elHeaderActionsDropdown);if(!t)return;const s=t.querySelector(".cb-btn-main-action"),i=t.querySelector(W.selectors.elDropdownMenu);if(!s)return;if(this.hasPublishDrivenSingleAction())return void this.syncHeaderActionWithPublishPanel();if(!i)return;const n={publish:{mainLabel:s.dataset.titleUpdate||"Update",mainClass:"cb-btn-update",mainStatus:"publish",dropdownLabel:s.dataset.titleDraft||"Save Draft",dropdownClass:"cb-btn-darft",dropdownStatus:"draft",dropdownIcon:"dashicons-media-default"},draft:{mainLabel:s.dataset.titleDraft||"Save Draft",mainClass:"cb-btn-darft",mainStatus:"draft",dropdownLabel:s.dataset.titlePublish||"Publish",dropdownClass:"cb-btn-publish",dropdownStatus:"publish",dropdownIcon:"dashicons-visibility"},pending:{mainLabel:"Submit for Review",mainClass:"cb-btn-pending",mainStatus:"pending",dropdownLabel:s.dataset.titleDraft||"Save Draft",dropdownClass:"cb-btn-darft",dropdownStatus:"draft",dropdownIcon:"dashicons-media-default"},trash:{mainLabel:s.dataset.titleDraft||"Save Draft",mainClass:"cb-btn-darft",mainStatus:"draft",dropdownLabel:s.dataset.titlePublish||"Publish",dropdownClass:"cb-btn-publish",dropdownStatus:"publish",dropdownIcon:"dashicons-visibility"}},o=n[e]||n.draft;s.className=`${o.mainClass} cb-btn-primary cb-btn-main-action`,s.dataset.status=o.mainStatus,s.textContent=o.mainLabel;const a=i.querySelectorAll(".cb-dropdown-item:not(.cb-btn-trash)");if(a.length>0){const e=a[0];e.className=`cb-dropdown-item ${o.dropdownClass}`,e.dataset.status=o.dropdownStatus,e.innerHTML=`<span class="dashicons ${o.dropdownIcon}"></span>${o.dropdownLabel}`}t.dataset.currentStatus=e}isQuizContext(){return!!document.querySelector(W.selectors.elDataQuiz)}async updateQuiz(t){if(!this.isQuizContext())return;const{target:s}=t,i=s.closest(W.selectors.elBtnMainAction);if(!i)return;if(!this.validateTitleBeforeUpdate())return;const o=this.getStatusFromPublishPanel(i.dataset.status||"publish");if(!await this.confirmUnpublishIfNeeded(o,i))return;e.lpSetLoadingEl(i,1);const a=this.getQuizDataForUpdate(),r={...a,action:"builder_update_quiz",args:{id_url:"builder-update-quiz"},quiz_status:o},l={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),"success"===t){if(this.updateActionButtons(i?.status||o),this.syncPublishPanelStatus(i?.status||o),document.dispatchEvent(new CustomEvent("lp-course-builder-saved")),i?.redirect_url&&(window.location.href=i.redirect_url),i?.status){const e=document.querySelector(W.selectors.elQuizStatus);if(e&&(e.className="quizze-status "+i.status,e.textContent=i.status),"trash"===i.status||"draft"===i.status){const e=document.querySelector(`.quiz-item[data-quiz-id="${a.quiz_id}"]`);if(e){const t=e.closest(".quiz");t&&t.remove()}}}this.updatePermalinkUIAfterSave(i)}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(i,0)}};window.lpAJAXG.fetchAJAX(r,l)}async confirmUnpublishIfNeeded(e,t){if("draft"!==e)return!0;const s=document.querySelector(W.selectors.elQuizStatus);if(!s||!s.className.includes("publish"))return!0;const n=t?.dataset?.confirmUnpublish||"Saving as draft will unpublish this item. Are you sure?";return!!(await i().fire({title:n,iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0})).isConfirmed}async saveDraftQuiz(t){if(!this.isQuizContext())return;const{target:s}=t,a=s.closest(W.selectors.elBtnDraft);if(!a)return;const r=document.querySelector(W.selectors.elQuizStatus);if(r&&r.className.includes("publish")){const e=a.dataset.confirmUnpublish||"Saving as draft will unpublish this item. Are you sure?";if(!(await i().fire({title:e,iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0})).isConfirmed)return}if(!this.validateTitleBeforeUpdate())return;const l=document.querySelector(W.selectors.elQuizActionExpanded);e.lpSetLoadingEl(l,1);const c=this.getQuizDataForUpdate(),d={...c,action:"builder_update_quiz",args:{id_url:"builder-update-quiz"},quiz_status:"draft"},u={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),"success"===t){if(this.updateActionButtons("draft"),this.syncPublishPanelStatus(i?.status||"draft"),document.dispatchEvent(new CustomEvent("lp-course-builder-saved")),i?.quiz_id_new){const e=window.location.href;window.location.href=e.replace(/post-new\/?/,`${i.quiz_id_new}/`)}if(i?.status){const e=document.querySelector(W.selectors.elQuizStatus);if(e&&(e.className="quizze-status "+i.status,e.textContent=i.status),"trash"===i.status||"draft"===i.status){const e=document.querySelector(`.quiz-item[data-quiz-id="${c.quiz_id}"]`);if(e){const t=e.closest(".quiz");t&&t.remove()}}}this.updatePermalinkUIAfterSave(i)}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(l,0)}};window.lpAJAXG.fetchAJAX(d,u)}async trashQuiz(t){if(!this.isQuizContext())return;const{target:s}=t;if(!s.closest(W.selectors.elBtnTrash))return;if(!(await i().fire({title:"Are you sure you want to trash this quiz?",iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0})).isConfirmed)return;const a=document.querySelector(W.selectors.elQuizActionExpanded);e.lpSetLoadingEl(a,1);const r=document.querySelector(W.selectors.elDataQuiz),l=r&&parseInt(r.dataset.quizId)||0,c={quiz_id:l,action:"move_trash_quiz",args:{id_url:"builder-trash-quiz"}},d={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),"success"===t){if(i?.status){const e=document.querySelector(W.selectors.elQuizStatus);if(e&&(e.className="quizze-status "+i.status,e.textContent=i.status),"trash"===i.status||"draft"===i.status){const e=document.querySelector(`.quiz-item[data-quiz-id="${l}"]`);if(e){const t=e.closest(".quiz");t&&t.remove()}}this.updateActionButtons(i.status)}this.updatePermalinkUIAfterSave(i),i?.redirect_url&&(window.location.href=i.redirect_url)}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(c,d)}async duplicateQuiz(t){if(!this.isQuizContext())return;const{target:s}=t,o=s.closest(W.selectors.elBtnDuplicate);if(!o)return;const r=document.querySelector(W.selectors.elDataQuiz),l=r&&parseInt(r.dataset.quizId,10)||0;if(!l)return;if(!(await i().fire({title:o.dataset.title||"Are you sure?",text:o.dataset.content||"Are you sure you want to duplicate this quiz?",iconHtml:a,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0})).isConfirmed)return;const c=document.querySelector(W.selectors.elQuizActionExpanded);e.lpSetLoadingEl(c,1);const d={quiz_id:l,action:"duplicate_quiz",args:{id_url:"duplicate-quiz"}},u={success:e=>{const{status:t,message:s,data:i}=e;n.W(s||"Duplicated successfully!",t),"success"===t&&i?.redirect_url&&(window.location.href=i.redirect_url)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(c,0)}};window.lpAJAXG.fetchAJAX(d,u)}}class j{constructor(){this.init()}static selectors={elQuestionItem:".question-item",elQuestionExpandedItems:".question-action-expanded__items",elQuestionDuplicate:".question-action-expanded__duplicate",elQuestionTrash:".question-action-expanded__trash",elQuestionRestore:".question-action-expanded__restore",elQuestionPublish:".question-action-expanded__publish",elQuestionDelete:".question-action-expanded__delete",elQuestionActionExpanded:".question-action-expanded",elQuestionStatus:".question-status",elBtnEditQuestion:".btn-edit-question"};init(){this.events()}events(){j._loadedEvents||(j._loadedEvents=!0,e.eventHandlers("click",[{selector:j.selectors.elQuestionDuplicate,class:this,callBack:this.duplicateQuestion.name},{selector:j.selectors.elQuestionTrash,class:this,callBack:this.trashQuestion.name},{selector:j.selectors.elQuestionPublish,class:this,callBack:this.publishQuestion.name},{selector:j.selectors.elQuestionRestore,class:this,callBack:this.restoreQuestion.name},{selector:j.selectors.elQuestionDelete,class:this,callBack:this.deleteQuestion.name},{selector:j.selectors.elQuestionActionExpanded,class:this,callBack:this.toggleExpandedAction.name},{selector:j.selectors.elBtnEditQuestion,class:this,callBack:this.editQuestion.name}]),document.addEventListener("click",e=>{e.target.closest(j.selectors.elQuestionActionExpanded)||this.closeAllExpanded()}))}editQuestion(t){const{target:s}=t,i=s.closest(j.selectors.elBtnEditQuestion);i&&e.lpSetLoadingEl(i,1)}duplicateQuestion(t){const{target:s}=t,o=s.closest(j.selectors.elQuestionDuplicate),r=o.closest(j.selectors.elQuestionItem);if(!r)return;const l=r.querySelector(j.selectors.elQuestionActionExpanded),c=r.dataset.questionId||"";i().fire({title:o.dataset.title||"Duplicate Question",text:o.dataset.content||"Are you sure you want to duplicate this question?",iconHtml:a,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(l,1);const t={action:"duplicate_question",args:{id_url:"duplicate-question"},question_id:c},s={success:e=>{const{status:t,message:s,data:i}=e;n.W(s||"Duplicated successfully!",t),"success"===t&&i?.redirect_url&&(window.location.href=i.redirect_url)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(l,0)}};window.lpAJAXG.fetchAJAX(t,s)}})}trashQuestion(t){const{target:s}=t,a=s.closest(j.selectors.elQuestionTrash),r=a.closest(j.selectors.elQuestionItem);if(!r)return;const l=r.querySelector(j.selectors.elQuestionActionExpanded),c=r.dataset.questionId||"";i().fire({title:a.dataset.title||"Trash Question",text:a.dataset.content||"Are you sure you want to move this question to trash?",iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(l,1);const t={action:"move_trash_question",args:{id_url:"move-trash-question"},question_id:c},s={success:e=>{const{status:t,message:s,data:i}=e;n.W(s,t),i?.html&&this.replaceItemHtml(a.closest(".question"),i.html)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(l,0)}};window.lpAJAXG.fetchAJAX(t,s)}})}publishQuestion(t){const{target:s}=t,i=s.closest(j.selectors.elQuestionPublish),o=i.closest(j.selectors.elQuestionItem);if(!o)return;const a=o.querySelector(j.selectors.elQuestionActionExpanded);e.lpSetLoadingEl(a,1);const r={action:"move_trash_question",args:{id_url:"move-trash-question"},question_id:o.dataset.questionId||"",status:"publish"},l={success:e=>{const{status:t,message:s,data:o}=e;n.W(s,t),o?.html&&this.replaceItemHtml(i.closest(".question"),o.html)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(r,l)}restoreQuestion(t){const{target:s}=t,i=s.closest(j.selectors.elQuestionRestore),o=i.closest(j.selectors.elQuestionItem);if(!o)return;const a=o.querySelector(j.selectors.elQuestionActionExpanded);e.lpSetLoadingEl(a,1);const r={action:"move_trash_question",args:{id_url:"move-trash-question"},question_id:o.dataset.questionId||"",status:"draft"},l={success:e=>{const{status:t,message:s,data:o}=e;n.W(s,t),o?.html&&this.replaceItemHtml(i.closest(".question"),o.html)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(r,l)}deleteQuestion(t){const{target:s}=t,o=s.closest(j.selectors.elQuestionDelete),a=o.closest(j.selectors.elQuestionItem);if(!a)return;const l=a.querySelector(j.selectors.elQuestionActionExpanded),c=a.dataset.questionId||"";c&&i().fire({title:o.dataset.title||"Delete Question",text:o.dataset.content||"Are you sure you want to permanently delete this question?",iconHtml:r,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0}).then(t=>{if(t.isConfirmed){e.lpSetLoadingEl(l,1);const t={action:"move_trash_question",args:{id_url:"move-trash-question"},question_id:c,status:"delete"},s={success:e=>{const{status:t,message:s}=e;if(n.W(s,t),"success"===t){const e=o.closest(".question");e.style.transition="opacity 0.4s ease-out, transform 0.4s ease-out",e.style.opacity="0",e.style.transform="translateX(160px)",setTimeout(()=>{e.remove()},400)}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(l,0)}};window.lpAJAXG.fetchAJAX(t,s)}})}toggleExpandedAction(e){const{target:t}=e,s=t.closest(j.selectors.elQuestionActionExpanded);if(!s)return;const i=s.closest(j.selectors.elQuestionItem);if(!i)return;const n=i.querySelector(j.selectors.elQuestionExpandedItems);n&&(this.closeAllExpanded(n),n.classList.contains("active")?(n.classList.remove("active"),n.classList.remove("is-dropup"),s.classList.remove("active")):(n.classList.add("active"),s.classList.add("active"),this.setExpandedDirection(n)))}closeAllExpanded(e=null){document.querySelectorAll(`${j.selectors.elQuestionExpandedItems}.active`).forEach(t=>{if(t===e)return;t.classList.remove("active"),t.classList.remove("is-dropup");const s=t.closest(j.selectors.elQuestionItem);if(!s)return;const i=s.querySelector(j.selectors.elQuestionActionExpanded);i&&i.classList.remove("active")})}setExpandedDirection(e){if(!e)return;e.classList.remove("is-dropup");const t=e.closest(".question");t&&t.matches(":last-child")&&e.classList.add("is-dropup")}replaceItemHtml(e,t){if(!e||!t)return;const s=document.createElement("div");s.innerHTML=t;const i=s.firstElementChild;i&&e.replaceWith(i)}}class V{constructor(){this.editQuestion=null,this.init()}static selectors={elDataQuestion:".cb-section__question-edit",elBtnUpdateQuestion:".cb-btn-update",elBtnDraftQuestion:".cb-btn-draft",elBtnDuplicateQuestion:".cb-btn-duplicate-question",elBtnTrashQuestion:".cb-btn-trash",elBtnMainAction:".cb-btn-main-action",elQuestionStatus:".question-status",idTitle:"title",idDescEditor:"question_description_editor",elPublishStatusSelect:"#cb-question-publish-status",elFormSetting:".lp-form-setting-question",elPermalinkDisplay:".cb-permalink-display",elPermalinkEditor:".cb-permalink-editor",elPermalinkEditBtn:".cb-permalink-edit-btn",elPermalinkOkBtn:".cb-permalink-ok-btn",elPermalinkCancelBtn:".cb-permalink-cancel-btn",elPermalinkSlugInput:".cb-permalink-slug-input",elPermalinkUrl:".cb-permalink-url",elPermalinkBaseUrl:"#cb-permalink-base-url",elEditQuestionWrap:".lp-edit-question-wrap",elQuestionEditMain:".lp-question-edit-main",elCBHorizontalTabs:".lp-cb-tabs__item",elCBTabPanels:".lp-cb-tab-panel",elDropdownToggle:".cb-btn-dropdown-toggle",elDropdownMenu:".cb-dropdown-menu",elDropdownItem:".cb-dropdown-item",elHeaderActionsDropdown:".cb-header-actions-dropdown",elQuestionActionExpanded:".course-action-expanded"};init(){this.initQuestionAnswersSettings(),this.initTabs(),this.initHeaderActionsDropdown(),this.syncHeaderActionWithPublishPanel(),this.events()}initHeaderActionsDropdown(){document.addEventListener("click",e=>{const t=document.querySelector(V.selectors.elHeaderActionsDropdown);if(t&&!t.contains(e.target)){const e=t.querySelector(V.selectors.elDropdownMenu),s=t.querySelector(V.selectors.elDropdownToggle);e&&e.classList.remove("is-open"),s&&s.setAttribute("aria-expanded","false")}})}handleDropdownToggle(e){if(this.hasPublishDrivenSingleAction())return;const{target:t}=e,s=t.closest(V.selectors.elDropdownToggle);if(!s)return;const i=s.closest(V.selectors.elHeaderActionsDropdown);if(!i)return;const n=i.querySelector(V.selectors.elDropdownMenu);if(n){n.classList.toggle("is-open");const e=n.classList.contains("is-open");s.setAttribute("aria-expanded",e?"true":"false")}}handleDropdownItemClick(e){if(!this.isQuestionContext())return;if(this.hasPublishDrivenSingleAction())return;const{target:t}=e,s=t.closest(V.selectors.elDropdownItem);if(!s)return;if(s.classList.contains("cb-btn-trash")||s.classList.contains("cb-btn-duplicate-question"))return;const i=s.dataset.status;if(!i)return;const n=s.closest(V.selectors.elDropdownMenu);n&&n.classList.remove("is-open"),this.saveQuestionWithStatus(s,i)}async saveQuestionWithStatus(t,s){if(!await this.confirmUnpublishIfNeeded(s,t))return;if(!this.validateTitleBeforeUpdate())return;e.lpSetLoadingEl(t,1);const i=this.getQuestionDataForUpdate(),o={...i,action:"builder_update_question",args:{id_url:"builder-update-question"},question_status:s};"undefined"!=typeof lpQuestionBuilder&&lpQuestionBuilder.nonce&&(o.nonce=lpQuestionBuilder.nonce);const a={success:e=>{const{status:t,message:o,data:a}=e;if(n.W(o,t),"success"===t){if(this.updateActionButtons(a?.status||s),this.syncPublishPanelStatus(a?.status||s),this.updatePermalinkUIAfterSave(a),document.dispatchEvent(new CustomEvent("lp-course-builder-saved")),a?.question_id_new){const e=window.location.href;window.location.href=e.replace(/post-new\/?/,`${a.question_id_new}/`)}if(a?.status){const e=document.querySelector(V.selectors.elQuestionStatus);if(e&&(e.className="question-status "+a.status,e.textContent=a.status),"trash"===a.status||"draft"===a.status){const e=document.querySelector(`.question-item[data-question-id="${i.question_id}"]`);if(e){const t=e.closest(".question");t&&t.remove()}}}}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(t,0)}};window.lpAJAXG.fetchAJAX(o,a)}initTabs(){const e=document.querySelectorAll(V.selectors.elCBHorizontalTabs);if(0!==e.length&&!document.querySelector(`${V.selectors.elCBHorizontalTabs}.is-active`)&&e.length>0){e[0].classList.add("is-active");const t=e[0].getAttribute("data-tab-section");if(t){const e=document.querySelector(`${V.selectors.elCBTabPanels}[data-section="${t}"]`);e&&e.classList.remove("lp-hidden")}}}handleTabClick(e){const{e:t,target:s}=e,i=s.closest(V.selectors.elCBHorizontalTabs);if(!i)return;t.preventDefault();const n=i.getAttribute("data-tab-section");if(!n)return;document.querySelectorAll(V.selectors.elCBHorizontalTabs).forEach(e=>e.classList.remove("is-active")),i.classList.add("is-active");const o=new URL(window.location.href);o.searchParams.set("tab",n),window.history.replaceState({},"",o),document.querySelectorAll(V.selectors.elCBTabPanels).forEach(e=>{e.getAttribute("data-section")===n?e.classList.remove("lp-hidden"):e.classList.add("lp-hidden")})}initQuestionAnswersSettings(){e.lpOnElementReady(V.selectors.elQuestionEditMain,e=>{this.editQuestion||(this.editQuestion=new N.f,this.editQuestion.init()),this.editQuestion&&this.editQuestion.sortAbleQuestionAnswer(e)})}reinitQuestionHandlers(e){this.editQuestion&&e&&(this.editQuestion.sortAbleQuestionAnswer(e),this.editQuestion.initTinyMCE())}reinit(e){const t=e?e.querySelector(V.selectors.elQuestionEditMain):document.querySelector(V.selectors.elQuestionEditMain);t&&(this.editQuestion&&"undefined"!=typeof tinymce&&e&&e.querySelectorAll("textarea.lp-meta-box__editor").forEach(e=>{const t=e.id;if(t){const e=tinymce.get(t);e&&e.remove(),"undefined"!=typeof wp&&wp.editor&&wp.editor.remove&&wp.editor.remove(t)}}),this.editQuestion=new N.f,this.editQuestion.init(),this.editQuestion.sortAbleQuestionAnswer(t),setTimeout(()=>{this.editQuestion&&this.editQuestion.initTinyMCE()},100))}events(){V._loadedEvents||(V._loadedEvents=!0,e.eventHandlers("click",[{selector:V.selectors.elBtnMainAction,class:this,callBack:this.updateQuestion.name},{selector:V.selectors.elBtnDraftQuestion,class:this,callBack:this.saveDraftQuestion.name},{selector:V.selectors.elBtnDuplicateQuestion,class:this,callBack:this.duplicateQuestion.name},{selector:V.selectors.elBtnTrashQuestion,class:this,callBack:this.trashQuestion.name},{selector:V.selectors.elCBHorizontalTabs,class:this,callBack:this.handleTabClick.name},{selector:V.selectors.elDropdownToggle,class:this,callBack:this.handleDropdownToggle.name},{selector:V.selectors.elDropdownItem,class:this,callBack:this.handleDropdownItemClick.name},{selector:V.selectors.elPermalinkEditBtn,class:this,callBack:this.handlePermalinkEdit.name},{selector:V.selectors.elPermalinkOkBtn,class:this,callBack:this.handlePermalinkOk.name},{selector:V.selectors.elPermalinkCancelBtn,class:this,callBack:this.handlePermalinkCancel.name}]),e.eventHandlers("change",[{selector:V.selectors.elPublishStatusSelect,class:this,callBack:this.handlePublishStatusChange.name}]))}handlePublishStatusChange(){this.syncHeaderActionWithPublishPanel(),C().markAsChanged()}validateTitleBeforeUpdate(){const e=document.getElementById(V.selectors.idTitle);return!e||(!!e.value.trim()||(n.W("Question title is required.","error"),e.focus(),!1))}updateActionButtons(e){const t=document.querySelector(V.selectors.elHeaderActionsDropdown);if(!t)return;const s=t.querySelector(".cb-btn-main-action"),i=t.querySelector(V.selectors.elDropdownMenu);if(!s)return;if(this.hasPublishDrivenSingleAction())return void this.syncHeaderActionWithPublishPanel();if(!i)return;const n={publish:{mainLabel:s.dataset.titleUpdate||"Update",mainClass:"cb-btn-update",mainStatus:"publish",dropdownLabel:s.dataset.titleDraft||"Save Draft",dropdownClass:"cb-btn-darft",dropdownStatus:"draft",dropdownIcon:"dashicons-media-default"},draft:{mainLabel:s.dataset.titleDraft||"Save Draft",mainClass:"cb-btn-darft",mainStatus:"draft",dropdownLabel:s.dataset.titlePublish||"Publish",dropdownClass:"cb-btn-publish",dropdownStatus:"publish",dropdownIcon:"dashicons-visibility"},pending:{mainLabel:"Submit for Review",mainClass:"cb-btn-pending",mainStatus:"pending",dropdownLabel:s.dataset.titleDraft||"Save Draft",dropdownClass:"cb-btn-darft",dropdownStatus:"draft",dropdownIcon:"dashicons-media-default"}},o=n[e]||n.draft;s.className=`${o.mainClass} cb-btn-primary cb-btn-main-action`,s.dataset.status=o.mainStatus,s.textContent=o.mainLabel;const a=i.querySelectorAll(".cb-dropdown-item:not(.cb-btn-trash)");if(a.length>0){const e=a[0];e.className=`cb-dropdown-item ${o.dropdownClass}`,e.dataset.status=o.dropdownStatus,e.innerHTML=`<span class="dashicons ${o.dropdownIcon}"></span>${o.dropdownLabel}`}t.dataset.currentStatus=e}isQuestionContext(){return!!document.querySelector(V.selectors.elDataQuestion)}getQuestionDataForUpdate(){const e={},t=document.querySelector(V.selectors.elDataQuestion);e.question_id=t&&parseInt(t.dataset.questionId)||0;const s=document.getElementById(V.selectors.idTitle);e.question_title=s?s.value:"";const i=document.getElementById(V.selectors.idDescEditor);if(e.question_description=i?i.value:"","undefined"!=typeof tinymce){const t=tinymce.get(V.selectors.idDescEditor);t&&(e.question_description=t.getContent())}const n=document.querySelector(V.selectors.elPermalinkSlugInput);n&&n.value&&(e.question_permalink=n.value);const o=document.querySelector(V.selectors.elFormSetting);return o&&(e.question_settings=!0,o.querySelectorAll("input, select, textarea").forEach(t=>{const s=t.name||t.id;if(s&&"learnpress_meta_box_nonce"!==s&&"_wp_http_referer"!==s)if("checkbox"===t.type){const i=s.replace("[]","");e.hasOwnProperty(i)||(e[i]=t.checked?"yes":"no")}else if("radio"===t.type){if(t.checked){const i=s.replace("[]","");e[i]=t.value}}else if("file"===t.type){const i=s.replace("[]","");t.files&&t.files.length>0&&(e[i]=t.files)}else{const i=s.replace("[]","");s.endsWith("[]")?(e.hasOwnProperty(i)||(e[i]=[]),Array.isArray(e[i])&&e[i].push(t.value)):e.hasOwnProperty(i)||(e[i]=t.value)}}),Object.keys(e).forEach(t=>{Array.isArray(e[t])&&(e[t]=e[t].join(","))})),e}getStatusFromPublishPanel(e="publish"){const t=document.querySelector(V.selectors.elPublishStatusSelect);if(!t)return e;const s=t.value;return"publish"===s||"draft"===s?s:e}hasPublishDrivenSingleAction(){if(!document.querySelector(V.selectors.elPublishStatusSelect))return!1;const e=document.querySelector(V.selectors.elDataQuestion);return(e&&parseInt(e.dataset.questionId)||0)>0}syncHeaderActionWithPublishPanel(){if(!this.hasPublishDrivenSingleAction())return;const e=document.querySelector(V.selectors.elHeaderActionsDropdown);if(!e)return;const t=e.querySelector(".cb-btn-main-action");if(!t)return;const s=e.querySelector(V.selectors.elDropdownToggle),i=e.querySelector(V.selectors.elDropdownMenu),n=this.getStatusFromPublishPanel(t.dataset.status||"publish");t.classList.remove("cb-btn-darft","cb-btn-publish","cb-btn-pending"),t.classList.add("cb-btn-update","cb-btn-primary","cb-btn-main-action"),t.textContent=t.dataset.titleUpdate||"Update",t.dataset.status=n,e.dataset.currentStatus=n,e.classList.add("cb-header-actions-dropdown--single"),s&&(s.style.display="none"),i&&(i.style.display="none")}syncPublishPanelStatus(e){const t=document.querySelector(V.selectors.elPublishStatusSelect);t&&(t.value="publish"===e?"publish":"draft",this.syncHeaderActionWithPublishPanel())}updatePermalinkUIAfterSave(e={}){const t=document.querySelector(V.selectors.elPermalinkSlugInput),s=document.querySelector(V.selectors.elPermalinkUrl),i=document.querySelector(V.selectors.elPermalinkBaseUrl),n=this.buildPermalinkDisplayUrl(i?i.value:"",e?.question_slug,e?.question_permalink);t&&e?.question_slug&&(t.value=e.question_slug,t.dataset.originalValue=e.question_slug),s&&e?.question_permalink?(s.href=e.question_permalink,s.textContent=n||e.question_permalink):s&&n&&(s.textContent=n)}slugify(e){return(e||"").toString().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/Đ/g,"D").toLowerCase().replace(/\s+/g,"-").replace(/[^\w-]+/g,"").replace(/--+/g,"-").replace(/^-+/,"").replace(/-+$/,"")}buildPermalinkDisplayUrl(e="",t="",s=""){const i="string"==typeof e?e:"",n="string"==typeof t?t.trim():"";return i&&n?`${i}${n}`:"string"==typeof s?s:""}handlePermalinkEdit(e){if(!this.isQuestionContext())return;const{e:t}=e;t&&t.preventDefault();const s=document.querySelector(V.selectors.elPermalinkDisplay),i=document.querySelector(V.selectors.elPermalinkEditor),n=document.querySelector(V.selectors.elPermalinkSlugInput);s&&i&&n&&(n.dataset.originalValue=n.value,s.classList.add("lp-hidden"),i.classList.remove("lp-hidden"),n.focus(),n.select())}handlePermalinkOk(e){if(!this.isQuestionContext())return;const{e:t}=e;t&&t.preventDefault();const s=document.querySelector(V.selectors.elPermalinkDisplay),i=document.querySelector(V.selectors.elPermalinkEditor),n=document.querySelector(V.selectors.elPermalinkSlugInput),o=document.querySelector(V.selectors.elPermalinkUrl),a=document.querySelector(V.selectors.elPermalinkBaseUrl);if(!(s&&i&&n&&o))return;let r=this.slugify(n.value.trim());r||(r=n.dataset.originalValue||"question"),n.value=r;const l=a?a.value:"",c=this.buildPermalinkDisplayUrl(l,r,o.textContent||"");o.textContent=c,i.classList.add("lp-hidden"),s.classList.remove("lp-hidden"),r!==n.dataset.originalValue&&C().markAsChanged()}handlePermalinkCancel(e){if(!this.isQuestionContext())return;const{e:t}=e;t&&t.preventDefault();const s=document.querySelector(V.selectors.elPermalinkDisplay),i=document.querySelector(V.selectors.elPermalinkEditor),n=document.querySelector(V.selectors.elPermalinkSlugInput);s&&i&&n&&(n.value=n.dataset.originalValue||"",i.classList.add("lp-hidden"),s.classList.remove("lp-hidden"))}async updateQuestion(t){if(!this.isQuestionContext())return;const{target:s}=t,i=s.closest(V.selectors.elBtnMainAction);if(!i)return;if(!this.validateTitleBeforeUpdate())return;const o=this.getStatusFromPublishPanel(i.dataset.status||"publish");if(!await this.confirmUnpublishIfNeeded(o,i))return;e.lpSetLoadingEl(i,1);const a=this.getQuestionDataForUpdate(),r={...a,action:"builder_update_question",args:{id_url:"builder-update-question"},question_status:o};"undefined"!=typeof lpQuestionBuilder&&lpQuestionBuilder.nonce&&(r.nonce=lpQuestionBuilder.nonce);const l={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),"success"===t&&(this.updateActionButtons(i?.status||o),this.syncPublishPanelStatus(i?.status||o),this.updatePermalinkUIAfterSave(i),document.dispatchEvent(new CustomEvent("lp-course-builder-saved")),i?.redirect_url&&(window.location.href=i.redirect_url),i?.status)){const e=document.querySelector(V.selectors.elQuestionStatus);if(e&&(e.className="question-status "+i.status,e.textContent=i.status),"trash"===i.status||"draft"===i.status){const e=document.querySelector(`.question-item[data-question-id="${a.question_id}"]`);if(e){const t=e.closest(".question");t&&t.remove()}}}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(i,0)}};window.lpAJAXG.fetchAJAX(r,l)}async confirmUnpublishIfNeeded(e,t){if("draft"!==e)return!0;const s=document.querySelector(V.selectors.elQuestionStatus);if(!s||!s.classList.contains("publish"))return!0;const n=t?.dataset?.confirmUnpublish||"Saving as draft will unpublish this item. Are you sure?";return!!(await i().fire({title:n,iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0})).isConfirmed}async saveDraftQuestion(t){if(!this.isQuestionContext())return;const{target:s}=t,a=s.closest(V.selectors.elBtnDraftQuestion);if(!a)return;const r=document.querySelector(V.selectors.elQuestionStatus);if(r&&r.classList.contains("publish")){const e=a.dataset.confirmUnpublish||"Saving as draft will unpublish this item. Are you sure?";if(!(await i().fire({title:e,iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0})).isConfirmed)return}if(!this.validateTitleBeforeUpdate())return;const l=document.querySelector(V.selectors.elQuestionActionExpanded);e.lpSetLoadingEl(l,1);const c=this.getQuestionDataForUpdate(),d={...c,action:"builder_update_question",args:{id_url:"builder-update-question"},question_status:"draft"};"undefined"!=typeof lpQuestionBuilder&&lpQuestionBuilder.nonce&&(d.nonce=lpQuestionBuilder.nonce);const u={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),"success"===t){if(this.updateActionButtons("draft"),this.syncPublishPanelStatus(i?.status||"draft"),this.updatePermalinkUIAfterSave(i),document.dispatchEvent(new CustomEvent("lp-course-builder-saved")),i?.question_id_new){const e=window.location.href;window.location.href=e.replace(/post-new\/?/,`${i.question_id_new}/`)}if(i?.status){const e=document.querySelector(V.selectors.elQuestionStatus);if(e&&(e.className="question-status "+i.status,e.textContent=i.status),"trash"===i.status||"draft"===i.status){const e=document.querySelector(`.question-item[data-question-id="${c.question_id}"]`);if(e){const t=e.closest(".question");t&&t.remove()}}}}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(l,0)}};window.lpAJAXG.fetchAJAX(d,u)}async trashQuestion(t){if(!this.isQuestionContext())return;const{target:s}=t;if(!s.closest(V.selectors.elBtnTrashQuestion))return;if(!(await i().fire({title:"Are you sure you want to trash this question?",iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0})).isConfirmed)return;const a=document.querySelector(V.selectors.elQuestionActionExpanded);e.lpSetLoadingEl(a,1);const r=this.getQuestionDataForUpdate(),l={action:"move_trash_question",args:{id_url:"move-trash-question"},question_id:r.question_id||0},c={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),"success"===t&&(i?.redirect_url&&(window.location.href=i.redirect_url),i?.status)){const e=document.querySelector(V.selectors.elQuestionStatus);if(e&&(e.className="question-status "+i.status,e.textContent=i.status),"trash"===i.status||"draft"===i.status){const e=document.querySelector(`.question-item[data-question-id="${r.question_id}"]`);if(e){const t=e.closest(".question");t&&t.remove()}}}},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(a,0)}};window.lpAJAXG.fetchAJAX(l,c)}async duplicateQuestion(t){if(!this.isQuestionContext())return;const{target:s}=t,o=s.closest(V.selectors.elBtnDuplicateQuestion);if(!o)return;const r=this.getQuestionDataForUpdate(),l=parseInt(r?.question_id,10)||0;if(!l)return;if(!(await i().fire({title:o.dataset.title||"Are you sure?",text:o.dataset.content||"Are you sure you want to duplicate this question?",iconHtml:a,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0})).isConfirmed)return;const c=document.querySelector(V.selectors.elQuestionActionExpanded);e.lpSetLoadingEl(c,1);const d={action:"duplicate_question",args:{id_url:"duplicate-question"},question_id:l},u={success:e=>{const{status:t,message:s,data:i}=e;n.W(s||"Duplicated successfully!",t),"success"===t&&i?.redirect_url&&(window.location.href=i.redirect_url)},error:e=>{n.W(e.message||e,"error")},completed:()=>{e.lpSetLoadingEl(c,0)}};window.lpAJAXG.fetchAJAX(d,u)}}class U{constructor(e=null){this.container=e,this.initialized=!1,this.eventsBound=!1,this.sortable=null,this.boundHandlers={handleAddMaterial:null,handleChange:null,handleClick:null,handleSaveAll:null,handleDelete:null,handleDragStart:null,handleDragOver:null,handleDrop:null,handleDragEnd:null},this.elements={},this.container&&this.init()}reinit(e){this.initialized&&this.destroy(),this.container=e,this.container&&this.init()}cacheElements(){const e=this.elements;e.postId=this.container.querySelector("#current-material-post-id"),e.maxFileSize=this.container.querySelector("#material-max-file-size"),e.uploadField=this.container.querySelector(".lp-material--field-upload"),e.canUpload=this.container.querySelector("#available-to-upload"),e.addBtn=this.container.querySelector("#btn-lp--add-material"),e.groupTemplate=this.container.querySelector("#lp-material--add-material-template"),e.groupContainer=this.container.querySelector("#lp-material--group-container"),e.materialTab=this.container.querySelector("#lp-material-container")||this.container,e.saveBtn=this.container.querySelector("#btn-lp--save-material"),e.uploadTemplate=this.container.querySelector("#lp-material--upload-field-template"),e.externalTemplate=this.container.querySelector("#lp-material--external-field-template"),e.deleteText=this.container.querySelector("#delete-material-row-text"),e.deleteMessage=this.container.querySelector("#delete-material-message"),e.materialTable=this.container.querySelector(".lp-material--table"),e.tbody=e.materialTable?.querySelector("tbody"),e.thead=e.materialTable?.querySelector("thead")}init(){if(!this.container)return;this.cacheElements();const{postId:e,materialTab:t}=this.elements;e&&t&&(this.postID=e.value,this.maxFileSize=this.elements.maxFileSize?.value||10,this.acceptFile=this.elements.uploadField&&this.elements.uploadField.getAttribute("accept")?.split(",").map(e=>e.trim())||[],this.loadMaterials(),this.bindEvents(),this.initSortable(),this.initialized=!0)}async loadMaterials(){const{materialTab:e,tbody:t}=this.elements;if(e&&this.postID&&t)try{const s=`${this.getRestUrl()}lp/v1/material/item-materials/${this.postID}`,i=await fetch(s,{method:"GET",headers:{"X-WP-Nonce":this.getNonce(),"Content-Type":"application/json"}});if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);const n=await i.json(),{data:o,status:a}=n;if("success"!==a)return void console.error(n.message);if(o?.items?.length>0){const s=e.querySelector(".lp-skeleton-animation");s?.remove();const i=document.createDocumentFragment();o.items.forEach(e=>{const t=this.createRow(e);i.appendChild(t)}),t.appendChild(i),this.initSortable()}}catch(e){console.error("Load materials error:",e.message)}}createRow(e){const t=document.createElement("tr");t.dataset.id=e.file_id,t.dataset.sort=e.orders,t.draggable=!0;const s=this.elements.deleteText?.value||"Delete";return t.innerHTML=`\n\t\t\t<td class="sort">\n\t\t\t\t<span class="dashicons dashicons-menu"></span> ${this.escapeHtml(e.file_name)}\n\t\t\t</td>\n\t\t\t<td>${this.capitalizeFirstChar(e.method)}</td>\n\t\t\t<td>\n\t\t\t\t<a href="javascript:void(0)" class="delete-material-row" data-id="${e.file_id}">\n\t\t\t\t\t${s}\n\t\t\t\t</a>\n\t\t\t</td>\n\t\t`,t}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}capitalizeFirstChar(e){return e.charAt(0).toUpperCase()+e.substring(1)}bindEvents(){if(this.eventsBound)return;const{addBtn:e,materialTab:t,saveBtn:s}=this.elements;this.boundHandlers.handleAddMaterial=()=>this.handleAddMaterial(),this.boundHandlers.handleChange=e=>this.handleChange(e),this.boundHandlers.handleClick=e=>this.handleClick(e),this.boundHandlers.handleSaveAll=()=>this.handleSaveAll(),this.boundHandlers.handleDelete=e=>this.handleDelete(e),e?.addEventListener("click",this.boundHandlers.handleAddMaterial),t&&(t.addEventListener("change",this.boundHandlers.handleChange),t.addEventListener("click",this.boundHandlers.handleClick)),s?.addEventListener("click",this.boundHandlers.handleSaveAll),this.container.addEventListener("click",this.boundHandlers.handleDelete),this.eventsBound=!0}handleAddMaterial(){const{addBtn:e,groupContainer:t,groupTemplate:s}=this.elements;if(!e||!t||!s)return;const i=parseInt(e.getAttribute("can-upload"))||0;t.querySelectorAll(".lp-material--group").length>=i||t.insertAdjacentHTML("afterbegin",s.innerHTML)}handleChange(e){const t=e.target;t.classList.contains("lp-material--field-method")&&this.handleMethodSwitch(t),t.classList.contains("lp-material--field-upload")&&this.validateFile(t)}handleMethodSwitch(e){const t=e.value,{uploadTemplate:s,externalTemplate:i}=this.elements;if(!s||!i)return;const n=e.closest(".lp-material--group");if(n)switch(t){case"upload":e.parentNode.insertAdjacentHTML("afterend",s.innerHTML),n.querySelector(".lp-material--external-wrap")?.remove();break;case"external":e.parentNode.insertAdjacentHTML("afterend",i.innerHTML),n.querySelector(".lp-material--upload-wrap")?.remove()}}validateFile(e){if(!e.value||!e.files?.length)return void this.resetUploadLabel(e);const t=e.files[0];return this.acceptFile.length>0&&!this.acceptFile.includes(t.type)?(alert("This file is not allowed! Please choose another file!"),e.value="",void this.resetUploadLabel(e)):t.size>1024*this.maxFileSize*1024?(alert(`This file size is greater than ${this.maxFileSize}MB! Please choose another file!`),e.value="",void this.resetUploadLabel(e)):void this.updateUploadLabel(e,t.name)}updateUploadLabel(e,t){if(!t)return;const s=e.closest(".lp-material--upload-wrap")?.querySelector("label");s&&(s.classList.add("has-selected-file"),s.setAttribute("data-file-name",t),s.setAttribute("title",t))}resetUploadLabel(e){const t=e?.closest(".lp-material--upload-wrap")?.querySelector("label");t&&(t.classList.remove("has-selected-file"),t.removeAttribute("data-file-name"),t.removeAttribute("title"))}handleClick(e){const t=e.target;if(t.classList.contains("lp-material--delete")&&"BUTTON"===t.nodeName)t.closest(".lp-material--group")?.remove();else if(t.classList.contains("lp-material-save-field")){const e=t.closest(".lp-material--group");e&&this.saveMaterial([e],!0,t)}}handleSaveAll(){const{groupContainer:e,saveBtn:t}=this.elements;if(!e)return;const s=Array.from(e.querySelectorAll(".lp-material--group"));s.length>0&&this.saveMaterial(s,!1,t)}async saveMaterial(e,t=!1,s){if(!e.length)return;const i=[],n=new FormData;let o=!0;for(const t of e){const e=t.querySelector(".lp-material--field-title")?.value,s=t.querySelector(".lp-material--field-method")?.value,a=t.querySelector(".lp-material--field-external-link"),r=t.querySelector(".lp-material--field-upload");if(!e){o=!1;break}let l="",c="";switch(s){case"upload":r?.value&&r.files?.length>0?(l=r.files[0].name,n.append("file[]",r.files[0])):o=!1;break;case"external":c=a?.value||"",c||(o=!1)}if(!o)break;i.push({label:e,method:s,file:l,link:c})}if(o){n.append("data",JSON.stringify(i)),s?.classList.add("loading");try{const s=`${this.getRestUrl()}lp/v1/material/item-materials/${this.postID}`,i=await fetch(s,{method:"POST",headers:{"X-WP-Nonce":this.getNonce()},body:n});if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);const o=await i.text();let a;try{a=JSON.parse(o)}catch(e){throw console.error("Response is not valid JSON:",o.substring(0,200)),new Error("Server returned invalid response. Check console for details.")}t?e[0].remove():e.forEach(e=>{e.querySelector(".lp-material--field-title").value="";const t=e.querySelector(".lp-material--field-upload");t&&(t.value="",this.resetUploadLabel(t));const s=e.querySelector(".lp-material--field-external-link");s&&(s.value="")});const{message:r,data:l,status:c}=a;if("success"===c&&l?.length>0){const{thead:e,tbody:t}=this.elements;if(e?.classList.remove("hidden"),t){const e=document.createDocumentFragment();l.forEach(t=>{e.appendChild(this.createRow(t))}),t.appendChild(e)}this.updateCanUploadCount(-l.length),this.initSortable()}}catch(e){console.error("Save material error:",e),alert("Error saving material: "+e.message)}finally{s?.classList.remove("loading")}}else alert("Enter file title, choose file or enter file link!")}async handleDelete(e){const t=e.target;if(!t.classList.contains("delete-material-row")||"A"!==t.nodeName)return;e.preventDefault();const s=t.dataset.id,i=this.elements.deleteMessage?.value||"Are you sure you want to delete this material?";if(confirm(i))try{const e=`${this.getRestUrl()}lp/v1/material/${s}`,i=await fetch(e,{method:"DELETE",headers:{"X-WP-Nonce":this.getNonce(),"Content-Type":"application/json"},body:JSON.stringify({item_id:this.postID})}),n=await i.json();200===n.status&&n.delete?(t.closest("tr")?.remove(),this.updateCanUploadCount(1)):alert(n.message)}catch(e){console.error("Delete material error:",e),alert("Error deleting material: "+e.message)}}updateCanUploadCount(e){const{canUpload:t,addBtn:s}=this.elements;if(t&&s){const i=parseInt(t.textContent)+e;t.textContent=i,s.setAttribute("can-upload",i)}}initSortable(){const{tbody:e}=this.elements;if(!e)return;this.destroySortable();const t=e.querySelectorAll("tr");this.boundHandlers.handleDragStart=e=>this.handleDragStart(e),this.boundHandlers.handleDragOver=e=>this.handleDragOver(e),this.boundHandlers.handleDrop=e=>this.handleDrop(e),this.boundHandlers.handleDragEnd=()=>this.handleDragEnd(),t.forEach(e=>{e.draggable=!0,e.addEventListener("dragstart",this.boundHandlers.handleDragStart),e.addEventListener("dragover",this.boundHandlers.handleDragOver),e.addEventListener("drop",this.boundHandlers.handleDrop),e.addEventListener("dragend",this.boundHandlers.handleDragEnd)}),this.sortable={tbody:e,rows:t}}handleDragStart(e){this.draggedElement=e.currentTarget,e.currentTarget.style.opacity="0.4",e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/html",e.currentTarget.innerHTML)}handleDragOver(e){e.preventDefault&&e.preventDefault(),e.dataTransfer.dropEffect="move";const t=e.currentTarget;if(this.draggedElement!==t){const s=t.getBoundingClientRect(),i=(e.clientY-s.top)/(s.bottom-s.top)>.5;t.parentNode.insertBefore(this.draggedElement,i?t.nextSibling:t)}return!1}handleDrop(e){return e.stopPropagation&&e.stopPropagation(),!1}handleDragEnd(){this.draggedElement.style.opacity="1",this.draggedElement=null,this.updateSort()}async updateSort(){const{tbody:e}=this.elements;if(!e)return;const t=e.querySelectorAll("tr"),s=Array.from(t).map((e,t)=>(e.dataset.sort=t+1,{file_id:parseInt(e.dataset.id),orders:t+1}));try{const e=`${this.getRestUrl()}lp/v1/material/item-materials/${this.postID}`,t=await fetch(e,{method:"PUT",headers:{"X-WP-Nonce":this.getNonce(),"Content-Type":"application/json"},body:JSON.stringify({sort_arr:JSON.stringify(s)})});200!==(await t.json()).status&&console.error("Sort table fail.")}catch(e){console.error("Update sort error:",e)}}getRestUrl(){return window.lpGlobalSettings?.rest||window.lpData?.lp_rest_url||"/wp-json/"}getNonce(){return window.lpGlobalSettings?.nonce||window.lpData?.nonce||""}destroySortable(){if(!this.sortable)return;const{rows:e}=this.sortable;e?.forEach(e=>{e.removeEventListener("dragstart",this.boundHandlers.handleDragStart),e.removeEventListener("dragover",this.boundHandlers.handleDragOver),e.removeEventListener("drop",this.boundHandlers.handleDrop),e.removeEventListener("dragend",this.boundHandlers.handleDragEnd)}),this.sortable=null}destroy(){const{addBtn:e,materialTab:t,saveBtn:s}=this.elements;e&&e.removeEventListener("click",this.boundHandlers.handleAddMaterial),t&&(t.removeEventListener("change",this.boundHandlers.handleChange),t.removeEventListener("click",this.boundHandlers.handleClick)),s&&s.removeEventListener("click",this.boundHandlers.handleSaveAll),this.container&&this.container.removeEventListener("click",this.boundHandlers.handleDelete),this.destroySortable(),this.boundHandlers={handleAddMaterial:null,handleChange:null,handleClick:null,handleSaveAll:null,handleDelete:null,handleDragStart:null,handleDragOver:null,handleDrop:null,handleDragEnd:null},this.elements={},this.initialized=!1,this.eventsBound=!1}}class X{constructor(){this.popupContainer=null,this.currentType=null,this.currentId=null,this.currentTemplate="",this.isNewItem=!1,this.savedData=null,this.openContext=this.getDefaultOpenContext(),this.builderEditQuiz=null,this.builderEditQuestion=null,this.builderMaterial=null,this.loadedTabAssets=new Set,this.initializedTabs=new Map,this.init()}static selectors={popupContainer:"#lp-builder-popup-container",popupOverlay:".lp-builder-popup-overlay",popup:".lp-builder-popup",closeBtn:".lp-builder-popup__close",resizeBtn:".lp-builder-popup__resize",cancelBtn:".lp-builder-popup__btn--cancel",saveBtn:".lp-builder-popup__btn--save",draftBtn:".lp-builder-popup__btn--draft",trashBtn:".lp-builder-popup__btn--trash",tabs:".lp-builder-popup__tabs",tab:".lp-builder-popup__tab",tabPane:".lp-builder-popup__tab-pane",permalinkSlugInput:".cb-permalink-slug-input",permalinkUrl:".cb-permalink-url",permalinkBaseUrl:"#cb-permalink-base-url",permalinkDisplay:".cb-permalink-display",permalinkEditor:".cb-permalink-editor",permalinkRoot:".cb-item-edit-permalink, .cb-course-edit-permalink",permalinkPlaceholder:".cb-item-edit-permalink__placeholder",popupTrigger:"[data-popup-lesson], [data-popup-quiz], [data-popup-question], [data-add-new-lesson], [data-template][data-popup-type]",triggerLesson:"[data-popup-lesson]",triggerQuiz:"[data-popup-quiz]",triggerQuestion:"[data-popup-question]",addNewLesson:"[data-add-new-lesson]"};init(){let e=document.querySelector(X.selectors.popupContainer);e||(e=document.createElement("div"),e.id="lp-builder-popup-container",document.body.appendChild(e)),this.popupContainer=e,this.events()}events(){X._loadedEvents||(X._loadedEvents=!0,e.eventHandlers("click",[{selector:X.selectors.popupTrigger,class:this,callBack:this.openPopup.name},{selector:`${X.selectors.closeBtn}, ${X.selectors.cancelBtn}, ${X.selectors.popupOverlay}`,class:this,callBack:this.closePopup.name,conditionBeforeCallBack:()=>this.isPopupOpen()},{selector:X.selectors.resizeBtn,class:this,callBack:this.toggleFullscreen.name,conditionBeforeCallBack:()=>this.isPopupOpen()},{selector:X.selectors.tab,class:this,callBack:this.switchTab.name,conditionBeforeCallBack:()=>this.isPopupOpen()},{selector:X.selectors.saveBtn,class:this,callBack:this.handleSave.name,conditionBeforeCallBack:()=>this.isPopupOpen()},{selector:X.selectors.draftBtn,class:this,callBack:this.handleDraft.name,conditionBeforeCallBack:()=>this.isPopupOpen()},{selector:X.selectors.trashBtn,class:this,callBack:this.handleTrash.name,conditionBeforeCallBack:()=>this.isPopupOpen()}]),e.eventHandlers("keydown",[{selector:"body",class:this,callBack:this.closePopup.name,conditionBeforeCallBack:e=>"Escape"===e.e.key&&this.isPopupOpen()}]))}toggleFullscreen(){const e=this.popupContainer.querySelector(X.selectors.popup);if(!e)return;e.classList.toggle("lp-builder-popup--fullscreen");const t=e.querySelector(X.selectors.resizeBtn);if(t){const s=t.querySelector("i");if(s){const t=e.classList.contains("lp-builder-popup--fullscreen");s.classList.toggle("lp-icon-expand",!t),s.classList.toggle("lp-icon-compress",t)}}document.dispatchEvent(new CustomEvent("lp-builder-popup-fullscreen-toggled",{detail:{isFullscreen:e.classList.contains("lp-builder-popup--fullscreen"),type:this.currentType,id:this.currentId}}))}openPopup(e){const{target:t}=e,s=t.closest(X.selectors.popupTrigger);if(!s)return;let i="",n=0;s.matches(X.selectors.addNewLesson)?i="lesson":s.dataset.popupType?(i=s.dataset.popupType,n=parseInt(s.dataset.popupId)||0):void 0!==s.dataset.popupLesson?(i="lesson",n=parseInt(s.dataset.popupLesson)||0):void 0!==s.dataset.popupQuiz?(i="quiz",n=parseInt(s.dataset.popupQuiz)||0):void 0!==s.dataset.popupQuestion&&(i="question",n=parseInt(s.dataset.popupQuestion)||0),i&&this.showPopup(s,i,n,this.resolveOpenContext(s))}getDefaultOpenContext(){return{isCurriculum:!1,courseId:0}}resolveOpenContext(e){const t=!!e?.closest("#lp-course-edit-curriculum")||!!e?.closest(".lp-edit-curriculum-wrap"),s=parseInt(e?.dataset?.courseId)||0;return{isCurriculum:t&&s>0,courseId:s}}showPopup(e,t,s,i=null){const n=e?.dataset?.template||"",o=document.querySelector(n);if(!n||!o)return;if(this.currentType=t,this.currentId=s,this.currentTemplate=n,this.isNewItem=0===s,this.openContext=i?{...i}:this.getDefaultOpenContext(),!this.popupContainer)return;this.popupContainer.innerHTML=o.innerHTML,this.popupContainer.classList.add("active"),document.body.classList.add("lp-popup-open");const a=this.popupContainer.querySelector(".lp-target");if(!a||!window.lpAJAXG)return;const r=window.lpAJAXG.getDataSetCurrent(a);r.args=r.args||{},r.args[`${t}_id`]=s,window.lpAJAXG.setDataSetCurrent(a,r),this.requestPopupContent(r)}reloadCurrentPopup(){if(!this.currentTemplate||!this.currentType)return;const e=document.querySelector(this.currentTemplate);if(!e)return;if(!this.popupContainer)return;this.popupContainer.innerHTML=e.innerHTML,this.popupContainer.classList.add("active"),document.body.classList.add("lp-popup-open");const t=this.popupContainer.querySelector(".lp-target");if(!t||!window.lpAJAXG)return;const s=window.lpAJAXG.getDataSetCurrent(t);s.args=s.args||{},s.args[`${this.currentType}_id`]=this.currentId,window.lpAJAXG.setDataSetCurrent(t,s),this.requestPopupContent(s)}requestPopupContent(e){if(!this.popupContainer||!window.lpAJAXG)return;const t={success:e=>{const{status:t,data:s}=e;if("success"===t&&s?.content){this.popupContainer.innerHTML=s.content,this.popupContainer.classList.add("active"),document.body.classList.add("lp-popup-open"),this.loadedTabAssets.clear(),this.initializedTabs.clear(),this.popupContainer.querySelectorAll(".lp-load-ajax-element.loaded").forEach(e=>e.classList.remove("loaded")),setTimeout(()=>window.lpAJAXG.getElements(),50);const e=this.popupContainer.querySelector(X.selectors.popup),t=e?.querySelector(`${X.selectors.tab}.active`),i=t?.dataset.tab||"overview",n=e?.querySelector(`${X.selectors.tabPane}[data-tab="${i}"]`);if(n&&this.loadTabAssets(i,n),"overview"===i&&setTimeout(()=>this.initTinyMCE(),50),"quiz"===this.currentType){if(this.builderEditQuiz||(this.builderEditQuiz=new R),"questions"===i){const e=`${this.currentType}-${i}`;setTimeout(()=>{this.triggerAjaxLoadForTab(n),this.builderEditQuiz.reinit(this.popupContainer),this.initializedTabs.set(e,!0)},100)}}else if("question"===this.currentType){if(this.builderEditQuestion||(this.builderEditQuestion=new V),"settings"===i){const e=`${this.currentType}-${i}`;setTimeout(()=>{this.triggerAjaxLoadForTab(n),this.builderEditQuestion.reinit(this.popupContainer),this.initializedTabs.set(e,!0)},100)}}else if("lesson"===this.currentType&&(this.builderMaterial||(this.builderMaterial=new U),"settings"===i)){const e=`${this.currentType}-${i}`;setTimeout(()=>{this.triggerAjaxLoadForTab(n),this.builderMaterial.reinit(this.popupContainer),this.initializedTabs.set(e,!0)},100)}document.dispatchEvent(new CustomEvent("lp-builder-popup-opened",{detail:{type:this.currentType,id:this.currentId,isNew:this.isNewItem}}))}else n.W(e.message||"Failed to load popup","error"),this.popupContainer.innerHTML="",this.popupContainer.classList.remove("active"),document.body.classList.remove("lp-popup-open")},error:e=>{n.W(e.message||"Failed to load popup","error"),this.popupContainer.innerHTML="",this.popupContainer.classList.remove("active"),document.body.classList.remove("lp-popup-open")},completed:()=>{}};window.lpAJAXG.fetchAJAX(e,t)}closePopup(){const e=this.currentType,t=this.currentId,s=this.savedData;this.destroyAllTinyMCE(),this.popupContainer.innerHTML="",this.popupContainer.classList.remove("active"),document.body.classList.remove("lp-popup-open"),this.loadedTabAssets.clear(),this.initializedTabs.clear(),s&&t&&this.updateListItem(e,t,s),document.dispatchEvent(new CustomEvent("lp-builder-popup-closed",{detail:{type:e,id:t,savedData:s}})),this.currentType=null,this.currentId=null,this.currentTemplate="",this.isNewItem=!1,this.savedData=null,this.openContext=this.getDefaultOpenContext()}updateListItem(e,t,s){if(!e||!t||!s)return;const{formData:i,data:n,wasNewItem:o}=s;let a=this.findListItems(e,t);if((!a||0===a.length)&&o){const s=this.insertNewListItem(e,t,n?.list_item_html);s&&(a=[s])}a&&0!==a.length&&(a.forEach(t=>{let s=t;if(n?.section_item_html&&s.classList.contains("section-item")){const e=document.createElement("template");e.innerHTML=n.section_item_html.trim();const t=e.content.firstElementChild;t&&(s.replaceWith(t),s=t)}else if(n?.list_item_html&&!s.classList.contains("section-item")){const e=document.createElement("template");e.innerHTML=n.list_item_html.trim();const t=e.content.firstElementChild;t&&(s.replaceWith(t),s=t)}else{const t=i[`${e}_title`];if(t&&this.updateElementText(s,[".item-title",".lp-item-title",`.lp-${e}-title`,".curriculum-item-title",".item-name","span.title",".lp-question-title-input",".section-item-title input",".section-item-title span",".lp-item-title-input"],t),n?.status&&this.updateElementClass(s,[`.${e}-status`,".item-status",".post-status"],n.status),"lesson"===e){const e=i._lp_duration||n?.duration;e&&this.updateDuration(s,e);const t=i._lp_preview||n?.preview,o="yes"===t||!0===t||"1"===t,a=s.querySelector(".lp-btn-set-preview-item a, .course-item-preview");a&&(o?(a.classList.remove("lp-icon-eye-slash"),a.classList.add("lp-icon-eye")):(a.classList.remove("lp-icon-eye"),a.classList.add("lp-icon-eye-slash")));const r=s.querySelector('input[type="checkbox"].preview-checkbox');r&&(r.checked=o),s.classList.toggle("is-preview",o),s.classList.toggle("preview-item",o)}else if("quiz"===e){const e=i._lp_duration||n?.duration;e&&this.updateDuration(s,e);const t=n?.question_count||n?.questions_count;if(null!=t){const e=s.querySelector(".question-count");e&&(e.textContent=`${t} ${1===t?"Question":"Questions"}`)}const o=i._lp_passing_grade||n?.passing_grade;if(o){const e=s.querySelector(".passing-grade");e&&(e.textContent=`${o}%`)}}else if("question"===e){const e=i._lp_type||n?.type;if(e){const t={true_or_false:"True or False",single_choice:"Single Choice",multi_choice:"Multi Choice",fill_in_blanks:"Fill in Blanks"};this.updateElementText(s,[".question-type",".item-type"],t[e]||e),["true_or_false","single_choice","multi_choice","fill_in_blanks"].forEach(e=>s.classList.remove(e)),s.classList.add(e)}const t=i._lp_mark||n?.mark;if(t){const e=s.querySelector(".question-mark");e&&(e.textContent=t)}}}}),document.dispatchEvent(new CustomEvent("lp-builder-list-item-updated",{detail:{type:e,id:t,formData:i,data:n}})))}findListItems(e,t){const s=[`[data-${e}-id="${t}"]`,`[data-id="${t}"]`,`[data-popup-${e}="${t}"]`,`[data-item-id="${t}"]`,`.section-item[data-item-id="${t}"]`,`.lp-${e}-item[data-id="${t}"]`],i=new Set;for(const t of s){const s=document.querySelectorAll(t);for(const t of s)t.closest("#lp-builder-popup-container")||(t.classList.contains("section-item")||t.classList.contains(`lp-${e}-item`)||t.classList.contains("list-item")||t.classList.contains("cb-list-item")||"LI"===t.tagName||t.closest("ul"))&&i.add(t)}return Array.from(i)}insertNewListItem(e,t,s){if(!s)return null;const i=this.findListItems(e,t);if(i&&i.length>0)return i[0];const n=this.findListContainer(e);if(!n)return null;const o=document.createElement("template");o.innerHTML=s.trim();const a=o.content.firstElementChild;if(!a)return null;n.prepend(a);const r={lesson:"highlight-new-lesson",quiz:"highlight-new-quiz",question:"highlight-new-question"}[e];r&&(a.classList.add(r),a.scrollIntoView({behavior:"smooth",block:"nearest"}),setTimeout(()=>{a.classList.remove(r)},1500));const l=this.findListItems(e,t);return l&&l.length>0?l[0]:a}findListContainer(e){const t={lesson:".cb-list-lesson",quiz:".cb-list-quiz",question:".cb-list-question"}[e]||`.cb-list-${e}, [data-builder-list="${e}"]`;if(!t)return null;const s=document.querySelector(t);if(s)return s;const i=document.querySelector({lesson:".courses-builder__lesson-tab",quiz:".courses-builder__quiz-tab",question:".courses-builder__question-tab"}[e]||`.courses-builder__${e}-tab, [data-builder-tab="${e}"]`),n={lesson:"cb-list-lesson",quiz:"cb-list-quiz",question:"cb-list-question"}[e]||`cb-list-${e}`;if(!i||!n)return null;const o=i.querySelector(".learn-press-message");o&&o.remove();const a=document.createElement("ul");return a.className=n,i.appendChild(a),a}updateElementText(e,t,s){for(const i of t){const t=e.querySelector(i);if(t)return"INPUT"===t.tagName?t.value=s:t.textContent=s,!0}return!1}updateElementClass(e,t,s){for(const i of t){const t=e.querySelector(i);if(t){const e=i.replace(".","");return t.className=t.className.replace(/\b(publish|draft|pending|trash)\b/g,"").trim(),t.classList.add(e,s),t.textContent=s,!0}}return!1}updateDuration(e,t){const s=this.formatDuration(t);if(!this.updateElementText(e,[".item-meta.duration",".duration",".course-item-duration",".meta-duration"],s)&&s){const t=e.querySelector(".course-item__right, .item-meta-container, .course-item-meta");if(t){let e=t.querySelector(".duration");e||(e=document.createElement("span"),e.className="duration",t.insertBefore(e,t.firstChild)),e.textContent=s}}}formatDuration(e){if(!e)return"";if("string"==typeof e&&e.match(/\d+\s+\w+/))return e;const t=String(e).trim().split(/\s+/);if(t.length>=2){const e=parseInt(t[0])||0,s=t[1].toLowerCase();return 0===e?"":`${e} ${{minute:1===e?"Minute":"Minutes",hour:1===e?"Hour":"Hours",day:1===e?"Day":"Days",week:1===e?"Week":"Weeks"}[s]||s}`}const s=parseInt(e)||0;return s>0?`${s} ${1===s?"Minute":"Minutes"}`:""}isPopupOpen(){return this.popupContainer?.classList.contains("active")}switchTab(e){const t=e?.target?e.target.closest(X.selectors.tab):e;if(!t)return;const s=t.dataset.tab,i=t.closest(X.selectors.popup);if(!i||!s)return;this.syncAllTinyMCE(),i.querySelectorAll(X.selectors.tab).forEach(e=>{e.classList.remove("active")}),t.classList.add("active"),i.querySelectorAll(X.selectors.tabPane).forEach(e=>{e.classList.remove("active")});const n=i.querySelector(`${X.selectors.tabPane}[data-tab="${s}"]`);if(!n)return;n.classList.add("active"),this.loadTabAssets(s,n);const o=`${this.currentType}-${s}`;this.initializedTabs.has(o)||("overview"===s?(setTimeout(()=>this.initTinyMCE(),100),this.initializedTabs.set(o,!0)):"questions"===s&&"quiz"===this.currentType?(this.triggerAjaxLoadForTab(n),this.builderEditQuiz&&setTimeout(()=>{this.builderEditQuiz.reinit(this.popupContainer),this.initializedTabs.set(o,!0)},100)):"settings"===s&&"question"===this.currentType?(this.triggerAjaxLoadForTab(n),this.builderEditQuestion&&setTimeout(()=>{this.builderEditQuestion.reinit(this.popupContainer),this.initializedTabs.set(o,!0)},100)):"settings"===s&&"lesson"===this.currentType&&(this.triggerAjaxLoadForTab(n),this.builderMaterial&&setTimeout(()=>{this.builderMaterial.reinit(this.popupContainer),this.initializedTabs.set(o,!0)},100))),document.dispatchEvent(new CustomEvent("lp-builder-tab-switched",{detail:{tabName:s,type:this.currentType,id:this.currentId}}))}triggerAjaxLoadForTab(e){if(!e||!window.lpAJAXG)return;const t=e.querySelectorAll(".lp-load-ajax-element:not(.loaded)");t.length>0&&(t.forEach(e=>e.classList.remove("loaded")),window.lpAJAXG.getElements())}initTinyMCE(){const e=`${this.currentType}_description_editor`;document.getElementById(e)&&"undefined"!=typeof tinymce&&(this.destroyTinyMCE(e),"undefined"!=typeof wp&&wp.editor?.initialize?wp.editor.initialize(e,{tinymce:{wpautop:!0,content_style:"body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif; font-size: 14px; line-height: 1.6; color: #1e1e1e; }",plugins:"charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wplink wptextpattern",toolbar1:"formatselect,bold,italic,underline,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,unlink,spellchecker,wp_adv",toolbar2:"strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help",wordpress_adv_hidden:!0},quicktags:{buttons:"strong,em,link,block,del,ins,img,ul,ol,li,code,more,close"},mediaButtons:!0}):tinymce.init({selector:"#"+e,height:300,menubar:!1,content_style:"body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif; font-size: 14px; line-height: 1.6; color: #1e1e1e; }",plugins:["advlist autolink lists link image charmap print preview anchor","searchreplace visualblocks code fullscreen","insertdatetime media table paste code help wordcount"],toolbar:"undo redo | formatselect | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | help"}))}syncAllTinyMCE(){if("undefined"==typeof tinymce||!this.currentType)return;const e=`${this.currentType}_description_editor`,t=tinymce.get(e);t&&!this.isEditorInCodeMode(e)&&t.save(),tinymce.editors.forEach(e=>{e.id?.includes(this.currentType)&&!this.isEditorInCodeMode(e.id)&&e.save()})}isEditorInCodeMode(e){const t=document.getElementById(`wp-${e}-wrap`)||document.getElementById(`${e}-wrap`);if(t?.classList.contains("html-active"))return!0;const s="undefined"!=typeof tinymce?tinymce.get(e):null;return!(!s?.isHidden||!s.isHidden())}getEditorContent(e,t=document){const s=t?.querySelector?.(`#${e}`)||document.getElementById(e);if(this.isEditorInCodeMode(e))return s?s.value:"";if("undefined"!=typeof tinymce){const t=tinymce.get(e);if(t)return t.getContent()}return s?s.value:""}destroyTinyMCE(e){if("undefined"!=typeof tinymce){const t=tinymce.get(e);t&&t.remove()}"undefined"!=typeof wp&&wp.editor?.remove&&wp.editor.remove(e)}destroyAllTinyMCE(){if(!this.currentType||"undefined"==typeof tinymce)return;const e=`${this.currentType}_description_editor`;this.destroyTinyMCE(e);const t=[];tinymce.editors.forEach(e=>{e.id&&this.popupContainer?.querySelector(`#${e.id}`)&&t.push(e.id)}),t.forEach(e=>this.destroyTinyMCE(e))}getStatusFromPublishPanel(e="publish"){if(!this.currentType||!this.popupContainer)return e;const t=this.popupContainer.querySelector(`#cb-${this.currentType}-publish-status`);if(!t)return e;const s=t.value;return"publish"===s||"draft"===s?s:e}syncPublishPanelStatus(e){if(!this.currentType||!this.popupContainer)return;const t=this.popupContainer.querySelector(`#cb-${this.currentType}-publish-status`);t&&(t.value="publish"===e?"publish":"draft")}handleSave(t){const s=t?.target?t.target.closest(X.selectors.saveBtn):t;if(!s)return;if(!this.currentType)return;const i=(s?.dataset?.titlePublish||"").toString().trim().toLowerCase(),o=(s?.textContent||"").toString().trim().toLowerCase(),a=!!i&&o===i,r=a?"publish":this.getStatusFromPublishPanel("publish");a&&this.syncPublishPanelStatus("publish"),this.syncAllTinyMCE();const l=this.getFormData(),c=this.validateFormData(l);if(!c.valid)return void n.W(c.errors.join(". "),"error");e.lpSetLoadingEl(s,1);const d=this.isNewItem,u={...l,action:{lesson:"builder_update_lesson",quiz:"builder_update_quiz",question:"builder_update_question"}[this.currentType]||`builder_update_${this.currentType}`,args:{id_url:`builder-update-${this.currentType}`},[`${this.currentType}_status`]:r,return_html:"yes"},h={success:e=>{const{status:t,message:s,data:i}=e;n.W(s,t),"success"===t&&this.handleSaveSuccess(i,l,d)},error:e=>{n.W(e.message||"Save failed","error")},completed:()=>{e.lpSetLoadingEl(s,0)}};window.lpAJAXG.fetchAJAX(u,h)}async handleDraft(t){const s=t?.target?t.target.closest(X.selectors.draftBtn):t;if(!s)return;if(!this.currentType)return;const a=this.popupContainer.querySelector(`.${this.currentType}-status`);if(a&&a.classList.contains("publish")){const e=s.dataset.confirmUnpublish||"Saving as draft will unpublish this item from the course.";if(!(await i().fire({title:"Are you sure?",text:e,iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0})).isConfirmed)return}this.syncAllTinyMCE();const r=this.getFormData(),l=this.validateFormData(r);if(!l.valid)return void n.W(l.errors.join(". "),"error");e.lpSetLoadingEl(s,1);const c=this.isNewItem,d={...r,action:{lesson:"builder_update_lesson",quiz:"builder_update_quiz",question:"builder_update_question"}[this.currentType]||`builder_update_${this.currentType}`,args:{id_url:`builder-update-${this.currentType}`},[`${this.currentType}_status`]:"draft",return_html:"yes"},u={success:e=>{const{status:t,message:s,data:i}=e;n.W(s,t),"success"===t&&this.handleSaveSuccess(i,r,c)},error:e=>{n.W(e.message||"Save draft failed","error")},completed:()=>{e.lpSetLoadingEl(s,0)}};window.lpAJAXG.fetchAJAX(d,u)}handleSaveSuccess(e,t,s){if(e?.button_title){const t=this.popupContainer.querySelector(X.selectors.saveBtn);t&&(t.textContent=e.button_title)}if(e?.status){this.syncPublishPanelStatus(e.status);const t=this.popupContainer.querySelector(`.${this.currentType}-status`);t&&(t.className=`${this.currentType}-status ${e.status}`,t.textContent=e.status),this.shouldRemoveFromCurriculum(e.status)&&this.removeItemFromCurriculum(this.currentId),this.shouldRemoveQuestionFromAssignedQuiz(e.status)&&this.removeQuestionFromAssignedQuiz(this.currentId)}this.updatePermalinkUIAfterSave(e);const i=`${this.currentType}_id_new`;if(e?.[i]){const t=e[i];this.currentId=t,this.isNewItem=!1;const s=this.popupContainer.querySelector(`[data-${this.currentType}-id]`);s&&(s.dataset[`${this.currentType}Id`]=t);const n=this.popupContainer.querySelector(X.selectors.popup);n&&(n.dataset[`${this.currentType}Id`]=t)}this.savedData={formData:t,data:e,wasNewItem:s},this.updateListItem(this.currentType,this.currentId,this.savedData),s&&this.currentId?(document.dispatchEvent(new CustomEvent("lp-builder-popup-saved",{detail:{type:this.currentType,id:this.currentId,data:e,formData:t,wasNewItem:s,listItemHtml:e?.list_item_html||null}})),setTimeout(()=>{this.destroyAllTinyMCE(),this.reloadCurrentPopup()},300)):document.dispatchEvent(new CustomEvent("lp-builder-popup-saved",{detail:{type:this.currentType,id:this.currentId,data:e,formData:t,wasNewItem:!1}}))}async handleTrash(t){const s=t?.target?t.target.closest(X.selectors.trashBtn):t;if(!s)return;if(!this.currentType||!this.currentId)return;const a=s.dataset.confirmTrash||"Moving it to the trash will cause this item to be removed from the course.";if(!(await i().fire({title:"Are you sure?",text:a,iconHtml:o,customClass:{icon:"lp-cb-swal-icon-html"},showCloseButton:!0,showCancelButton:!0,cancelButtonText:lpData.i18n.cancel,confirmButtonText:lpData.i18n.yes,reverseButtons:!0})).isConfirmed)return;e.lpSetLoadingEl(s,1);const r={action:{lesson:"move_trash_lesson",quiz:"move_trash_quiz",question:"move_trash_question"}[this.currentType]||`move_trash_${this.currentType}`,args:{id_url:`move-trash-${this.currentType}`},[`${this.currentType}_id`]:this.currentId};this.openContext?.isCurriculum&&(parseInt(this.openContext?.courseId)||0)>0&&(r.course_id=parseInt(this.openContext.courseId)||0);const l={success:e=>{const{status:t,message:s,data:i}=e;if(n.W(s,t),"success"===t){if(i?.button_title){const e=this.popupContainer.querySelector(X.selectors.saveBtn);e&&(e.textContent=i.button_title)}if(i?.status){const e=this.popupContainer.querySelector(`.${this.currentType}-status`);e&&(e.className=`${this.currentType}-status ${i.status}`,e.textContent=i.status),this.shouldRemoveFromCurriculum(i.status)&&this.removeItemFromCurriculum(this.currentId),this.shouldRemoveQuestionFromAssignedQuiz(i.status)&&this.removeQuestionFromAssignedQuiz(this.currentId)}this.updatePermalinkUIAfterSave(i),this.savedData={formData:this.getFormData(),data:i,wasNewItem:!1},document.dispatchEvent(new CustomEvent("lp-builder-popup-trashed",{detail:{type:this.currentType,id:this.currentId,data:i}}))}},error:e=>{n.W(e.message||"Trash failed","error")},completed:()=>{e.lpSetLoadingEl(s,0)}};window.lpAJAXG.fetchAJAX(r,l)}shouldRemoveFromCurriculum(e){const t=(e||"").toString().toLowerCase();return!!this.openContext?.isCurriculum&&["draft","trash"].includes(t)&&(parseInt(this.currentId)||0)>0}shouldRemoveQuestionFromAssignedQuiz(e){const t=(e||"").toString().toLowerCase();return"question"===this.currentType&&["draft","trash"].includes(t)&&(parseInt(this.currentId)||0)>0}removeItemFromCurriculum(e){const t=parseInt(e)||0;if(t<=0)return;const s=document.querySelector("#lp-course-edit-curriculum")||document.querySelector(".lp-edit-curriculum-wrap");if(!s)return;const i=s.querySelectorAll(`.section-item[data-item-id="${t}"]`);if(!i.length)return;const n=new Set;i.forEach(e=>{const t=e.closest(".section");t&&n.add(t),e.remove()}),this.syncCurriculumCounters(s,n)}removeQuestionFromAssignedQuiz(e){const t=parseInt(e)||0;t<=0||document.querySelectorAll(`.lp-question-item[data-question-id="${t}"]`).forEach(e=>e.remove())}syncCurriculumCounters(e,t=new Set){if(!e)return;const s=e.querySelectorAll(".section-item:not(.clone)").length,i=e.querySelector(".total-items");if(i){i.dataset.count=s;const e=i.querySelector(".count");e&&(e.textContent=s)}(t.size>0?Array.from(t):Array.from(e.querySelectorAll(".section"))).forEach(e=>{const t=e.querySelector(".section-items-counts");if(!t)return;const s=e.querySelectorAll(".section-item:not(.clone)").length;t.dataset.count=s;const i=t.querySelector(".count");i&&(i.textContent=s)})}validateFormData(e){const t=[],s=e[`${this.currentType}_title`]||"";return s.trim()||t.push(`${this.currentType.charAt(0).toUpperCase()+this.currentType.slice(1)} title is required`),s.length>200&&t.push("Title must be less than 200 characters"),{valid:0===t.length,errors:t}}getFormData(){const e={},t=this.popupContainer.querySelector(X.selectors.popup);if(!t)return e;e[`${this.currentType}_id`]=this.currentId||0,this.openContext?.isCurriculum&&(parseInt(this.openContext?.courseId)||0)>0&&(e.course_id=parseInt(this.openContext.courseId)||0);const s=t.querySelector('input[name$="_title"], #title, #'+this.currentType+"_title");s&&(e[`${this.currentType}_title`]=s.value);const i=`${this.currentType}_description_editor`,n=this.getEditorContent(i,t);e[`${this.currentType}_description`]=n;const o=t.querySelector(`.lp-form-setting-${this.currentType}`);o&&(e[`${this.currentType}_settings`]=!0,this.collectFormData(o,e));const a=t.querySelector(`input[name="${this.currentType}_permalink"], #${this.currentType}_permalink, ${X.selectors.permalinkSlugInput}`);return a&&a.value&&(e[`${this.currentType}_permalink`]=a.value),e}updatePermalinkUIAfterSave(e={}){if(!this.currentType||!this.popupContainer)return;const t=this.popupContainer.querySelector(X.selectors.popup);if(!t)return;const s=t.querySelector(`input[name="${this.currentType}_permalink"], #${this.currentType}_permalink, ${X.selectors.permalinkSlugInput}`),i=t.querySelector(X.selectors.permalinkRoot),n=i?.querySelector(X.selectors.permalinkPlaceholder),o=e?.[`${this.currentType}_slug`];s&&o&&(s.value=o,s.dataset.originalValue=o);const a=e?.[`${this.currentType}_permalink`],r=["lesson","quiz"].includes(this.currentType);if(!1===e?.permalink_available||r&&("draft"===e?.status||"trash"===e?.status||!a)){if(!i)return;const t=i.querySelector(X.selectors.permalinkDisplay),s=i.querySelector(".cb-item-edit-permalink__label")||i.querySelector(".cb-permalink-label"),o=i.querySelector(X.selectors.permalinkEditor);let a=n;return a||(a=document.createElement("span"),a.className="cb-item-edit-permalink__placeholder",s?s.insertAdjacentElement("afterend",a):i.prepend(a)),a.textContent=e?.permalink_notice||"Permalink is only available if the item is already assigned to a course.",a.classList.remove("lp-hidden"),t&&t.classList.add("lp-hidden"),void(o&&o.classList.add("lp-hidden"))}const l=t.querySelector(X.selectors.permalinkUrl),c=i?.querySelector(X.selectors.permalinkDisplay),d=t.querySelector(X.selectors.permalinkBaseUrl),u="string"==typeof d?.value?d.value:"",h="string"==typeof o?o.trim():"";let p="";u&&h?p=`${u}${h}`:"string"==typeof a&&(p=a),n&&n.classList.add("lp-hidden"),c&&c.classList.remove("lp-hidden"),l&&a?(l.href=a,l.textContent=p||a):l&&p&&(l.textContent=p)}collectFormData(e,t){e.querySelectorAll("input, select, textarea").forEach(e=>{const s=e.name||e.id;if(!s||"learnpress_meta_box_nonce"===s||"_wp_http_referer"===s)return;const i=s.replace("[]","");"checkbox"===e.type?t.hasOwnProperty(i)||(t[i]=e.checked?"yes":"no"):"radio"===e.type?e.checked&&(t[i]=e.value):"file"===e.type?e.files?.length>0&&(t[i]=e.files):s.endsWith("[]")?(t.hasOwnProperty(i)||(t[i]=[]),Array.isArray(t[i])&&t[i].push(e.value)):t.hasOwnProperty(i)||(t[i]=e.value)}),Object.keys(t).forEach(e=>{Array.isArray(t[e])&&(t[e]=t[e].join(","))})}loadTabAssets(e,t){const s=`${this.currentType}-${e}`;if(this.loadedTabAssets.has(s))return;const i=t.dataset.tabAssets;if(i)try{const e=JSON.parse(i);e.css&&Array.isArray(e.css)&&e.css.forEach(e=>{if(!document.querySelector(`link[href="${e}"]`)){const t=document.createElement("link");t.rel="stylesheet",t.href=e,t.dataset.tabAsset=s,document.head.appendChild(t)}}),e.js&&Array.isArray(e.js)&&e.js.forEach(e=>{if(!document.querySelector(`script[src="${e}"]`)){const t=document.createElement("script");t.src=e,t.dataset.tabAsset=s,document.head.appendChild(t)}}),this.loadedTabAssets.add(s)}catch(t){console.warn(`Failed to load assets for tab "${e}":`,t),this.loadedTabAssets.add(s)}else this.loadedTabAssets.add(s)}static open(e,t=0){X._instance||(X._instance=new X);const s={lesson:t?`[data-popup-lesson="${t}"]`:X.selectors.addNewLesson,quiz:t?`[data-popup-quiz="${t}"]`:"",question:t?`[data-popup-question="${t}"]`:""}[e]||(t?`[data-popup-type="${e}"][data-popup-id="${t}"]`:`[data-popup-type="${e}"][data-template]`);if(!s)return;const i=document.querySelector(s);i&&X._instance.showPopup(i,e,t,X._instance.resolveOpenContext(i))}static close(){X._instance&&X._instance.closePopup()}}function J(e){return e+.5|0}document.addEventListener("DOMContentLoaded",()=>{X._instance=new X});const G=(e,t,s)=>Math.max(Math.min(e,s),t);function Y(e){return G(J(2.55*e),0,255)}function K(e){return G(J(255*e),0,255)}function Z(e){return G(J(e/2.55)/100,0,1)}function ee(e){return G(J(100*e),0,100)}const te={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,A:10,B:11,C:12,D:13,E:14,F:15,a:10,b:11,c:12,d:13,e:14,f:15},se=[..."0123456789ABCDEF"],ie=e=>se[15&e],ne=e=>se[(240&e)>>4]+se[15&e],oe=e=>(240&e)>>4==(15&e);const ae=/^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;function re(e,t,s){const i=t*Math.min(s,1-s),n=(t,n=(t+e/30)%12)=>s-i*Math.max(Math.min(n-3,9-n,1),-1);return[n(0),n(8),n(4)]}function le(e,t,s){const i=(i,n=(i+e/60)%6)=>s-s*t*Math.max(Math.min(n,4-n,1),0);return[i(5),i(3),i(1)]}function ce(e,t,s){const i=re(e,1,.5);let n;for(t+s>1&&(n=1/(t+s),t*=n,s*=n),n=0;n<3;n++)i[n]*=1-t-s,i[n]+=t;return i}function de(e){const t=e.r/255,s=e.g/255,i=e.b/255,n=Math.max(t,s,i),o=Math.min(t,s,i),a=(n+o)/2;let r,l,c;return n!==o&&(c=n-o,l=a>.5?c/(2-n-o):c/(n+o),r=function(e,t,s,i,n){return e===n?(t-s)/i+(t<s?6:0):t===n?(s-e)/i+2:(e-t)/i+4}(t,s,i,c,n),r=60*r+.5),[0|r,l||0,a]}function ue(e,t,s,i){return(Array.isArray(t)?e(t[0],t[1],t[2]):e(t,s,i)).map(K)}function he(e,t,s){return ue(re,e,t,s)}function pe(e){return(e%360+360)%360}const me={x:"dark",Z:"light",Y:"re",X:"blu",W:"gr",V:"medium",U:"slate",A:"ee",T:"ol",S:"or",B:"ra",C:"lateg",D:"ights",R:"in",Q:"turquois",E:"hi",P:"ro",O:"al",N:"le",M:"de",L:"yello",F:"en",K:"ch",G:"arks",H:"ea",I:"ightg",J:"wh"},ge={OiceXe:"f0f8ff",antiquewEte:"faebd7",aqua:"ffff",aquamarRe:"7fffd4",azuY:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"0",blanKedOmond:"ffebcd",Xe:"ff",XeviTet:"8a2be2",bPwn:"a52a2a",burlywood:"deb887",caMtXe:"5f9ea0",KartYuse:"7fff00",KocTate:"d2691e",cSO:"ff7f50",cSnflowerXe:"6495ed",cSnsilk:"fff8dc",crimson:"dc143c",cyan:"ffff",xXe:"8b",xcyan:"8b8b",xgTMnPd:"b8860b",xWay:"a9a9a9",xgYF:"6400",xgYy:"a9a9a9",xkhaki:"bdb76b",xmagFta:"8b008b",xTivegYF:"556b2f",xSange:"ff8c00",xScEd:"9932cc",xYd:"8b0000",xsOmon:"e9967a",xsHgYF:"8fbc8f",xUXe:"483d8b",xUWay:"2f4f4f",xUgYy:"2f4f4f",xQe:"ced1",xviTet:"9400d3",dAppRk:"ff1493",dApskyXe:"bfff",dimWay:"696969",dimgYy:"696969",dodgerXe:"1e90ff",fiYbrick:"b22222",flSOwEte:"fffaf0",foYstWAn:"228b22",fuKsia:"ff00ff",gaRsbSo:"dcdcdc",ghostwEte:"f8f8ff",gTd:"ffd700",gTMnPd:"daa520",Way:"808080",gYF:"8000",gYFLw:"adff2f",gYy:"808080",honeyMw:"f0fff0",hotpRk:"ff69b4",RdianYd:"cd5c5c",Rdigo:"4b0082",ivSy:"fffff0",khaki:"f0e68c",lavFMr:"e6e6fa",lavFMrXsh:"fff0f5",lawngYF:"7cfc00",NmoncEffon:"fffacd",ZXe:"add8e6",ZcSO:"f08080",Zcyan:"e0ffff",ZgTMnPdLw:"fafad2",ZWay:"d3d3d3",ZgYF:"90ee90",ZgYy:"d3d3d3",ZpRk:"ffb6c1",ZsOmon:"ffa07a",ZsHgYF:"20b2aa",ZskyXe:"87cefa",ZUWay:"778899",ZUgYy:"778899",ZstAlXe:"b0c4de",ZLw:"ffffe0",lime:"ff00",limegYF:"32cd32",lRF:"faf0e6",magFta:"ff00ff",maPon:"800000",VaquamarRe:"66cdaa",VXe:"cd",VScEd:"ba55d3",VpurpN:"9370db",VsHgYF:"3cb371",VUXe:"7b68ee",VsprRggYF:"fa9a",VQe:"48d1cc",VviTetYd:"c71585",midnightXe:"191970",mRtcYam:"f5fffa",mistyPse:"ffe4e1",moccasR:"ffe4b5",navajowEte:"ffdead",navy:"80",Tdlace:"fdf5e6",Tive:"808000",TivedBb:"6b8e23",Sange:"ffa500",SangeYd:"ff4500",ScEd:"da70d6",pOegTMnPd:"eee8aa",pOegYF:"98fb98",pOeQe:"afeeee",pOeviTetYd:"db7093",papayawEp:"ffefd5",pHKpuff:"ffdab9",peru:"cd853f",pRk:"ffc0cb",plum:"dda0dd",powMrXe:"b0e0e6",purpN:"800080",YbeccapurpN:"663399",Yd:"ff0000",Psybrown:"bc8f8f",PyOXe:"4169e1",saddNbPwn:"8b4513",sOmon:"fa8072",sandybPwn:"f4a460",sHgYF:"2e8b57",sHshell:"fff5ee",siFna:"a0522d",silver:"c0c0c0",skyXe:"87ceeb",UXe:"6a5acd",UWay:"708090",UgYy:"708090",snow:"fffafa",sprRggYF:"ff7f",stAlXe:"4682b4",tan:"d2b48c",teO:"8080",tEstN:"d8bfd8",tomato:"ff6347",Qe:"40e0d0",viTet:"ee82ee",JHt:"f5deb3",wEte:"ffffff",wEtesmoke:"f5f5f5",Lw:"ffff00",LwgYF:"9acd32"};let fe;const be=/^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/,ve=e=>e<=.0031308?12.92*e:1.055*Math.pow(e,1/2.4)-.055,ye=e=>e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4);function we(e,t,s){if(e){let i=de(e);i[t]=Math.max(0,Math.min(i[t]+i[t]*s,0===t?360:1)),i=he(i),e.r=i[0],e.g=i[1],e.b=i[2]}}function _e(e,t){return e?Object.assign(t||{},e):e}function xe(e){var t={r:0,g:0,b:0,a:255};return Array.isArray(e)?e.length>=3&&(t={r:e[0],g:e[1],b:e[2],a:255},e.length>3&&(t.a=K(e[3]))):(t=_e(e,{r:0,g:0,b:0,a:1})).a=K(t.a),t}function Se(e){return"r"===e.charAt(0)?function(e){const t=be.exec(e);let s,i,n,o=255;if(t){if(t[7]!==s){const e=+t[7];o=t[8]?Y(e):G(255*e,0,255)}return s=+t[1],i=+t[3],n=+t[5],s=255&(t[2]?Y(s):G(s,0,255)),i=255&(t[4]?Y(i):G(i,0,255)),n=255&(t[6]?Y(n):G(n,0,255)),{r:s,g:i,b:n,a:o}}}(e):function(e){const t=ae.exec(e);let s,i=255;if(!t)return;t[5]!==s&&(i=t[6]?Y(+t[5]):K(+t[5]));const n=pe(+t[2]),o=+t[3]/100,a=+t[4]/100;return s="hwb"===t[1]?function(e,t,s){return ue(ce,e,t,s)}(n,o,a):"hsv"===t[1]?function(e,t,s){return ue(le,e,t,s)}(n,o,a):he(n,o,a),{r:s[0],g:s[1],b:s[2],a:i}}(e)}class Ce{constructor(e){if(e instanceof Ce)return e;const t=typeof e;let s;var i,n,o;"object"===t?s=xe(e):"string"===t&&(o=(i=e).length,"#"===i[0]&&(4===o||5===o?n={r:255&17*te[i[1]],g:255&17*te[i[2]],b:255&17*te[i[3]],a:5===o?17*te[i[4]]:255}:7!==o&&9!==o||(n={r:te[i[1]]<<4|te[i[2]],g:te[i[3]]<<4|te[i[4]],b:te[i[5]]<<4|te[i[6]],a:9===o?te[i[7]]<<4|te[i[8]]:255})),s=n||function(e){fe||(fe=function(){const e={},t=Object.keys(ge),s=Object.keys(me);let i,n,o,a,r;for(i=0;i<t.length;i++){for(a=r=t[i],n=0;n<s.length;n++)o=s[n],r=r.replace(o,me[o]);o=parseInt(ge[a],16),e[r]=[o>>16&255,o>>8&255,255&o]}return e}(),fe.transparent=[0,0,0,0]);const t=fe[e.toLowerCase()];return t&&{r:t[0],g:t[1],b:t[2],a:4===t.length?t[3]:255}}(e)||Se(e)),this._rgb=s,this._valid=!!s}get valid(){return this._valid}get rgb(){var e=_e(this._rgb);return e&&(e.a=Z(e.a)),e}set rgb(e){this._rgb=xe(e)}rgbString(){return this._valid?(e=this._rgb)&&(e.a<255?`rgba(${e.r}, ${e.g}, ${e.b}, ${Z(e.a)})`:`rgb(${e.r}, ${e.g}, ${e.b})`):void 0;var e}hexString(){return this._valid?(e=this._rgb,t=(e=>oe(e.r)&&oe(e.g)&&oe(e.b)&&oe(e.a))(e)?ie:ne,e?"#"+t(e.r)+t(e.g)+t(e.b)+((e,t)=>e<255?t(e):"")(e.a,t):void 0):void 0;var e,t}hslString(){return this._valid?function(e){if(!e)return;const t=de(e),s=t[0],i=ee(t[1]),n=ee(t[2]);return e.a<255?`hsla(${s}, ${i}%, ${n}%, ${Z(e.a)})`:`hsl(${s}, ${i}%, ${n}%)`}(this._rgb):void 0}mix(e,t){if(e){const s=this.rgb,i=e.rgb;let n;const o=t===n?.5:t,a=2*o-1,r=s.a-i.a,l=((a*r===-1?a:(a+r)/(1+a*r))+1)/2;n=1-l,s.r=255&l*s.r+n*i.r+.5,s.g=255&l*s.g+n*i.g+.5,s.b=255&l*s.b+n*i.b+.5,s.a=o*s.a+(1-o)*i.a,this.rgb=s}return this}interpolate(e,t){return e&&(this._rgb=function(e,t,s){const i=ye(Z(e.r)),n=ye(Z(e.g)),o=ye(Z(e.b));return{r:K(ve(i+s*(ye(Z(t.r))-i))),g:K(ve(n+s*(ye(Z(t.g))-n))),b:K(ve(o+s*(ye(Z(t.b))-o))),a:e.a+s*(t.a-e.a)}}(this._rgb,e._rgb,t)),this}clone(){return new Ce(this.rgb)}alpha(e){return this._rgb.a=K(e),this}clearer(e){return this._rgb.a*=1-e,this}greyscale(){const e=this._rgb,t=J(.3*e.r+.59*e.g+.11*e.b);return e.r=e.g=e.b=t,this}opaquer(e){return this._rgb.a*=1+e,this}negate(){const e=this._rgb;return e.r=255-e.r,e.g=255-e.g,e.b=255-e.b,this}lighten(e){return we(this._rgb,2,e),this}darken(e){return we(this._rgb,2,-e),this}saturate(e){return we(this._rgb,1,e),this}desaturate(e){return we(this._rgb,1,-e),this}rotate(e){return function(e,t){var s=de(e);s[0]=pe(s[0]+t),s=he(s),e.r=s[0],e.g=s[1],e.b=s[2]}(this._rgb,e),this}}function ke(){}const Ae=(()=>{let e=0;return()=>e++})();function Ee(e){return null==e}function Te(e){if(Array.isArray&&Array.isArray(e))return!0;const t=Object.prototype.toString.call(e);return"[object"===t.slice(0,7)&&"Array]"===t.slice(-6)}function Le(e){return null!==e&&"[object Object]"===Object.prototype.toString.call(e)}function Ie(e){return("number"==typeof e||e instanceof Number)&&isFinite(+e)}function De(e,t){return Ie(e)?e:t}function qe(e,t){return void 0===e?t:e}const Be=(e,t)=>"string"==typeof e&&e.endsWith("%")?parseFloat(e)/100*t:+e;function Pe(e,t,s){if(e&&"function"==typeof e.call)return e.apply(s,t)}function Me(e,t,s,i){let n,o,a;if(Te(e))if(o=e.length,i)for(n=o-1;n>=0;n--)t.call(s,e[n],n);else for(n=0;n<o;n++)t.call(s,e[n],n);else if(Le(e))for(a=Object.keys(e),o=a.length,n=0;n<o;n++)t.call(s,e[a[n]],a[n])}function Oe(e,t){let s,i,n,o;if(!e||!t||e.length!==t.length)return!1;for(s=0,i=e.length;s<i;++s)if(n=e[s],o=t[s],n.datasetIndex!==o.datasetIndex||n.index!==o.index)return!1;return!0}function ze(e){if(Te(e))return e.map(ze);if(Le(e)){const t=Object.create(null),s=Object.keys(e),i=s.length;let n=0;for(;n<i;++n)t[s[n]]=ze(e[s[n]]);return t}return e}function $e(e){return-1===["__proto__","prototype","constructor"].indexOf(e)}function Fe(e,t,s,i){if(!$e(e))return;const n=t[e],o=s[e];Le(n)&&Le(o)?He(n,o,i):t[e]=ze(o)}function He(e,t,s){const i=Te(t)?t:[t],n=i.length;if(!Le(e))return e;const o=(s=s||{}).merger||Fe;let a;for(let t=0;t<n;++t){if(a=i[t],!Le(a))continue;const n=Object.keys(a);for(let t=0,i=n.length;t<i;++t)o(n[t],e,a,s)}return e}function Qe(e,t){return He(e,t,{merger:Ne})}function Ne(e,t,s){if(!$e(e))return;const i=t[e],n=s[e];Le(i)&&Le(n)?Qe(i,n):Object.prototype.hasOwnProperty.call(t,e)||(t[e]=ze(n))}const Re={"":e=>e,x:e=>e.x,y:e=>e.y};function We(e,t){const s=Re[t]||(Re[t]=function(e){const t=function(e){const t=e.split("."),s=[];let i="";for(const e of t)i+=e,i.endsWith("\\")?i=i.slice(0,-1)+".":(s.push(i),i="");return s}(e);return e=>{for(const s of t){if(""===s)break;e=e&&e[s]}return e}}(t));return s(e)}function je(e){return e.charAt(0).toUpperCase()+e.slice(1)}const Ve=e=>void 0!==e,Ue=e=>"function"==typeof e,Xe=(e,t)=>{if(e.size!==t.size)return!1;for(const s of e)if(!t.has(s))return!1;return!0},Je=Math.PI,Ge=2*Je,Ye=Ge+Je,Ke=Number.POSITIVE_INFINITY,Ze=Je/180,et=Je/2,tt=Je/4,st=2*Je/3,it=Math.log10,nt=Math.sign;function ot(e,t,s){return Math.abs(e-t)<s}function at(e){const t=Math.round(e);e=ot(e,t,e/1e3)?t:e;const s=Math.pow(10,Math.floor(it(e))),i=e/s;return(i<=1?1:i<=2?2:i<=5?5:10)*s}function rt(e){return!function(e){return"symbol"==typeof e||"object"==typeof e&&null!==e&&!(Symbol.toPrimitive in e||"toString"in e||"valueOf"in e)}(e)&&!isNaN(parseFloat(e))&&isFinite(e)}function lt(e,t,s){let i,n,o;for(i=0,n=e.length;i<n;i++)o=e[i][s],isNaN(o)||(t.min=Math.min(t.min,o),t.max=Math.max(t.max,o))}function ct(e){return e*(Je/180)}function dt(e){return e*(180/Je)}function ut(e){if(!Ie(e))return;let t=1,s=0;for(;Math.round(e*t)/t!==e;)t*=10,s++;return s}function ht(e,t){const s=t.x-e.x,i=t.y-e.y,n=Math.sqrt(s*s+i*i);let o=Math.atan2(i,s);return o<-.5*Je&&(o+=Ge),{angle:o,distance:n}}function pt(e,t){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function mt(e,t){return(e-t+Ye)%Ge-Je}function gt(e){return(e%Ge+Ge)%Ge}function ft(e,t,s,i){const n=gt(e),o=gt(t),a=gt(s),r=gt(o-n),l=gt(a-n),c=gt(n-o),d=gt(n-a);return n===o||n===a||i&&o===a||r>l&&c<d}function bt(e,t,s){return Math.max(t,Math.min(s,e))}function vt(e,t,s,i=1e-6){return e>=Math.min(t,s)-i&&e<=Math.max(t,s)+i}function yt(e,t,s){s=s||(s=>e[s]<t);let i,n=e.length-1,o=0;for(;n-o>1;)i=o+n>>1,s(i)?o=i:n=i;return{lo:o,hi:n}}const wt=(e,t,s,i)=>yt(e,s,i?i=>{const n=e[i][t];return n<s||n===s&&e[i+1][t]===s}:i=>e[i][t]<s),_t=(e,t,s)=>yt(e,s,i=>e[i][t]>=s),xt=["push","pop","shift","splice","unshift"];function St(e,t){const s=e._chartjs;if(!s)return;const i=s.listeners,n=i.indexOf(t);-1!==n&&i.splice(n,1),i.length>0||(xt.forEach(t=>{delete e[t]}),delete e._chartjs)}function Ct(e){const t=new Set(e);return t.size===e.length?e:Array.from(t)}const kt="undefined"==typeof window?function(e){return e()}:window.requestAnimationFrame;function At(e,t){let s=[],i=!1;return function(...n){s=n,i||(i=!0,kt.call(window,()=>{i=!1,e.apply(t,s)}))}}const Et=e=>"start"===e?"left":"end"===e?"right":"center",Tt=(e,t,s)=>"start"===e?t:"end"===e?s:(t+s)/2;function Lt(e,t,s){const i=t.length;let n=0,o=i;if(e._sorted){const{iScale:a,vScale:r,_parsed:l}=e,c=e.dataset&&e.dataset.options?e.dataset.options.spanGaps:null,d=a.axis,{min:u,max:h,minDefined:p,maxDefined:m}=a.getUserBounds();if(p){if(n=Math.min(wt(l,d,u).lo,s?i:wt(t,d,a.getPixelForValue(u)).lo),c){const e=l.slice(0,n+1).reverse().findIndex(e=>!Ee(e[r.axis]));n-=Math.max(0,e)}n=bt(n,0,i-1)}if(m){let e=Math.max(wt(l,a.axis,h,!0).hi+1,s?0:wt(t,d,a.getPixelForValue(h),!0).hi+1);if(c){const t=l.slice(e-1).findIndex(e=>!Ee(e[r.axis]));e+=Math.max(0,t)}o=bt(e,n,i)-n}else o=i-n}return{start:n,count:o}}function It(e){const{xScale:t,yScale:s,_scaleRanges:i}=e,n={xmin:t.min,xmax:t.max,ymin:s.min,ymax:s.max};if(!i)return e._scaleRanges=n,!0;const o=i.xmin!==t.min||i.xmax!==t.max||i.ymin!==s.min||i.ymax!==s.max;return Object.assign(i,n),o}const Dt=e=>0===e||1===e,qt=(e,t,s)=>-Math.pow(2,10*(e-=1))*Math.sin((e-t)*Ge/s),Bt=(e,t,s)=>Math.pow(2,-10*e)*Math.sin((e-t)*Ge/s)+1,Pt={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>-e*(e-2),easeInOutQuad:e=>(e/=.5)<1?.5*e*e:-.5*(--e*(e-2)-1),easeInCubic:e=>e*e*e,easeOutCubic:e=>(e-=1)*e*e+1,easeInOutCubic:e=>(e/=.5)<1?.5*e*e*e:.5*((e-=2)*e*e+2),easeInQuart:e=>e*e*e*e,easeOutQuart:e=>-((e-=1)*e*e*e-1),easeInOutQuart:e=>(e/=.5)<1?.5*e*e*e*e:-.5*((e-=2)*e*e*e-2),easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>(e-=1)*e*e*e*e+1,easeInOutQuint:e=>(e/=.5)<1?.5*e*e*e*e*e:.5*((e-=2)*e*e*e*e+2),easeInSine:e=>1-Math.cos(e*et),easeOutSine:e=>Math.sin(e*et),easeInOutSine:e=>-.5*(Math.cos(Je*e)-1),easeInExpo:e=>0===e?0:Math.pow(2,10*(e-1)),easeOutExpo:e=>1===e?1:1-Math.pow(2,-10*e),easeInOutExpo:e=>Dt(e)?e:e<.5?.5*Math.pow(2,10*(2*e-1)):.5*(2-Math.pow(2,-10*(2*e-1))),easeInCirc:e=>e>=1?e:-(Math.sqrt(1-e*e)-1),easeOutCirc:e=>Math.sqrt(1-(e-=1)*e),easeInOutCirc:e=>(e/=.5)<1?-.5*(Math.sqrt(1-e*e)-1):.5*(Math.sqrt(1-(e-=2)*e)+1),easeInElastic:e=>Dt(e)?e:qt(e,.075,.3),easeOutElastic:e=>Dt(e)?e:Bt(e,.075,.3),easeInOutElastic(e){const t=.1125;return Dt(e)?e:e<.5?.5*qt(2*e,t,.45):.5+.5*Bt(2*e-1,t,.45)},easeInBack(e){const t=1.70158;return e*e*((t+1)*e-t)},easeOutBack(e){const t=1.70158;return(e-=1)*e*((t+1)*e+t)+1},easeInOutBack(e){let t=1.70158;return(e/=.5)<1?e*e*((1+(t*=1.525))*e-t)*.5:.5*((e-=2)*e*((1+(t*=1.525))*e+t)+2)},easeInBounce:e=>1-Pt.easeOutBounce(1-e),easeOutBounce(e){const t=7.5625,s=2.75;return e<1/s?t*e*e:e<2/s?t*(e-=1.5/s)*e+.75:e<2.5/s?t*(e-=2.25/s)*e+.9375:t*(e-=2.625/s)*e+.984375},easeInOutBounce:e=>e<.5?.5*Pt.easeInBounce(2*e):.5*Pt.easeOutBounce(2*e-1)+.5};function Mt(e){if(e&&"object"==typeof e){const t=e.toString();return"[object CanvasPattern]"===t||"[object CanvasGradient]"===t}return!1}function Ot(e){return Mt(e)?e:new Ce(e)}function zt(e){return Mt(e)?e:new Ce(e).saturate(.5).darken(.1).hexString()}const $t=["x","y","borderWidth","radius","tension"],Ft=["color","borderColor","backgroundColor"],Ht=new Map;function Qt(e,t,s){return function(e,t){t=t||{};const s=e+JSON.stringify(t);let i=Ht.get(s);return i||(i=new Intl.NumberFormat(e,t),Ht.set(s,i)),i}(t,s).format(e)}const Nt={values:e=>Te(e)?e:""+e,numeric(e,t,s){if(0===e)return"0";const i=this.chart.options.locale;let n,o=e;if(s.length>1){const t=Math.max(Math.abs(s[0].value),Math.abs(s[s.length-1].value));(t<1e-4||t>1e15)&&(n="scientific"),o=function(e,t){let s=t.length>3?t[2].value-t[1].value:t[1].value-t[0].value;return Math.abs(s)>=1&&e!==Math.floor(e)&&(s=e-Math.floor(e)),s}(e,s)}const a=it(Math.abs(o)),r=isNaN(a)?1:Math.max(Math.min(-1*Math.floor(a),20),0),l={notation:n,minimumFractionDigits:r,maximumFractionDigits:r};return Object.assign(l,this.options.ticks.format),Qt(e,i,l)},logarithmic(e,t,s){if(0===e)return"0";const i=s[t].significand||e/Math.pow(10,Math.floor(it(e)));return[1,2,3,5,10,15].includes(i)||t>.8*s.length?Nt.numeric.call(this,e,t,s):""}};var Rt={formatters:Nt};const Wt=Object.create(null),jt=Object.create(null);function Vt(e,t){if(!t)return e;const s=t.split(".");for(let t=0,i=s.length;t<i;++t){const i=s[t];e=e[i]||(e[i]=Object.create(null))}return e}function Ut(e,t,s){return"string"==typeof t?He(Vt(e,t),s):He(Vt(e,""),t)}class Xt{constructor(e,t){this.animation=void 0,this.backgroundColor="rgba(0,0,0,0.1)",this.borderColor="rgba(0,0,0,0.1)",this.color="#666",this.datasets={},this.devicePixelRatio=e=>e.chart.platform.getDevicePixelRatio(),this.elements={},this.events=["mousemove","mouseout","click","touchstart","touchmove"],this.font={family:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",size:12,style:"normal",lineHeight:1.2,weight:null},this.hover={},this.hoverBackgroundColor=(e,t)=>zt(t.backgroundColor),this.hoverBorderColor=(e,t)=>zt(t.borderColor),this.hoverColor=(e,t)=>zt(t.color),this.indexAxis="x",this.interaction={mode:"nearest",intersect:!0,includeInvisible:!1},this.maintainAspectRatio=!0,this.onHover=null,this.onClick=null,this.parsing=!0,this.plugins={},this.responsive=!0,this.scale=void 0,this.scales={},this.showLine=!0,this.drawActiveElementsOnTop=!0,this.describe(e),this.apply(t)}set(e,t){return Ut(this,e,t)}get(e){return Vt(this,e)}describe(e,t){return Ut(jt,e,t)}override(e,t){return Ut(Wt,e,t)}route(e,t,s,i){const n=Vt(this,e),o=Vt(this,s),a="_"+t;Object.defineProperties(n,{[a]:{value:n[t],writable:!0},[t]:{enumerable:!0,get(){const e=this[a],t=o[i];return Le(e)?Object.assign({},t,e):qe(e,t)},set(e){this[a]=e}}})}apply(e){e.forEach(e=>e(this))}}var Jt=new Xt({_scriptable:e=>!e.startsWith("on"),_indexable:e=>"events"!==e,hover:{_fallback:"interaction"},interaction:{_scriptable:!1,_indexable:!1}},[function(e){e.set("animation",{delay:void 0,duration:1e3,easing:"easeOutQuart",fn:void 0,from:void 0,loop:void 0,to:void 0,type:void 0}),e.describe("animation",{_fallback:!1,_indexable:!1,_scriptable:e=>"onProgress"!==e&&"onComplete"!==e&&"fn"!==e}),e.set("animations",{colors:{type:"color",properties:Ft},numbers:{type:"number",properties:$t}}),e.describe("animations",{_fallback:"animation"}),e.set("transitions",{active:{animation:{duration:400}},resize:{animation:{duration:0}},show:{animations:{colors:{from:"transparent"},visible:{type:"boolean",duration:0}}},hide:{animations:{colors:{to:"transparent"},visible:{type:"boolean",easing:"linear",fn:e=>0|e}}}})},function(e){e.set("layout",{autoPadding:!0,padding:{top:0,right:0,bottom:0,left:0}})},function(e){e.set("scale",{display:!0,offset:!1,reverse:!1,beginAtZero:!1,bounds:"ticks",clip:!0,grace:0,grid:{display:!0,lineWidth:1,drawOnChartArea:!0,drawTicks:!0,tickLength:8,tickWidth:(e,t)=>t.lineWidth,tickColor:(e,t)=>t.color,offset:!1},border:{display:!0,dash:[],dashOffset:0,width:1},title:{display:!1,text:"",padding:{top:4,bottom:4}},ticks:{minRotation:0,maxRotation:50,mirror:!1,textStrokeWidth:0,textStrokeColor:"",padding:3,display:!0,autoSkip:!0,autoSkipPadding:3,labelOffset:0,callback:Rt.formatters.values,minor:{},major:{},align:"center",crossAlign:"near",showLabelBackdrop:!1,backdropColor:"rgba(255, 255, 255, 0.75)",backdropPadding:2}}),e.route("scale.ticks","color","","color"),e.route("scale.grid","color","","borderColor"),e.route("scale.border","color","","borderColor"),e.route("scale.title","color","","color"),e.describe("scale",{_fallback:!1,_scriptable:e=>!e.startsWith("before")&&!e.startsWith("after")&&"callback"!==e&&"parser"!==e,_indexable:e=>"borderDash"!==e&&"tickBorderDash"!==e&&"dash"!==e}),e.describe("scales",{_fallback:"scale"}),e.describe("scale.ticks",{_scriptable:e=>"backdropPadding"!==e&&"callback"!==e,_indexable:e=>"backdropPadding"!==e})}]);function Gt(e,t,s,i,n){let o=t[n];return o||(o=t[n]=e.measureText(n).width,s.push(n)),o>i&&(i=o),i}function Yt(e,t,s,i){let n=(i=i||{}).data=i.data||{},o=i.garbageCollect=i.garbageCollect||[];i.font!==t&&(n=i.data={},o=i.garbageCollect=[],i.font=t),e.save(),e.font=t;let a=0;const r=s.length;let l,c,d,u,h;for(l=0;l<r;l++)if(u=s[l],null==u||Te(u)){if(Te(u))for(c=0,d=u.length;c<d;c++)h=u[c],null==h||Te(h)||(a=Gt(e,n,o,a,h))}else a=Gt(e,n,o,a,u);e.restore();const p=o.length/2;if(p>s.length){for(l=0;l<p;l++)delete n[o[l]];o.splice(0,p)}return a}function Kt(e,t,s){const i=e.currentDevicePixelRatio,n=0!==s?Math.max(s/2,.5):0;return Math.round((t-n)*i)/i+n}function Zt(e,t){(t||e)&&((t=t||e.getContext("2d")).save(),t.resetTransform(),t.clearRect(0,0,e.width,e.height),t.restore())}function es(e,t,s,i){ts(e,t,s,i,null)}function ts(e,t,s,i,n){let o,a,r,l,c,d,u,h;const p=t.pointStyle,m=t.rotation,g=t.radius;let f=(m||0)*Ze;if(p&&"object"==typeof p&&(o=p.toString(),"[object HTMLImageElement]"===o||"[object HTMLCanvasElement]"===o))return e.save(),e.translate(s,i),e.rotate(f),e.drawImage(p,-p.width/2,-p.height/2,p.width,p.height),void e.restore();if(!(isNaN(g)||g<=0)){switch(e.beginPath(),p){default:n?e.ellipse(s,i,n/2,g,0,0,Ge):e.arc(s,i,g,0,Ge),e.closePath();break;case"triangle":d=n?n/2:g,e.moveTo(s+Math.sin(f)*d,i-Math.cos(f)*g),f+=st,e.lineTo(s+Math.sin(f)*d,i-Math.cos(f)*g),f+=st,e.lineTo(s+Math.sin(f)*d,i-Math.cos(f)*g),e.closePath();break;case"rectRounded":c=.516*g,l=g-c,a=Math.cos(f+tt)*l,u=Math.cos(f+tt)*(n?n/2-c:l),r=Math.sin(f+tt)*l,h=Math.sin(f+tt)*(n?n/2-c:l),e.arc(s-u,i-r,c,f-Je,f-et),e.arc(s+h,i-a,c,f-et,f),e.arc(s+u,i+r,c,f,f+et),e.arc(s-h,i+a,c,f+et,f+Je),e.closePath();break;case"rect":if(!m){l=Math.SQRT1_2*g,d=n?n/2:l,e.rect(s-d,i-l,2*d,2*l);break}f+=tt;case"rectRot":u=Math.cos(f)*(n?n/2:g),a=Math.cos(f)*g,r=Math.sin(f)*g,h=Math.sin(f)*(n?n/2:g),e.moveTo(s-u,i-r),e.lineTo(s+h,i-a),e.lineTo(s+u,i+r),e.lineTo(s-h,i+a),e.closePath();break;case"crossRot":f+=tt;case"cross":u=Math.cos(f)*(n?n/2:g),a=Math.cos(f)*g,r=Math.sin(f)*g,h=Math.sin(f)*(n?n/2:g),e.moveTo(s-u,i-r),e.lineTo(s+u,i+r),e.moveTo(s+h,i-a),e.lineTo(s-h,i+a);break;case"star":u=Math.cos(f)*(n?n/2:g),a=Math.cos(f)*g,r=Math.sin(f)*g,h=Math.sin(f)*(n?n/2:g),e.moveTo(s-u,i-r),e.lineTo(s+u,i+r),e.moveTo(s+h,i-a),e.lineTo(s-h,i+a),f+=tt,u=Math.cos(f)*(n?n/2:g),a=Math.cos(f)*g,r=Math.sin(f)*g,h=Math.sin(f)*(n?n/2:g),e.moveTo(s-u,i-r),e.lineTo(s+u,i+r),e.moveTo(s+h,i-a),e.lineTo(s-h,i+a);break;case"line":a=n?n/2:Math.cos(f)*g,r=Math.sin(f)*g,e.moveTo(s-a,i-r),e.lineTo(s+a,i+r);break;case"dash":e.moveTo(s,i),e.lineTo(s+Math.cos(f)*(n?n/2:g),i+Math.sin(f)*g);break;case!1:e.closePath()}e.fill(),t.borderWidth>0&&e.stroke()}}function ss(e,t,s){return s=s||.5,!t||e&&e.x>t.left-s&&e.x<t.right+s&&e.y>t.top-s&&e.y<t.bottom+s}function is(e,t){e.save(),e.beginPath(),e.rect(t.left,t.top,t.right-t.left,t.bottom-t.top),e.clip()}function ns(e){e.restore()}function os(e,t,s,i,n){if(!t)return e.lineTo(s.x,s.y);if("middle"===n){const i=(t.x+s.x)/2;e.lineTo(i,t.y),e.lineTo(i,s.y)}else"after"===n!=!!i?e.lineTo(t.x,s.y):e.lineTo(s.x,t.y);e.lineTo(s.x,s.y)}function as(e,t,s,i){if(!t)return e.lineTo(s.x,s.y);e.bezierCurveTo(i?t.cp1x:t.cp2x,i?t.cp1y:t.cp2y,i?s.cp2x:s.cp1x,i?s.cp2y:s.cp1y,s.x,s.y)}function rs(e,t,s,i,n){if(n.strikethrough||n.underline){const o=e.measureText(i),a=t-o.actualBoundingBoxLeft,r=t+o.actualBoundingBoxRight,l=s-o.actualBoundingBoxAscent,c=s+o.actualBoundingBoxDescent,d=n.strikethrough?(l+c)/2:c;e.strokeStyle=e.fillStyle,e.beginPath(),e.lineWidth=n.decorationWidth||2,e.moveTo(a,d),e.lineTo(r,d),e.stroke()}}function ls(e,t){const s=e.fillStyle;e.fillStyle=t.color,e.fillRect(t.left,t.top,t.width,t.height),e.fillStyle=s}function cs(e,t,s,i,n,o={}){const a=Te(t)?t:[t],r=o.strokeWidth>0&&""!==o.strokeColor;let l,c;for(e.save(),e.font=n.string,function(e,t){t.translation&&e.translate(t.translation[0],t.translation[1]),Ee(t.rotation)||e.rotate(t.rotation),t.color&&(e.fillStyle=t.color),t.textAlign&&(e.textAlign=t.textAlign),t.textBaseline&&(e.textBaseline=t.textBaseline)}(e,o),l=0;l<a.length;++l)c=a[l],o.backdrop&&ls(e,o.backdrop),r&&(o.strokeColor&&(e.strokeStyle=o.strokeColor),Ee(o.strokeWidth)||(e.lineWidth=o.strokeWidth),e.strokeText(c,s,i,o.maxWidth)),e.fillText(c,s,i,o.maxWidth),rs(e,s,i,c,o),i+=Number(n.lineHeight);e.restore()}function ds(e,t){const{x:s,y:i,w:n,h:o,radius:a}=t;e.arc(s+a.topLeft,i+a.topLeft,a.topLeft,1.5*Je,Je,!0),e.lineTo(s,i+o-a.bottomLeft),e.arc(s+a.bottomLeft,i+o-a.bottomLeft,a.bottomLeft,Je,et,!0),e.lineTo(s+n-a.bottomRight,i+o),e.arc(s+n-a.bottomRight,i+o-a.bottomRight,a.bottomRight,et,0,!0),e.lineTo(s+n,i+a.topRight),e.arc(s+n-a.topRight,i+a.topRight,a.topRight,0,-et,!0),e.lineTo(s+a.topLeft,i)}const us=/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/,hs=/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/;function ps(e,t){const s=(""+e).match(us);if(!s||"normal"===s[1])return 1.2*t;switch(e=+s[2],s[3]){case"px":return e;case"%":e/=100}return t*e}const ms=e=>+e||0;function gs(e,t){const s={},i=Le(t),n=i?Object.keys(t):t,o=Le(e)?i?s=>qe(e[s],e[t[s]]):t=>e[t]:()=>e;for(const e of n)s[e]=ms(o(e));return s}function fs(e){return gs(e,{top:"y",right:"x",bottom:"y",left:"x"})}function bs(e){return gs(e,["topLeft","topRight","bottomLeft","bottomRight"])}function vs(e){const t=fs(e);return t.width=t.left+t.right,t.height=t.top+t.bottom,t}function ys(e,t){e=e||{},t=t||Jt.font;let s=qe(e.size,t.size);"string"==typeof s&&(s=parseInt(s,10));let i=qe(e.style,t.style);i&&!(""+i).match(hs)&&(console.warn('Invalid font style specified: "'+i+'"'),i=void 0);const n={family:qe(e.family,t.family),lineHeight:ps(qe(e.lineHeight,t.lineHeight),s),size:s,style:i,weight:qe(e.weight,t.weight),string:""};return n.string=function(e){return!e||Ee(e.size)||Ee(e.family)?null:(e.style?e.style+" ":"")+(e.weight?e.weight+" ":"")+e.size+"px "+e.family}(n),n}function ws(e,t,s,i){let n,o,a,r=!0;for(n=0,o=e.length;n<o;++n)if(a=e[n],void 0!==a&&(void 0!==t&&"function"==typeof a&&(a=a(t),r=!1),void 0!==s&&Te(a)&&(a=a[s%a.length],r=!1),void 0!==a))return i&&!r&&(i.cacheable=!1),a}function _s(e,t){return Object.assign(Object.create(e),t)}function xs(e,t=[""],s,i,n=()=>e[0]){const o=s||e;void 0===i&&(i=Bs("_fallback",e));const a={[Symbol.toStringTag]:"Object",_cacheable:!0,_scopes:e,_rootScopes:o,_fallback:i,_getTarget:n,override:s=>xs([s,...e],t,o,i)};return new Proxy(a,{deleteProperty:(t,s)=>(delete t[s],delete t._keys,delete e[0][s],!0),get:(s,i)=>Es(s,i,()=>function(e,t,s,i){let n;for(const o of t)if(n=Bs(ks(o,e),s),void 0!==n)return As(e,n)?Ds(s,i,e,n):n}(i,t,e,s)),getOwnPropertyDescriptor:(e,t)=>Reflect.getOwnPropertyDescriptor(e._scopes[0],t),getPrototypeOf:()=>Reflect.getPrototypeOf(e[0]),has:(e,t)=>Ps(e).includes(t),ownKeys:e=>Ps(e),set(e,t,s){const i=e._storage||(e._storage=n());return e[t]=i[t]=s,delete e._keys,!0}})}function Ss(e,t,s,i){const n={_cacheable:!1,_proxy:e,_context:t,_subProxy:s,_stack:new Set,_descriptors:Cs(e,i),setContext:t=>Ss(e,t,s,i),override:n=>Ss(e.override(n),t,s,i)};return new Proxy(n,{deleteProperty:(t,s)=>(delete t[s],delete e[s],!0),get:(e,t,s)=>Es(e,t,()=>function(e,t,s){const{_proxy:i,_context:n,_subProxy:o,_descriptors:a}=e;let r=i[t];return Ue(r)&&a.isScriptable(t)&&(r=function(e,t,s,i){const{_proxy:n,_context:o,_subProxy:a,_stack:r}=s;if(r.has(e))throw new Error("Recursion detected: "+Array.from(r).join("->")+"->"+e);r.add(e);let l=t(o,a||i);return r.delete(e),As(e,l)&&(l=Ds(n._scopes,n,e,l)),l}(t,r,e,s)),Te(r)&&r.length&&(r=function(e,t,s,i){const{_proxy:n,_context:o,_subProxy:a,_descriptors:r}=s;if(void 0!==o.index&&i(e))return t[o.index%t.length];if(Le(t[0])){const s=t,i=n._scopes.filter(e=>e!==s);t=[];for(const l of s){const s=Ds(i,n,e,l);t.push(Ss(s,o,a&&a[e],r))}}return t}(t,r,e,a.isIndexable)),As(t,r)&&(r=Ss(r,n,o&&o[t],a)),r}(e,t,s)),getOwnPropertyDescriptor:(t,s)=>t._descriptors.allKeys?Reflect.has(e,s)?{enumerable:!0,configurable:!0}:void 0:Reflect.getOwnPropertyDescriptor(e,s),getPrototypeOf:()=>Reflect.getPrototypeOf(e),has:(t,s)=>Reflect.has(e,s),ownKeys:()=>Reflect.ownKeys(e),set:(t,s,i)=>(e[s]=i,delete t[s],!0)})}function Cs(e,t={scriptable:!0,indexable:!0}){const{_scriptable:s=t.scriptable,_indexable:i=t.indexable,_allKeys:n=t.allKeys}=e;return{allKeys:n,scriptable:s,indexable:i,isScriptable:Ue(s)?s:()=>s,isIndexable:Ue(i)?i:()=>i}}const ks=(e,t)=>e?e+je(t):t,As=(e,t)=>Le(t)&&"adapters"!==e&&(null===Object.getPrototypeOf(t)||t.constructor===Object);function Es(e,t,s){if(Object.prototype.hasOwnProperty.call(e,t)||"constructor"===t)return e[t];const i=s();return e[t]=i,i}function Ts(e,t,s){return Ue(e)?e(t,s):e}const Ls=(e,t)=>!0===e?t:"string"==typeof e?We(t,e):void 0;function Is(e,t,s,i,n){for(const o of t){const t=Ls(s,o);if(t){e.add(t);const o=Ts(t._fallback,s,n);if(void 0!==o&&o!==s&&o!==i)return o}else if(!1===t&&void 0!==i&&s!==i)return null}return!1}function Ds(e,t,s,i){const n=t._rootScopes,o=Ts(t._fallback,s,i),a=[...e,...n],r=new Set;r.add(i);let l=qs(r,a,s,o||s,i);return null!==l&&(void 0===o||o===s||(l=qs(r,a,o,l,i),null!==l))&&xs(Array.from(r),[""],n,o,()=>function(e,t,s){const i=e._getTarget();t in i||(i[t]={});const n=i[t];return Te(n)&&Le(s)?s:n||{}}(t,s,i))}function qs(e,t,s,i,n){for(;s;)s=Is(e,t,s,i,n);return s}function Bs(e,t){for(const s of t){if(!s)continue;const t=s[e];if(void 0!==t)return t}}function Ps(e){let t=e._keys;return t||(t=e._keys=function(e){const t=new Set;for(const s of e)for(const e of Object.keys(s).filter(e=>!e.startsWith("_")))t.add(e);return Array.from(t)}(e._scopes)),t}function Ms(e,t,s,i){const{iScale:n}=e,{key:o="r"}=this._parsing,a=new Array(i);let r,l,c,d;for(r=0,l=i;r<l;++r)c=r+s,d=t[c],a[r]={r:n.parse(We(d,o),c)};return a}const Os=Number.EPSILON||1e-14,zs=(e,t)=>t<e.length&&!e[t].skip&&e[t],$s=e=>"x"===e?"y":"x";function Fs(e,t,s,i){const n=e.skip?t:e,o=t,a=s.skip?t:s,r=pt(o,n),l=pt(a,o);let c=r/(r+l),d=l/(r+l);c=isNaN(c)?0:c,d=isNaN(d)?0:d;const u=i*c,h=i*d;return{previous:{x:o.x-u*(a.x-n.x),y:o.y-u*(a.y-n.y)},next:{x:o.x+h*(a.x-n.x),y:o.y+h*(a.y-n.y)}}}function Hs(e,t,s){return Math.max(Math.min(e,s),t)}function Qs(e,t,s,i,n){let o,a,r,l;if(t.spanGaps&&(e=e.filter(e=>!e.skip)),"monotone"===t.cubicInterpolationMode)!function(e,t="x"){const s=$s(t),i=e.length,n=Array(i).fill(0),o=Array(i);let a,r,l,c=zs(e,0);for(a=0;a<i;++a)if(r=l,l=c,c=zs(e,a+1),l){if(c){const e=c[t]-l[t];n[a]=0!==e?(c[s]-l[s])/e:0}o[a]=r?c?nt(n[a-1])!==nt(n[a])?0:(n[a-1]+n[a])/2:n[a-1]:n[a]}!function(e,t,s){const i=e.length;let n,o,a,r,l,c=zs(e,0);for(let d=0;d<i-1;++d)l=c,c=zs(e,d+1),l&&c&&(ot(t[d],0,Os)?s[d]=s[d+1]=0:(n=s[d]/t[d],o=s[d+1]/t[d],r=Math.pow(n,2)+Math.pow(o,2),r<=9||(a=3/Math.sqrt(r),s[d]=n*a*t[d],s[d+1]=o*a*t[d])))}(e,n,o),function(e,t,s="x"){const i=$s(s),n=e.length;let o,a,r,l=zs(e,0);for(let c=0;c<n;++c){if(a=r,r=l,l=zs(e,c+1),!r)continue;const n=r[s],d=r[i];a&&(o=(n-a[s])/3,r[`cp1${s}`]=n-o,r[`cp1${i}`]=d-o*t[c]),l&&(o=(l[s]-n)/3,r[`cp2${s}`]=n+o,r[`cp2${i}`]=d+o*t[c])}}(e,o,t)}(e,n);else{let s=i?e[e.length-1]:e[0];for(o=0,a=e.length;o<a;++o)r=e[o],l=Fs(s,r,e[Math.min(o+1,a-(i?0:1))%a],t.tension),r.cp1x=l.previous.x,r.cp1y=l.previous.y,r.cp2x=l.next.x,r.cp2y=l.next.y,s=r}t.capBezierPoints&&function(e,t){let s,i,n,o,a,r=ss(e[0],t);for(s=0,i=e.length;s<i;++s)a=o,o=r,r=s<i-1&&ss(e[s+1],t),o&&(n=e[s],a&&(n.cp1x=Hs(n.cp1x,t.left,t.right),n.cp1y=Hs(n.cp1y,t.top,t.bottom)),r&&(n.cp2x=Hs(n.cp2x,t.left,t.right),n.cp2y=Hs(n.cp2y,t.top,t.bottom)))}(e,s)}function Ns(){return"undefined"!=typeof window&&"undefined"!=typeof document}function Rs(e){let t=e.parentNode;return t&&"[object ShadowRoot]"===t.toString()&&(t=t.host),t}function Ws(e,t,s){let i;return"string"==typeof e?(i=parseInt(e,10),-1!==e.indexOf("%")&&(i=i/100*t.parentNode[s])):i=e,i}const js=e=>e.ownerDocument.defaultView.getComputedStyle(e,null),Vs=["top","right","bottom","left"];function Us(e,t,s){const i={};s=s?"-"+s:"";for(let n=0;n<4;n++){const o=Vs[n];i[o]=parseFloat(e[t+"-"+o+s])||0}return i.width=i.left+i.right,i.height=i.top+i.bottom,i}function Xs(e,t){if("native"in e)return e;const{canvas:s,currentDevicePixelRatio:i}=t,n=js(s),o="border-box"===n.boxSizing,a=Us(n,"padding"),r=Us(n,"border","width"),{x:l,y:c,box:d}=function(e,t){const s=e.touches,i=s&&s.length?s[0]:e,{offsetX:n,offsetY:o}=i;let a,r,l=!1;if(((e,t,s)=>(e>0||t>0)&&(!s||!s.shadowRoot))(n,o,e.target))a=n,r=o;else{const e=t.getBoundingClientRect();a=i.clientX-e.left,r=i.clientY-e.top,l=!0}return{x:a,y:r,box:l}}(e,s),u=a.left+(d&&r.left),h=a.top+(d&&r.top);let{width:p,height:m}=t;return o&&(p-=a.width+r.width,m-=a.height+r.height),{x:Math.round((l-u)/p*s.width/i),y:Math.round((c-h)/m*s.height/i)}}const Js=e=>Math.round(10*e)/10;function Gs(e,t,s){const i=t||1,n=Js(e.height*i),o=Js(e.width*i);e.height=Js(e.height),e.width=Js(e.width);const a=e.canvas;return a.style&&(s||!a.style.height&&!a.style.width)&&(a.style.height=`${e.height}px`,a.style.width=`${e.width}px`),(e.currentDevicePixelRatio!==i||a.height!==n||a.width!==o)&&(e.currentDevicePixelRatio=i,a.height=n,a.width=o,e.ctx.setTransform(i,0,0,i,0,0),!0)}const Ys=function(){let e=!1;try{const t={get passive(){return e=!0,!1}};Ns()&&(window.addEventListener("test",null,t),window.removeEventListener("test",null,t))}catch(e){}return e}();function Ks(e,t){const s=function(e,t){return js(e).getPropertyValue(t)}(e,t),i=s&&s.match(/^(\d+)(\.\d+)?px$/);return i?+i[1]:void 0}function Zs(e,t,s,i){return{x:e.x+s*(t.x-e.x),y:e.y+s*(t.y-e.y)}}function ei(e,t,s,i){return{x:e.x+s*(t.x-e.x),y:"middle"===i?s<.5?e.y:t.y:"after"===i?s<1?e.y:t.y:s>0?t.y:e.y}}function ti(e,t,s,i){const n={x:e.cp2x,y:e.cp2y},o={x:t.cp1x,y:t.cp1y},a=Zs(e,n,s),r=Zs(n,o,s),l=Zs(o,t,s),c=Zs(a,r,s),d=Zs(r,l,s);return Zs(c,d,s)}function si(e,t,s){return e?function(e,t){return{x:s=>e+e+t-s,setWidth(e){t=e},textAlign:e=>"center"===e?e:"right"===e?"left":"right",xPlus:(e,t)=>e-t,leftForLtr:(e,t)=>e-t}}(t,s):{x:e=>e,setWidth(e){},textAlign:e=>e,xPlus:(e,t)=>e+t,leftForLtr:(e,t)=>e}}function ii(e,t){let s,i;"ltr"!==t&&"rtl"!==t||(s=e.canvas.style,i=[s.getPropertyValue("direction"),s.getPropertyPriority("direction")],s.setProperty("direction",t,"important"),e.prevTextDirection=i)}function ni(e,t){void 0!==t&&(delete e.prevTextDirection,e.canvas.style.setProperty("direction",t[0],t[1]))}function oi(e){return"angle"===e?{between:ft,compare:mt,normalize:gt}:{between:vt,compare:(e,t)=>e-t,normalize:e=>e}}function ai({start:e,end:t,count:s,loop:i,style:n}){return{start:e%s,end:t%s,loop:i&&(t-e+1)%s==0,style:n}}function ri(e,t,s){if(!s)return[e];const{property:i,start:n,end:o}=s,a=t.length,{compare:r,between:l,normalize:c}=oi(i),{start:d,end:u,loop:h,style:p}=function(e,t,s){const{property:i,start:n,end:o}=s,{between:a,normalize:r}=oi(i),l=t.length;let c,d,{start:u,end:h,loop:p}=e;if(p){for(u+=l,h+=l,c=0,d=l;c<d&&a(r(t[u%l][i]),n,o);++c)u--,h--;u%=l,h%=l}return h<u&&(h+=l),{start:u,end:h,loop:p,style:e.style}}(e,t,s),m=[];let g,f,b,v=!1,y=null;const w=()=>v||l(n,b,g)&&0!==r(n,b),_=()=>!v||0===r(o,g)||l(o,b,g);for(let e=d,s=d;e<=u;++e)f=t[e%a],f.skip||(g=c(f[i]),g!==b&&(v=l(g,n,o),null===y&&w()&&(y=0===r(g,n)?e:s),null!==y&&_()&&(m.push(ai({start:y,end:e,loop:h,count:a,style:p})),y=null),s=e,b=g));return null!==y&&m.push(ai({start:y,end:u,loop:h,count:a,style:p})),m}function li(e,t){const s=[],i=e.segments;for(let n=0;n<i.length;n++){const o=ri(i[n],e.points,t);o.length&&s.push(...o)}return s}function ci(e){return{backgroundColor:e.backgroundColor,borderCapStyle:e.borderCapStyle,borderDash:e.borderDash,borderDashOffset:e.borderDashOffset,borderJoinStyle:e.borderJoinStyle,borderWidth:e.borderWidth,borderColor:e.borderColor}}function di(e,t){if(!t)return!1;const s=[],i=function(e,t){return Mt(t)?(s.includes(t)||s.push(t),s.indexOf(t)):t};return JSON.stringify(e,i)!==JSON.stringify(t,i)}function ui(e,t,s){return e.options.clip?e[s]:t[s]}function hi(e,t){const s=t._clip;if(s.disabled)return!1;const i=function(e,t){const{xScale:s,yScale:i}=e;return s&&i?{left:ui(s,t,"left"),right:ui(s,t,"right"),top:ui(i,t,"top"),bottom:ui(i,t,"bottom")}:t}(t,e.chartArea);return{left:!1===s.left?0:i.left-(!0===s.left?0:s.left),right:!1===s.right?e.width:i.right+(!0===s.right?0:s.right),top:!1===s.top?0:i.top-(!0===s.top?0:s.top),bottom:!1===s.bottom?e.height:i.bottom+(!0===s.bottom?0:s.bottom)}}class pi{constructor(){this._request=null,this._charts=new Map,this._running=!1,this._lastDate=void 0}_notify(e,t,s,i){const n=t.listeners[i],o=t.duration;n.forEach(i=>i({chart:e,initial:t.initial,numSteps:o,currentStep:Math.min(s-t.start,o)}))}_refresh(){this._request||(this._running=!0,this._request=kt.call(window,()=>{this._update(),this._request=null,this._running&&this._refresh()}))}_update(e=Date.now()){let t=0;this._charts.forEach((s,i)=>{if(!s.running||!s.items.length)return;const n=s.items;let o,a=n.length-1,r=!1;for(;a>=0;--a)o=n[a],o._active?(o._total>s.duration&&(s.duration=o._total),o.tick(e),r=!0):(n[a]=n[n.length-1],n.pop());r&&(i.draw(),this._notify(i,s,e,"progress")),n.length||(s.running=!1,this._notify(i,s,e,"complete"),s.initial=!1),t+=n.length}),this._lastDate=e,0===t&&(this._running=!1)}_getAnims(e){const t=this._charts;let s=t.get(e);return s||(s={running:!1,initial:!0,items:[],listeners:{complete:[],progress:[]}},t.set(e,s)),s}listen(e,t,s){this._getAnims(e).listeners[t].push(s)}add(e,t){t&&t.length&&this._getAnims(e).items.push(...t)}has(e){return this._getAnims(e).items.length>0}start(e){const t=this._charts.get(e);t&&(t.running=!0,t.start=Date.now(),t.duration=t.items.reduce((e,t)=>Math.max(e,t._duration),0),this._refresh())}running(e){if(!this._running)return!1;const t=this._charts.get(e);return!!(t&&t.running&&t.items.length)}stop(e){const t=this._charts.get(e);if(!t||!t.items.length)return;const s=t.items;let i=s.length-1;for(;i>=0;--i)s[i].cancel();t.items=[],this._notify(e,t,Date.now(),"complete")}remove(e){return this._charts.delete(e)}}var mi=new pi;const gi="transparent",fi={boolean:(e,t,s)=>s>.5?t:e,color(e,t,s){const i=Ot(e||gi),n=i.valid&&Ot(t||gi);return n&&n.valid?n.mix(i,s).hexString():t},number:(e,t,s)=>e+(t-e)*s};class bi{constructor(e,t,s,i){const n=t[s];i=ws([e.to,i,n,e.from]);const o=ws([e.from,n,i]);this._active=!0,this._fn=e.fn||fi[e.type||typeof o],this._easing=Pt[e.easing]||Pt.linear,this._start=Math.floor(Date.now()+(e.delay||0)),this._duration=this._total=Math.floor(e.duration),this._loop=!!e.loop,this._target=t,this._prop=s,this._from=o,this._to=i,this._promises=void 0}active(){return this._active}update(e,t,s){if(this._active){this._notify(!1);const i=this._target[this._prop],n=s-this._start,o=this._duration-n;this._start=s,this._duration=Math.floor(Math.max(o,e.duration)),this._total+=n,this._loop=!!e.loop,this._to=ws([e.to,t,i,e.from]),this._from=ws([e.from,i,t])}}cancel(){this._active&&(this.tick(Date.now()),this._active=!1,this._notify(!1))}tick(e){const t=e-this._start,s=this._duration,i=this._prop,n=this._from,o=this._loop,a=this._to;let r;if(this._active=n!==a&&(o||t<s),!this._active)return this._target[i]=a,void this._notify(!0);t<0?this._target[i]=n:(r=t/s%2,r=o&&r>1?2-r:r,r=this._easing(Math.min(1,Math.max(0,r))),this._target[i]=this._fn(n,a,r))}wait(){const e=this._promises||(this._promises=[]);return new Promise((t,s)=>{e.push({res:t,rej:s})})}_notify(e){const t=e?"res":"rej",s=this._promises||[];for(let e=0;e<s.length;e++)s[e][t]()}}class vi{constructor(e,t){this._chart=e,this._properties=new Map,this.configure(t)}configure(e){if(!Le(e))return;const t=Object.keys(Jt.animation),s=this._properties;Object.getOwnPropertyNames(e).forEach(i=>{const n=e[i];if(!Le(n))return;const o={};for(const e of t)o[e]=n[e];(Te(n.properties)&&n.properties||[i]).forEach(e=>{e!==i&&s.has(e)||s.set(e,o)})})}_animateOptions(e,t){const s=t.options,i=function(e,t){if(!t)return;let s=e.options;if(s)return s.$shared&&(e.options=s=Object.assign({},s,{$shared:!1,$animations:{}})),s;e.options=t}(e,s);if(!i)return[];const n=this._createAnimations(i,s);return s.$shared&&function(e,t){const s=[],i=Object.keys(t);for(let t=0;t<i.length;t++){const n=e[i[t]];n&&n.active()&&s.push(n.wait())}return Promise.all(s)}(e.options.$animations,s).then(()=>{e.options=s},()=>{}),n}_createAnimations(e,t){const s=this._properties,i=[],n=e.$animations||(e.$animations={}),o=Object.keys(t),a=Date.now();let r;for(r=o.length-1;r>=0;--r){const l=o[r];if("$"===l.charAt(0))continue;if("options"===l){i.push(...this._animateOptions(e,t));continue}const c=t[l];let d=n[l];const u=s.get(l);if(d){if(u&&d.active()){d.update(u,c,a);continue}d.cancel()}u&&u.duration?(n[l]=d=new bi(u,e,l,c),i.push(d)):e[l]=c}return i}update(e,t){if(0===this._properties.size)return void Object.assign(e,t);const s=this._createAnimations(e,t);return s.length?(mi.add(this._chart,s),!0):void 0}}function yi(e,t){const s=e&&e.options||{},i=s.reverse,n=void 0===s.min?t:0,o=void 0===s.max?t:0;return{start:i?o:n,end:i?n:o}}function wi(e,t){const s=[],i=e._getSortedDatasetMetas(t);let n,o;for(n=0,o=i.length;n<o;++n)s.push(i[n].index);return s}function _i(e,t,s,i={}){const n=e.keys,o="single"===i.mode;let a,r,l,c;if(null===t)return;let d=!1;for(a=0,r=n.length;a<r;++a){if(l=+n[a],l===s){if(d=!0,i.all)continue;break}c=e.values[l],Ie(c)&&(o||0===t||nt(t)===nt(c))&&(t+=c)}return d||i.all?t:0}function xi(e,t){const s=e&&e.options.stacked;return s||void 0===s&&void 0!==t.stack}function Si(e,t,s){const i=e[t]||(e[t]={});return i[s]||(i[s]={})}function Ci(e,t,s,i){for(const n of t.getMatchingVisibleMetas(i).reverse()){const t=e[n.index];if(s&&t>0||!s&&t<0)return n.index}return null}function ki(e,t){const{chart:s,_cachedMeta:i}=e,n=s._stacks||(s._stacks={}),{iScale:o,vScale:a,index:r}=i,l=o.axis,c=a.axis,d=function(e,t,s){return`${e.id}.${t.id}.${s.stack||s.type}`}(o,a,i),u=t.length;let h;for(let e=0;e<u;++e){const s=t[e],{[l]:o,[c]:u}=s;h=(s._stacks||(s._stacks={}))[c]=Si(n,d,o),h[r]=u,h._top=Ci(h,a,!0,i.type),h._bottom=Ci(h,a,!1,i.type),(h._visualValues||(h._visualValues={}))[r]=u}}function Ai(e,t){const s=e.scales;return Object.keys(s).filter(e=>s[e].axis===t).shift()}function Ei(e,t){const s=e.controller.index,i=e.vScale&&e.vScale.axis;if(i){t=t||e._parsed;for(const e of t){const t=e._stacks;if(!t||void 0===t[i]||void 0===t[i][s])return;delete t[i][s],void 0!==t[i]._visualValues&&void 0!==t[i]._visualValues[s]&&delete t[i]._visualValues[s]}}}const Ti=e=>"reset"===e||"none"===e,Li=(e,t)=>t?e:Object.assign({},e);class Ii{static defaults={};static datasetElementType=null;static dataElementType=null;constructor(e,t){this.chart=e,this._ctx=e.ctx,this.index=t,this._cachedDataOpts={},this._cachedMeta=this.getMeta(),this._type=this._cachedMeta.type,this.options=void 0,this._parsing=!1,this._data=void 0,this._objectData=void 0,this._sharedOptions=void 0,this._drawStart=void 0,this._drawCount=void 0,this.enableOptionSharing=!1,this.supportsDecimation=!1,this.$context=void 0,this._syncList=[],this.datasetElementType=new.target.datasetElementType,this.dataElementType=new.target.dataElementType,this.initialize()}initialize(){const e=this._cachedMeta;this.configure(),this.linkScales(),e._stacked=xi(e.vScale,e),this.addElements(),this.options.fill&&!this.chart.isPluginEnabled("filler")&&console.warn("Tried to use the 'fill' option without the 'Filler' plugin enabled. Please import and register the 'Filler' plugin and make sure it is not disabled in the options")}updateIndex(e){this.index!==e&&Ei(this._cachedMeta),this.index=e}linkScales(){const e=this.chart,t=this._cachedMeta,s=this.getDataset(),i=(e,t,s,i)=>"x"===e?t:"r"===e?i:s,n=t.xAxisID=qe(s.xAxisID,Ai(e,"x")),o=t.yAxisID=qe(s.yAxisID,Ai(e,"y")),a=t.rAxisID=qe(s.rAxisID,Ai(e,"r")),r=t.indexAxis,l=t.iAxisID=i(r,n,o,a),c=t.vAxisID=i(r,o,n,a);t.xScale=this.getScaleForId(n),t.yScale=this.getScaleForId(o),t.rScale=this.getScaleForId(a),t.iScale=this.getScaleForId(l),t.vScale=this.getScaleForId(c)}getDataset(){return this.chart.data.datasets[this.index]}getMeta(){return this.chart.getDatasetMeta(this.index)}getScaleForId(e){return this.chart.scales[e]}_getOtherScale(e){const t=this._cachedMeta;return e===t.iScale?t.vScale:t.iScale}reset(){this._update("reset")}_destroy(){const e=this._cachedMeta;this._data&&St(this._data,this),e._stacked&&Ei(e)}_dataCheck(){const e=this.getDataset(),t=e.data||(e.data=[]),s=this._data;if(Le(t)){const e=this._cachedMeta;this._data=function(e,t){const{iScale:s,vScale:i}=t,n="x"===s.axis?"x":"y",o="x"===i.axis?"x":"y",a=Object.keys(e),r=new Array(a.length);let l,c,d;for(l=0,c=a.length;l<c;++l)d=a[l],r[l]={[n]:d,[o]:e[d]};return r}(t,e)}else if(s!==t){if(s){St(s,this);const e=this._cachedMeta;Ei(e),e._parsed=[]}t&&Object.isExtensible(t)&&((i=t)._chartjs?i._chartjs.listeners.push(this):(Object.defineProperty(i,"_chartjs",{configurable:!0,enumerable:!1,value:{listeners:[this]}}),xt.forEach(e=>{const t="_onData"+je(e),s=i[e];Object.defineProperty(i,e,{configurable:!0,enumerable:!1,value(...e){const n=s.apply(this,e);return i._chartjs.listeners.forEach(s=>{"function"==typeof s[t]&&s[t](...e)}),n}})}))),this._syncList=[],this._data=t}var i}addElements(){const e=this._cachedMeta;this._dataCheck(),this.datasetElementType&&(e.dataset=new this.datasetElementType)}buildOrUpdateElements(e){const t=this._cachedMeta,s=this.getDataset();let i=!1;this._dataCheck();const n=t._stacked;t._stacked=xi(t.vScale,t),t.stack!==s.stack&&(i=!0,Ei(t),t.stack=s.stack),this._resyncElements(e),(i||n!==t._stacked)&&(ki(this,t._parsed),t._stacked=xi(t.vScale,t))}configure(){const e=this.chart.config,t=e.datasetScopeKeys(this._type),s=e.getOptionScopes(this.getDataset(),t,!0);this.options=e.createResolver(s,this.getContext()),this._parsing=this.options.parsing,this._cachedDataOpts={}}parse(e,t){const{_cachedMeta:s,_data:i}=this,{iScale:n,_stacked:o}=s,a=n.axis;let r,l,c,d=0===e&&t===i.length||s._sorted,u=e>0&&s._parsed[e-1];if(!1===this._parsing)s._parsed=i,s._sorted=!0,c=i;else{c=Te(i[e])?this.parseArrayData(s,i,e,t):Le(i[e])?this.parseObjectData(s,i,e,t):this.parsePrimitiveData(s,i,e,t);const n=()=>null===l[a]||u&&l[a]<u[a];for(r=0;r<t;++r)s._parsed[r+e]=l=c[r],d&&(n()&&(d=!1),u=l);s._sorted=d}o&&ki(this,c)}parsePrimitiveData(e,t,s,i){const{iScale:n,vScale:o}=e,a=n.axis,r=o.axis,l=n.getLabels(),c=n===o,d=new Array(i);let u,h,p;for(u=0,h=i;u<h;++u)p=u+s,d[u]={[a]:c||n.parse(l[p],p),[r]:o.parse(t[p],p)};return d}parseArrayData(e,t,s,i){const{xScale:n,yScale:o}=e,a=new Array(i);let r,l,c,d;for(r=0,l=i;r<l;++r)c=r+s,d=t[c],a[r]={x:n.parse(d[0],c),y:o.parse(d[1],c)};return a}parseObjectData(e,t,s,i){const{xScale:n,yScale:o}=e,{xAxisKey:a="x",yAxisKey:r="y"}=this._parsing,l=new Array(i);let c,d,u,h;for(c=0,d=i;c<d;++c)u=c+s,h=t[u],l[c]={x:n.parse(We(h,a),u),y:o.parse(We(h,r),u)};return l}getParsed(e){return this._cachedMeta._parsed[e]}getDataElement(e){return this._cachedMeta.data[e]}applyStack(e,t,s){const i=this.chart,n=this._cachedMeta,o=t[e.axis];return _i({keys:wi(i,!0),values:t._stacks[e.axis]._visualValues},o,n.index,{mode:s})}updateRangeFromParsed(e,t,s,i){const n=s[t.axis];let o=null===n?NaN:n;const a=i&&s._stacks[t.axis];i&&a&&(i.values=a,o=_i(i,n,this._cachedMeta.index)),e.min=Math.min(e.min,o),e.max=Math.max(e.max,o)}getMinMax(e,t){const s=this._cachedMeta,i=s._parsed,n=s._sorted&&e===s.iScale,o=i.length,a=this._getOtherScale(e),r=((e,t,s)=>e&&!t.hidden&&t._stacked&&{keys:wi(s,!0),values:null})(t,s,this.chart),l={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY},{min:c,max:d}=function(e){const{min:t,max:s,minDefined:i,maxDefined:n}=e.getUserBounds();return{min:i?t:Number.NEGATIVE_INFINITY,max:n?s:Number.POSITIVE_INFINITY}}(a);let u,h;function p(){h=i[u];const t=h[a.axis];return!Ie(h[e.axis])||c>t||d<t}for(u=0;u<o&&(p()||(this.updateRangeFromParsed(l,e,h,r),!n));++u);if(n)for(u=o-1;u>=0;--u)if(!p()){this.updateRangeFromParsed(l,e,h,r);break}return l}getAllParsedValues(e){const t=this._cachedMeta._parsed,s=[];let i,n,o;for(i=0,n=t.length;i<n;++i)o=t[i][e.axis],Ie(o)&&s.push(o);return s}getMaxOverflow(){return!1}getLabelAndValue(e){const t=this._cachedMeta,s=t.iScale,i=t.vScale,n=this.getParsed(e);return{label:s?""+s.getLabelForValue(n[s.axis]):"",value:i?""+i.getLabelForValue(n[i.axis]):""}}_update(e){const t=this._cachedMeta;this.update(e||"default"),t._clip=function(e){let t,s,i,n;return Le(e)?(t=e.top,s=e.right,i=e.bottom,n=e.left):t=s=i=n=e,{top:t,right:s,bottom:i,left:n,disabled:!1===e}}(qe(this.options.clip,function(e,t,s){if(!1===s)return!1;const i=yi(e,s),n=yi(t,s);return{top:n.end,right:i.end,bottom:n.start,left:i.start}}(t.xScale,t.yScale,this.getMaxOverflow())))}update(e){}draw(){const e=this._ctx,t=this.chart,s=this._cachedMeta,i=s.data||[],n=t.chartArea,o=[],a=this._drawStart||0,r=this._drawCount||i.length-a,l=this.options.drawActiveElementsOnTop;let c;for(s.dataset&&s.dataset.draw(e,n,a,r),c=a;c<a+r;++c){const t=i[c];t.hidden||(t.active&&l?o.push(t):t.draw(e,n))}for(c=0;c<o.length;++c)o[c].draw(e,n)}getStyle(e,t){const s=t?"active":"default";return void 0===e&&this._cachedMeta.dataset?this.resolveDatasetElementOptions(s):this.resolveDataElementOptions(e||0,s)}getContext(e,t,s){const i=this.getDataset();let n;if(e>=0&&e<this._cachedMeta.data.length){const t=this._cachedMeta.data[e];n=t.$context||(t.$context=function(e,t,s){return _s(e,{active:!1,dataIndex:t,parsed:void 0,raw:void 0,element:s,index:t,mode:"default",type:"data"})}(this.getContext(),e,t)),n.parsed=this.getParsed(e),n.raw=i.data[e],n.index=n.dataIndex=e}else n=this.$context||(this.$context=function(e,t){return _s(e,{active:!1,dataset:void 0,datasetIndex:t,index:t,mode:"default",type:"dataset"})}(this.chart.getContext(),this.index)),n.dataset=i,n.index=n.datasetIndex=this.index;return n.active=!!t,n.mode=s,n}resolveDatasetElementOptions(e){return this._resolveElementOptions(this.datasetElementType.id,e)}resolveDataElementOptions(e,t){return this._resolveElementOptions(this.dataElementType.id,t,e)}_resolveElementOptions(e,t="default",s){const i="active"===t,n=this._cachedDataOpts,o=e+"-"+t,a=n[o],r=this.enableOptionSharing&&Ve(s);if(a)return Li(a,r);const l=this.chart.config,c=l.datasetElementScopeKeys(this._type,e),d=i?[`${e}Hover`,"hover",e,""]:[e,""],u=l.getOptionScopes(this.getDataset(),c),h=Object.keys(Jt.elements[e]),p=l.resolveNamedOptions(u,h,()=>this.getContext(s,i,t),d);return p.$shared&&(p.$shared=r,n[o]=Object.freeze(Li(p,r))),p}_resolveAnimations(e,t,s){const i=this.chart,n=this._cachedDataOpts,o=`animation-${t}`,a=n[o];if(a)return a;let r;if(!1!==i.options.animation){const i=this.chart.config,n=i.datasetAnimationScopeKeys(this._type,t),o=i.getOptionScopes(this.getDataset(),n);r=i.createResolver(o,this.getContext(e,s,t))}const l=new vi(i,r&&r.animations);return r&&r._cacheable&&(n[o]=Object.freeze(l)),l}getSharedOptions(e){if(e.$shared)return this._sharedOptions||(this._sharedOptions=Object.assign({},e))}includeOptions(e,t){return!t||Ti(e)||this.chart._animationsDisabled}_getSharedOptions(e,t){const s=this.resolveDataElementOptions(e,t),i=this._sharedOptions,n=this.getSharedOptions(s),o=this.includeOptions(t,n)||n!==i;return this.updateSharedOptions(n,t,s),{sharedOptions:n,includeOptions:o}}updateElement(e,t,s,i){Ti(i)?Object.assign(e,s):this._resolveAnimations(t,i).update(e,s)}updateSharedOptions(e,t,s){e&&!Ti(t)&&this._resolveAnimations(void 0,t).update(e,s)}_setStyle(e,t,s,i){e.active=i;const n=this.getStyle(t,i);this._resolveAnimations(t,s,i).update(e,{options:!i&&this.getSharedOptions(n)||n})}removeHoverStyle(e,t,s){this._setStyle(e,s,"active",!1)}setHoverStyle(e,t,s){this._setStyle(e,s,"active",!0)}_removeDatasetHoverStyle(){const e=this._cachedMeta.dataset;e&&this._setStyle(e,void 0,"active",!1)}_setDatasetHoverStyle(){const e=this._cachedMeta.dataset;e&&this._setStyle(e,void 0,"active",!0)}_resyncElements(e){const t=this._data,s=this._cachedMeta.data;for(const[e,t,s]of this._syncList)this[e](t,s);this._syncList=[];const i=s.length,n=t.length,o=Math.min(n,i);o&&this.parse(0,o),n>i?this._insertElements(i,n-i,e):n<i&&this._removeElements(n,i-n)}_insertElements(e,t,s=!0){const i=this._cachedMeta,n=i.data,o=e+t;let a;const r=e=>{for(e.length+=t,a=e.length-1;a>=o;a--)e[a]=e[a-t]};for(r(n),a=e;a<o;++a)n[a]=new this.dataElementType;this._parsing&&r(i._parsed),this.parse(e,t),s&&this.updateElements(n,e,t,"reset")}updateElements(e,t,s,i){}_removeElements(e,t){const s=this._cachedMeta;if(this._parsing){const i=s._parsed.splice(e,t);s._stacked&&Ei(s,i)}s.data.splice(e,t)}_sync(e){if(this._parsing)this._syncList.push(e);else{const[t,s,i]=e;this[t](s,i)}this.chart._dataChanges.push([this.index,...e])}_onDataPush(){const e=arguments.length;this._sync(["_insertElements",this.getDataset().data.length-e,e])}_onDataPop(){this._sync(["_removeElements",this._cachedMeta.data.length-1,1])}_onDataShift(){this._sync(["_removeElements",0,1])}_onDataSplice(e,t){t&&this._sync(["_removeElements",e,t]);const s=arguments.length-2;s&&this._sync(["_insertElements",e,s])}_onDataUnshift(){this._sync(["_insertElements",0,arguments.length])}}function Di(e){const t=e.iScale,s=function(e,t){if(!e._cache.$bar){const s=e.getMatchingVisibleMetas(t);let i=[];for(let t=0,n=s.length;t<n;t++)i=i.concat(s[t].controller.getAllParsedValues(e));e._cache.$bar=Ct(i.sort((e,t)=>e-t))}return e._cache.$bar}(t,e.type);let i,n,o,a,r=t._length;const l=()=>{32767!==o&&-32768!==o&&(Ve(a)&&(r=Math.min(r,Math.abs(o-a)||r)),a=o)};for(i=0,n=s.length;i<n;++i)o=t.getPixelForValue(s[i]),l();for(a=void 0,i=0,n=t.ticks.length;i<n;++i)o=t.getPixelForTick(i),l();return r}function qi(e,t,s,i){return Te(e)?function(e,t,s,i){const n=s.parse(e[0],i),o=s.parse(e[1],i),a=Math.min(n,o),r=Math.max(n,o);let l=a,c=r;Math.abs(a)>Math.abs(r)&&(l=r,c=a),t[s.axis]=c,t._custom={barStart:l,barEnd:c,start:n,end:o,min:a,max:r}}(e,t,s,i):t[s.axis]=s.parse(e,i),t}function Bi(e,t,s,i){const n=e.iScale,o=e.vScale,a=n.getLabels(),r=n===o,l=[];let c,d,u,h;for(c=s,d=s+i;c<d;++c)h=t[c],u={},u[n.axis]=r||n.parse(a[c],c),l.push(qi(h,u,o,c));return l}function Pi(e){return e&&void 0!==e.barStart&&void 0!==e.barEnd}function Mi(e,t,s,i){let n=t.borderSkipped;const o={};if(!n)return void(e.borderSkipped=o);if(!0===n)return void(e.borderSkipped={top:!0,right:!0,bottom:!0,left:!0});const{start:a,end:r,reverse:l,top:c,bottom:d}=function(e){let t,s,i,n,o;return e.horizontal?(t=e.base>e.x,s="left",i="right"):(t=e.base<e.y,s="bottom",i="top"),t?(n="end",o="start"):(n="start",o="end"),{start:s,end:i,reverse:t,top:n,bottom:o}}(e);"middle"===n&&s&&(e.enableBorderRadius=!0,(s._top||0)===i?n=c:(s._bottom||0)===i?n=d:(o[Oi(d,a,r,l)]=!0,n=c)),o[Oi(n,a,r,l)]=!0,e.borderSkipped=o}function Oi(e,t,s,i){var n,o,a;return i?(a=s,e=zi(e=(n=e)===(o=t)?a:n===a?o:n,s,t)):e=zi(e,t,s),e}function zi(e,t,s){return"start"===e?t:"end"===e?s:e}function $i(e,{inflateAmount:t},s){e.inflateAmount="auto"===t?1===s?.33:0:t}class Fi extends Ii{static id="doughnut";static defaults={datasetElementType:!1,dataElementType:"arc",animation:{animateRotate:!0,animateScale:!1},animations:{numbers:{type:"number",properties:["circumference","endAngle","innerRadius","outerRadius","startAngle","x","y","offset","borderWidth","spacing"]}},cutout:"50%",rotation:0,circumference:360,radius:"100%",spacing:0,indexAxis:"r"};static descriptors={_scriptable:e=>"spacing"!==e,_indexable:e=>"spacing"!==e&&!e.startsWith("borderDash")&&!e.startsWith("hoverBorderDash")};static overrides={aspectRatio:1,plugins:{legend:{labels:{generateLabels(e){const t=e.data,{labels:{pointStyle:s,textAlign:i,color:n,useBorderRadius:o,borderRadius:a}}=e.legend.options;return t.labels.length&&t.datasets.length?t.labels.map((t,r)=>{const l=e.getDatasetMeta(0).controller.getStyle(r);return{text:t,fillStyle:l.backgroundColor,fontColor:n,hidden:!e.getDataVisibility(r),lineDash:l.borderDash,lineDashOffset:l.borderDashOffset,lineJoin:l.borderJoinStyle,lineWidth:l.borderWidth,strokeStyle:l.borderColor,textAlign:i,pointStyle:s,borderRadius:o&&(a||l.borderRadius),index:r}}):[]}},onClick(e,t,s){s.chart.toggleDataVisibility(t.index),s.chart.update()}}}};constructor(e,t){super(e,t),this.enableOptionSharing=!0,this.innerRadius=void 0,this.outerRadius=void 0,this.offsetX=void 0,this.offsetY=void 0}linkScales(){}parse(e,t){const s=this.getDataset().data,i=this._cachedMeta;if(!1===this._parsing)i._parsed=s;else{let n,o,a=e=>+s[e];if(Le(s[e])){const{key:e="value"}=this._parsing;a=t=>+We(s[t],e)}for(n=e,o=e+t;n<o;++n)i._parsed[n]=a(n)}}_getRotation(){return ct(this.options.rotation-90)}_getCircumference(){return ct(this.options.circumference)}_getRotationExtents(){let e=Ge,t=-Ge;for(let s=0;s<this.chart.data.datasets.length;++s)if(this.chart.isDatasetVisible(s)&&this.chart.getDatasetMeta(s).type===this._type){const i=this.chart.getDatasetMeta(s).controller,n=i._getRotation(),o=i._getCircumference();e=Math.min(e,n),t=Math.max(t,n+o)}return{rotation:e,circumference:t-e}}update(e){const t=this.chart,{chartArea:s}=t,i=this._cachedMeta,n=i.data,o=this.getMaxBorderWidth()+this.getMaxOffset(n)+this.options.spacing,a=Math.max((Math.min(s.width,s.height)-o)/2,0),r=Math.min((c=a,"string"==typeof(l=this.options.cutout)&&l.endsWith("%")?parseFloat(l)/100:+l/c),1);var l,c;const d=this._getRingWeight(this.index),{circumference:u,rotation:h}=this._getRotationExtents(),{ratioX:p,ratioY:m,offsetX:g,offsetY:f}=function(e,t,s){let i=1,n=1,o=0,a=0;if(t<Ge){const r=e,l=r+t,c=Math.cos(r),d=Math.sin(r),u=Math.cos(l),h=Math.sin(l),p=(e,t,i)=>ft(e,r,l,!0)?1:Math.max(t,t*s,i,i*s),m=(e,t,i)=>ft(e,r,l,!0)?-1:Math.min(t,t*s,i,i*s),g=p(0,c,u),f=p(et,d,h),b=m(Je,c,u),v=m(Je+et,d,h);i=(g-b)/2,n=(f-v)/2,o=-(g+b)/2,a=-(f+v)/2}return{ratioX:i,ratioY:n,offsetX:o,offsetY:a}}(h,u,r),b=(s.width-o)/p,v=(s.height-o)/m,y=Math.max(Math.min(b,v)/2,0),w=Be(this.options.radius,y),_=(w-Math.max(w*r,0))/this._getVisibleDatasetWeightTotal();this.offsetX=g*w,this.offsetY=f*w,i.total=this.calculateTotal(),this.outerRadius=w-_*this._getRingWeightOffset(this.index),this.innerRadius=Math.max(this.outerRadius-_*d,0),this.updateElements(n,0,n.length,e)}_circumference(e,t){const s=this.options,i=this._cachedMeta,n=this._getCircumference();return t&&s.animation.animateRotate||!this.chart.getDataVisibility(e)||null===i._parsed[e]||i.data[e].hidden?0:this.calculateCircumference(i._parsed[e]*n/Ge)}updateElements(e,t,s,i){const n="reset"===i,o=this.chart,a=o.chartArea,r=o.options.animation,l=(a.left+a.right)/2,c=(a.top+a.bottom)/2,d=n&&r.animateScale,u=d?0:this.innerRadius,h=d?0:this.outerRadius,{sharedOptions:p,includeOptions:m}=this._getSharedOptions(t,i);let g,f=this._getRotation();for(g=0;g<t;++g)f+=this._circumference(g,n);for(g=t;g<t+s;++g){const t=this._circumference(g,n),s=e[g],o={x:l+this.offsetX,y:c+this.offsetY,startAngle:f,endAngle:f+t,circumference:t,outerRadius:h,innerRadius:u};m&&(o.options=p||this.resolveDataElementOptions(g,s.active?"active":i)),f+=t,this.updateElement(s,g,o,i)}}calculateTotal(){const e=this._cachedMeta,t=e.data;let s,i=0;for(s=0;s<t.length;s++){const n=e._parsed[s];null===n||isNaN(n)||!this.chart.getDataVisibility(s)||t[s].hidden||(i+=Math.abs(n))}return i}calculateCircumference(e){const t=this._cachedMeta.total;return t>0&&!isNaN(e)?Ge*(Math.abs(e)/t):0}getLabelAndValue(e){const t=this._cachedMeta,s=this.chart,i=s.data.labels||[],n=Qt(t._parsed[e],s.options.locale);return{label:i[e]||"",value:n}}getMaxBorderWidth(e){let t=0;const s=this.chart;let i,n,o,a,r;if(!e)for(i=0,n=s.data.datasets.length;i<n;++i)if(s.isDatasetVisible(i)){o=s.getDatasetMeta(i),e=o.data,a=o.controller;break}if(!e)return 0;for(i=0,n=e.length;i<n;++i)r=a.resolveDataElementOptions(i),"inner"!==r.borderAlign&&(t=Math.max(t,r.borderWidth||0,r.hoverBorderWidth||0));return t}getMaxOffset(e){let t=0;for(let s=0,i=e.length;s<i;++s){const e=this.resolveDataElementOptions(s);t=Math.max(t,e.offset||0,e.hoverOffset||0)}return t}_getRingWeightOffset(e){let t=0;for(let s=0;s<e;++s)this.chart.isDatasetVisible(s)&&(t+=this._getRingWeight(s));return t}_getRingWeight(e){return Math.max(qe(this.chart.data.datasets[e].weight,1),0)}_getVisibleDatasetWeightTotal(){return this._getRingWeightOffset(this.chart.data.datasets.length)||1}}class Hi extends Ii{static id="polarArea";static defaults={dataElementType:"arc",animation:{animateRotate:!0,animateScale:!0},animations:{numbers:{type:"number",properties:["x","y","startAngle","endAngle","innerRadius","outerRadius"]}},indexAxis:"r",startAngle:0};static overrides={aspectRatio:1,plugins:{legend:{labels:{generateLabels(e){const t=e.data;if(t.labels.length&&t.datasets.length){const{labels:{pointStyle:s,color:i}}=e.legend.options;return t.labels.map((t,n)=>{const o=e.getDatasetMeta(0).controller.getStyle(n);return{text:t,fillStyle:o.backgroundColor,strokeStyle:o.borderColor,fontColor:i,lineWidth:o.borderWidth,pointStyle:s,hidden:!e.getDataVisibility(n),index:n}})}return[]}},onClick(e,t,s){s.chart.toggleDataVisibility(t.index),s.chart.update()}}},scales:{r:{type:"radialLinear",angleLines:{display:!1},beginAtZero:!0,grid:{circular:!0},pointLabels:{display:!1},startAngle:0}}};constructor(e,t){super(e,t),this.innerRadius=void 0,this.outerRadius=void 0}getLabelAndValue(e){const t=this._cachedMeta,s=this.chart,i=s.data.labels||[],n=Qt(t._parsed[e].r,s.options.locale);return{label:i[e]||"",value:n}}parseObjectData(e,t,s,i){return Ms.bind(this)(e,t,s,i)}update(e){const t=this._cachedMeta.data;this._updateRadius(),this.updateElements(t,0,t.length,e)}getMinMax(){const e=this._cachedMeta,t={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY};return e.data.forEach((e,s)=>{const i=this.getParsed(s).r;!isNaN(i)&&this.chart.getDataVisibility(s)&&(i<t.min&&(t.min=i),i>t.max&&(t.max=i))}),t}_updateRadius(){const e=this.chart,t=e.chartArea,s=e.options,i=Math.min(t.right-t.left,t.bottom-t.top),n=Math.max(i/2,0),o=(n-Math.max(s.cutoutPercentage?n/100*s.cutoutPercentage:1,0))/e.getVisibleDatasetCount();this.outerRadius=n-o*this.index,this.innerRadius=this.outerRadius-o}updateElements(e,t,s,i){const n="reset"===i,o=this.chart,a=o.options.animation,r=this._cachedMeta.rScale,l=r.xCenter,c=r.yCenter,d=r.getIndexAngle(0)-.5*Je;let u,h=d;const p=360/this.countVisibleElements();for(u=0;u<t;++u)h+=this._computeAngle(u,i,p);for(u=t;u<t+s;u++){const t=e[u];let s=h,m=h+this._computeAngle(u,i,p),g=o.getDataVisibility(u)?r.getDistanceFromCenterForValue(this.getParsed(u).r):0;h=m,n&&(a.animateScale&&(g=0),a.animateRotate&&(s=m=d));const f={x:l,y:c,innerRadius:0,outerRadius:g,startAngle:s,endAngle:m,options:this.resolveDataElementOptions(u,t.active?"active":i)};this.updateElement(t,u,f,i)}}countVisibleElements(){const e=this._cachedMeta;let t=0;return e.data.forEach((e,s)=>{!isNaN(this.getParsed(s).r)&&this.chart.getDataVisibility(s)&&t++}),t}_computeAngle(e,t,s){return this.chart.getDataVisibility(e)?ct(this.resolveDataElementOptions(e,t).angle||s):0}}var Qi=Object.freeze({__proto__:null,BarController:class extends Ii{static id="bar";static defaults={datasetElementType:!1,dataElementType:"bar",categoryPercentage:.8,barPercentage:.9,grouped:!0,animations:{numbers:{type:"number",properties:["x","y","base","width","height"]}}};static overrides={scales:{_index_:{type:"category",offset:!0,grid:{offset:!0}},_value_:{type:"linear",beginAtZero:!0}}};parsePrimitiveData(e,t,s,i){return Bi(e,t,s,i)}parseArrayData(e,t,s,i){return Bi(e,t,s,i)}parseObjectData(e,t,s,i){const{iScale:n,vScale:o}=e,{xAxisKey:a="x",yAxisKey:r="y"}=this._parsing,l="x"===n.axis?a:r,c="x"===o.axis?a:r,d=[];let u,h,p,m;for(u=s,h=s+i;u<h;++u)m=t[u],p={},p[n.axis]=n.parse(We(m,l),u),d.push(qi(We(m,c),p,o,u));return d}updateRangeFromParsed(e,t,s,i){super.updateRangeFromParsed(e,t,s,i);const n=s._custom;n&&t===this._cachedMeta.vScale&&(e.min=Math.min(e.min,n.min),e.max=Math.max(e.max,n.max))}getMaxOverflow(){return 0}getLabelAndValue(e){const t=this._cachedMeta,{iScale:s,vScale:i}=t,n=this.getParsed(e),o=n._custom,a=Pi(o)?"["+o.start+", "+o.end+"]":""+i.getLabelForValue(n[i.axis]);return{label:""+s.getLabelForValue(n[s.axis]),value:a}}initialize(){this.enableOptionSharing=!0,super.initialize(),this._cachedMeta.stack=this.getDataset().stack}update(e){const t=this._cachedMeta;this.updateElements(t.data,0,t.data.length,e)}updateElements(e,t,s,i){const n="reset"===i,{index:o,_cachedMeta:{vScale:a}}=this,r=a.getBasePixel(),l=a.isHorizontal(),c=this._getRuler(),{sharedOptions:d,includeOptions:u}=this._getSharedOptions(t,i);for(let h=t;h<t+s;h++){const t=this.getParsed(h),s=n||Ee(t[a.axis])?{base:r,head:r}:this._calculateBarValuePixels(h),p=this._calculateBarIndexPixels(h,c),m=(t._stacks||{})[a.axis],g={horizontal:l,base:s.base,enableBorderRadius:!m||Pi(t._custom)||o===m._top||o===m._bottom,x:l?s.head:p.center,y:l?p.center:s.head,height:l?p.size:Math.abs(s.size),width:l?Math.abs(s.size):p.size};u&&(g.options=d||this.resolveDataElementOptions(h,e[h].active?"active":i));const f=g.options||e[h].options;Mi(g,f,m,o),$i(g,f,c.ratio),this.updateElement(e[h],h,g,i)}}_getStacks(e,t){const{iScale:s}=this._cachedMeta,i=s.getMatchingVisibleMetas(this._type).filter(e=>e.controller.options.grouped),n=s.options.stacked,o=[],a=this._cachedMeta.controller.getParsed(t),r=a&&a[s.axis],l=e=>{const t=e._parsed.find(e=>e[s.axis]===r),i=t&&t[e.vScale.axis];if(Ee(i)||isNaN(i))return!0};for(const s of i)if((void 0===t||!l(s))&&((!1===n||-1===o.indexOf(s.stack)||void 0===n&&void 0===s.stack)&&o.push(s.stack),s.index===e))break;return o.length||o.push(void 0),o}_getStackCount(e){return this._getStacks(void 0,e).length}_getAxisCount(){return this._getAxis().length}getFirstScaleIdForIndexAxis(){const e=this.chart.scales,t=this.chart.options.indexAxis;return Object.keys(e).filter(s=>e[s].axis===t).shift()}_getAxis(){const e={},t=this.getFirstScaleIdForIndexAxis();for(const s of this.chart.data.datasets)e[qe("x"===this.chart.options.indexAxis?s.xAxisID:s.yAxisID,t)]=!0;return Object.keys(e)}_getStackIndex(e,t,s){const i=this._getStacks(e,s),n=void 0!==t?i.indexOf(t):-1;return-1===n?i.length-1:n}_getRuler(){const e=this.options,t=this._cachedMeta,s=t.iScale,i=[];let n,o;for(n=0,o=t.data.length;n<o;++n)i.push(s.getPixelForValue(this.getParsed(n)[s.axis],n));const a=e.barThickness;return{min:a||Di(t),pixels:i,start:s._startPixel,end:s._endPixel,stackCount:this._getStackCount(),scale:s,grouped:e.grouped,ratio:a?1:e.categoryPercentage*e.barPercentage}}_calculateBarValuePixels(e){const{_cachedMeta:{vScale:t,_stacked:s,index:i},options:{base:n,minBarLength:o}}=this,a=n||0,r=this.getParsed(e),l=r._custom,c=Pi(l);let d,u,h=r[t.axis],p=0,m=s?this.applyStack(t,r,s):h;m!==h&&(p=m-h,m=h),c&&(h=l.barStart,m=l.barEnd-l.barStart,0!==h&&nt(h)!==nt(l.barEnd)&&(p=0),p+=h);const g=Ee(n)||c?p:n;let f=t.getPixelForValue(g);if(d=this.chart.getDataVisibility(e)?t.getPixelForValue(p+m):f,u=d-f,Math.abs(u)<o){u=function(e,t,s){return 0!==e?nt(e):(t.isHorizontal()?1:-1)*(t.min>=s?1:-1)}(u,t,a)*o,h===a&&(f-=u/2);const e=t.getPixelForDecimal(0),n=t.getPixelForDecimal(1),l=Math.min(e,n),p=Math.max(e,n);f=Math.max(Math.min(f,p),l),d=f+u,s&&!c&&(r._stacks[t.axis]._visualValues[i]=t.getValueForPixel(d)-t.getValueForPixel(f))}if(f===t.getPixelForValue(a)){const e=nt(u)*t.getLineWidthForValue(a)/2;f+=e,u-=e}return{size:u,base:f,head:d,center:d+u/2}}_calculateBarIndexPixels(e,t){const s=t.scale,i=this.options,n=i.skipNull,o=qe(i.maxBarThickness,1/0);let a,r;const l=this._getAxisCount();if(t.grouped){const s=n?this._getStackCount(e):t.stackCount,c="flex"===i.barThickness?function(e,t,s,i){const n=t.pixels,o=n[e];let a=e>0?n[e-1]:null,r=e<n.length-1?n[e+1]:null;const l=s.categoryPercentage;null===a&&(a=o-(null===r?t.end-t.start:r-o)),null===r&&(r=o+o-a);const c=o-(o-Math.min(a,r))/2*l;return{chunk:Math.abs(r-a)/2*l/i,ratio:s.barPercentage,start:c}}(e,t,i,s*l):function(e,t,s,i){const n=s.barThickness;let o,a;return Ee(n)?(o=t.min*s.categoryPercentage,a=s.barPercentage):(o=n*i,a=1),{chunk:o/i,ratio:a,start:t.pixels[e]-o/2}}(e,t,i,s*l),d="x"===this.chart.options.indexAxis?this.getDataset().xAxisID:this.getDataset().yAxisID,u=this._getAxis().indexOf(qe(d,this.getFirstScaleIdForIndexAxis())),h=this._getStackIndex(this.index,this._cachedMeta.stack,n?e:void 0)+u;a=c.start+c.chunk*h+c.chunk/2,r=Math.min(o,c.chunk*c.ratio)}else a=s.getPixelForValue(this.getParsed(e)[s.axis],e),r=Math.min(o,t.min*t.ratio);return{base:a-r/2,head:a+r/2,center:a,size:r}}draw(){const e=this._cachedMeta,t=e.vScale,s=e.data,i=s.length;let n=0;for(;n<i;++n)null===this.getParsed(n)[t.axis]||s[n].hidden||s[n].draw(this._ctx)}},BubbleController:class extends Ii{static id="bubble";static defaults={datasetElementType:!1,dataElementType:"point",animations:{numbers:{type:"number",properties:["x","y","borderWidth","radius"]}}};static overrides={scales:{x:{type:"linear"},y:{type:"linear"}}};initialize(){this.enableOptionSharing=!0,super.initialize()}parsePrimitiveData(e,t,s,i){const n=super.parsePrimitiveData(e,t,s,i);for(let e=0;e<n.length;e++)n[e]._custom=this.resolveDataElementOptions(e+s).radius;return n}parseArrayData(e,t,s,i){const n=super.parseArrayData(e,t,s,i);for(let e=0;e<n.length;e++){const i=t[s+e];n[e]._custom=qe(i[2],this.resolveDataElementOptions(e+s).radius)}return n}parseObjectData(e,t,s,i){const n=super.parseObjectData(e,t,s,i);for(let e=0;e<n.length;e++){const i=t[s+e];n[e]._custom=qe(i&&i.r&&+i.r,this.resolveDataElementOptions(e+s).radius)}return n}getMaxOverflow(){const e=this._cachedMeta.data;let t=0;for(let s=e.length-1;s>=0;--s)t=Math.max(t,e[s].size(this.resolveDataElementOptions(s))/2);return t>0&&t}getLabelAndValue(e){const t=this._cachedMeta,s=this.chart.data.labels||[],{xScale:i,yScale:n}=t,o=this.getParsed(e),a=i.getLabelForValue(o.x),r=n.getLabelForValue(o.y),l=o._custom;return{label:s[e]||"",value:"("+a+", "+r+(l?", "+l:"")+")"}}update(e){const t=this._cachedMeta.data;this.updateElements(t,0,t.length,e)}updateElements(e,t,s,i){const n="reset"===i,{iScale:o,vScale:a}=this._cachedMeta,{sharedOptions:r,includeOptions:l}=this._getSharedOptions(t,i),c=o.axis,d=a.axis;for(let u=t;u<t+s;u++){const t=e[u],s=!n&&this.getParsed(u),h={},p=h[c]=n?o.getPixelForDecimal(.5):o.getPixelForValue(s[c]),m=h[d]=n?a.getBasePixel():a.getPixelForValue(s[d]);h.skip=isNaN(p)||isNaN(m),l&&(h.options=r||this.resolveDataElementOptions(u,t.active?"active":i),n&&(h.options.radius=0)),this.updateElement(t,u,h,i)}}resolveDataElementOptions(e,t){const s=this.getParsed(e);let i=super.resolveDataElementOptions(e,t);i.$shared&&(i=Object.assign({},i,{$shared:!1}));const n=i.radius;return"active"!==t&&(i.radius=0),i.radius+=qe(s&&s._custom,n),i}},DoughnutController:Fi,LineController:class extends Ii{static id="line";static defaults={datasetElementType:"line",dataElementType:"point",showLine:!0,spanGaps:!1};static overrides={scales:{_index_:{type:"category"},_value_:{type:"linear"}}};initialize(){this.enableOptionSharing=!0,this.supportsDecimation=!0,super.initialize()}update(e){const t=this._cachedMeta,{dataset:s,data:i=[],_dataset:n}=t,o=this.chart._animationsDisabled;let{start:a,count:r}=Lt(t,i,o);this._drawStart=a,this._drawCount=r,It(t)&&(a=0,r=i.length),s._chart=this.chart,s._datasetIndex=this.index,s._decimated=!!n._decimated,s.points=i;const l=this.resolveDatasetElementOptions(e);this.options.showLine||(l.borderWidth=0),l.segment=this.options.segment,this.updateElement(s,void 0,{animated:!o,options:l},e),this.updateElements(i,a,r,e)}updateElements(e,t,s,i){const n="reset"===i,{iScale:o,vScale:a,_stacked:r,_dataset:l}=this._cachedMeta,{sharedOptions:c,includeOptions:d}=this._getSharedOptions(t,i),u=o.axis,h=a.axis,{spanGaps:p,segment:m}=this.options,g=rt(p)?p:Number.POSITIVE_INFINITY,f=this.chart._animationsDisabled||n||"none"===i,b=t+s,v=e.length;let y=t>0&&this.getParsed(t-1);for(let s=0;s<v;++s){const p=e[s],v=f?p:{};if(s<t||s>=b){v.skip=!0;continue}const w=this.getParsed(s),_=Ee(w[h]),x=v[u]=o.getPixelForValue(w[u],s),S=v[h]=n||_?a.getBasePixel():a.getPixelForValue(r?this.applyStack(a,w,r):w[h],s);v.skip=isNaN(x)||isNaN(S)||_,v.stop=s>0&&Math.abs(w[u]-y[u])>g,m&&(v.parsed=w,v.raw=l.data[s]),d&&(v.options=c||this.resolveDataElementOptions(s,p.active?"active":i)),f||this.updateElement(p,s,v,i),y=w}}getMaxOverflow(){const e=this._cachedMeta,t=e.dataset,s=t.options&&t.options.borderWidth||0,i=e.data||[];if(!i.length)return s;const n=i[0].size(this.resolveDataElementOptions(0)),o=i[i.length-1].size(this.resolveDataElementOptions(i.length-1));return Math.max(s,n,o)/2}draw(){const e=this._cachedMeta;e.dataset.updateControlPoints(this.chart.chartArea,e.iScale.axis),super.draw()}},PieController:class extends Fi{static id="pie";static defaults={cutout:0,rotation:0,circumference:360,radius:"100%"}},PolarAreaController:Hi,RadarController:class extends Ii{static id="radar";static defaults={datasetElementType:"line",dataElementType:"point",indexAxis:"r",showLine:!0,elements:{line:{fill:"start"}}};static overrides={aspectRatio:1,scales:{r:{type:"radialLinear"}}};getLabelAndValue(e){const t=this._cachedMeta.vScale,s=this.getParsed(e);return{label:t.getLabels()[e],value:""+t.getLabelForValue(s[t.axis])}}parseObjectData(e,t,s,i){return Ms.bind(this)(e,t,s,i)}update(e){const t=this._cachedMeta,s=t.dataset,i=t.data||[],n=t.iScale.getLabels();if(s.points=i,"resize"!==e){const t=this.resolveDatasetElementOptions(e);this.options.showLine||(t.borderWidth=0);const o={_loop:!0,_fullLoop:n.length===i.length,options:t};this.updateElement(s,void 0,o,e)}this.updateElements(i,0,i.length,e)}updateElements(e,t,s,i){const n=this._cachedMeta.rScale,o="reset"===i;for(let a=t;a<t+s;a++){const t=e[a],s=this.resolveDataElementOptions(a,t.active?"active":i),r=n.getPointPositionForValue(a,this.getParsed(a).r),l=o?n.xCenter:r.x,c=o?n.yCenter:r.y,d={x:l,y:c,angle:r.angle,skip:isNaN(l)||isNaN(c),options:s};this.updateElement(t,a,d,i)}}},ScatterController:class extends Ii{static id="scatter";static defaults={datasetElementType:!1,dataElementType:"point",showLine:!1,fill:!1};static overrides={interaction:{mode:"point"},scales:{x:{type:"linear"},y:{type:"linear"}}};getLabelAndValue(e){const t=this._cachedMeta,s=this.chart.data.labels||[],{xScale:i,yScale:n}=t,o=this.getParsed(e),a=i.getLabelForValue(o.x),r=n.getLabelForValue(o.y);return{label:s[e]||"",value:"("+a+", "+r+")"}}update(e){const t=this._cachedMeta,{data:s=[]}=t,i=this.chart._animationsDisabled;let{start:n,count:o}=Lt(t,s,i);if(this._drawStart=n,this._drawCount=o,It(t)&&(n=0,o=s.length),this.options.showLine){this.datasetElementType||this.addElements();const{dataset:n,_dataset:o}=t;n._chart=this.chart,n._datasetIndex=this.index,n._decimated=!!o._decimated,n.points=s;const a=this.resolveDatasetElementOptions(e);a.segment=this.options.segment,this.updateElement(n,void 0,{animated:!i,options:a},e)}else this.datasetElementType&&(delete t.dataset,this.datasetElementType=!1);this.updateElements(s,n,o,e)}addElements(){const{showLine:e}=this.options;!this.datasetElementType&&e&&(this.datasetElementType=this.chart.registry.getElement("line")),super.addElements()}updateElements(e,t,s,i){const n="reset"===i,{iScale:o,vScale:a,_stacked:r,_dataset:l}=this._cachedMeta,c=this.resolveDataElementOptions(t,i),d=this.getSharedOptions(c),u=this.includeOptions(i,d),h=o.axis,p=a.axis,{spanGaps:m,segment:g}=this.options,f=rt(m)?m:Number.POSITIVE_INFINITY,b=this.chart._animationsDisabled||n||"none"===i;let v=t>0&&this.getParsed(t-1);for(let c=t;c<t+s;++c){const t=e[c],s=this.getParsed(c),m=b?t:{},y=Ee(s[p]),w=m[h]=o.getPixelForValue(s[h],c),_=m[p]=n||y?a.getBasePixel():a.getPixelForValue(r?this.applyStack(a,s,r):s[p],c);m.skip=isNaN(w)||isNaN(_)||y,m.stop=c>0&&Math.abs(s[h]-v[h])>f,g&&(m.parsed=s,m.raw=l.data[c]),u&&(m.options=d||this.resolveDataElementOptions(c,t.active?"active":i)),b||this.updateElement(t,c,m,i),v=s}this.updateSharedOptions(d,i,c)}getMaxOverflow(){const e=this._cachedMeta,t=e.data||[];if(!this.options.showLine){let e=0;for(let s=t.length-1;s>=0;--s)e=Math.max(e,t[s].size(this.resolveDataElementOptions(s))/2);return e>0&&e}const s=e.dataset,i=s.options&&s.options.borderWidth||0;if(!t.length)return i;const n=t[0].size(this.resolveDataElementOptions(0)),o=t[t.length-1].size(this.resolveDataElementOptions(t.length-1));return Math.max(i,n,o)/2}}});function Ni(){throw new Error("This method is not implemented: Check that a complete date adapter is provided.")}class Ri{static override(e){Object.assign(Ri.prototype,e)}options;constructor(e){this.options=e||{}}init(){}formats(){return Ni()}parse(){return Ni()}format(){return Ni()}add(){return Ni()}diff(){return Ni()}startOf(){return Ni()}endOf(){return Ni()}}var Wi=Ri;function ji(e,t,s,i){const{controller:n,data:o,_sorted:a}=e,r=n._cachedMeta.iScale,l=e.dataset&&e.dataset.options?e.dataset.options.spanGaps:null;if(r&&t===r.axis&&"r"!==t&&a&&o.length){const a=r._reversePixels?_t:wt;if(!i){const i=a(o,t,s);if(l){const{vScale:t}=n._cachedMeta,{_parsed:s}=e,o=s.slice(0,i.lo+1).reverse().findIndex(e=>!Ee(e[t.axis]));i.lo-=Math.max(0,o);const a=s.slice(i.hi).findIndex(e=>!Ee(e[t.axis]));i.hi+=Math.max(0,a)}return i}if(n._sharedOptions){const e=o[0],i="function"==typeof e.getRange&&e.getRange(t);if(i){const e=a(o,t,s-i),n=a(o,t,s+i);return{lo:e.lo,hi:n.hi}}}}return{lo:0,hi:o.length-1}}function Vi(e,t,s,i,n){const o=e.getSortedVisibleDatasetMetas(),a=s[t];for(let e=0,s=o.length;e<s;++e){const{index:s,data:r}=o[e],{lo:l,hi:c}=ji(o[e],t,a,n);for(let e=l;e<=c;++e){const t=r[e];t.skip||i(t,s,e)}}}function Ui(e,t,s,i,n){const o=[];return n||e.isPointInArea(t)?(Vi(e,s,t,function(s,a,r){(n||ss(s,e.chartArea,0))&&s.inRange(t.x,t.y,i)&&o.push({element:s,datasetIndex:a,index:r})},!0),o):o}function Xi(e,t,s,i,n,o){return o||e.isPointInArea(t)?"r"!==s||i?function(e,t,s,i,n,o){let a=[];const r=function(e){const t=-1!==e.indexOf("x"),s=-1!==e.indexOf("y");return function(e,i){const n=t?Math.abs(e.x-i.x):0,o=s?Math.abs(e.y-i.y):0;return Math.sqrt(Math.pow(n,2)+Math.pow(o,2))}}(s);let l=Number.POSITIVE_INFINITY;return Vi(e,s,t,function(s,c,d){const u=s.inRange(t.x,t.y,n);if(i&&!u)return;const h=s.getCenterPoint(n);if(!o&&!e.isPointInArea(h)&&!u)return;const p=r(t,h);p<l?(a=[{element:s,datasetIndex:c,index:d}],l=p):p===l&&a.push({element:s,datasetIndex:c,index:d})}),a}(e,t,s,i,n,o):function(e,t,s,i){let n=[];return Vi(e,s,t,function(e,s,o){const{startAngle:a,endAngle:r}=e.getProps(["startAngle","endAngle"],i),{angle:l}=ht(e,{x:t.x,y:t.y});ft(l,a,r)&&n.push({element:e,datasetIndex:s,index:o})}),n}(e,t,s,n):[]}function Ji(e,t,s,i,n){const o=[],a="x"===s?"inXRange":"inYRange";let r=!1;return Vi(e,s,t,(e,i,l)=>{e[a]&&e[a](t[s],n)&&(o.push({element:e,datasetIndex:i,index:l}),r=r||e.inRange(t.x,t.y,n))}),i&&!r?[]:o}var Gi={evaluateInteractionItems:Vi,modes:{index(e,t,s,i){const n=Xs(t,e),o=s.axis||"x",a=s.includeInvisible||!1,r=s.intersect?Ui(e,n,o,i,a):Xi(e,n,o,!1,i,a),l=[];return r.length?(e.getSortedVisibleDatasetMetas().forEach(e=>{const t=r[0].index,s=e.data[t];s&&!s.skip&&l.push({element:s,datasetIndex:e.index,index:t})}),l):[]},dataset(e,t,s,i){const n=Xs(t,e),o=s.axis||"xy",a=s.includeInvisible||!1;let r=s.intersect?Ui(e,n,o,i,a):Xi(e,n,o,!1,i,a);if(r.length>0){const t=r[0].datasetIndex,s=e.getDatasetMeta(t).data;r=[];for(let e=0;e<s.length;++e)r.push({element:s[e],datasetIndex:t,index:e})}return r},point:(e,t,s,i)=>Ui(e,Xs(t,e),s.axis||"xy",i,s.includeInvisible||!1),nearest(e,t,s,i){const n=Xs(t,e),o=s.axis||"xy",a=s.includeInvisible||!1;return Xi(e,n,o,s.intersect,i,a)},x:(e,t,s,i)=>Ji(e,Xs(t,e),"x",s.intersect,i),y:(e,t,s,i)=>Ji(e,Xs(t,e),"y",s.intersect,i)}};const Yi=["left","top","right","bottom"];function Ki(e,t){return e.filter(e=>e.pos===t)}function Zi(e,t){return e.filter(e=>-1===Yi.indexOf(e.pos)&&e.box.axis===t)}function en(e,t){return e.sort((e,s)=>{const i=t?s:e,n=t?e:s;return i.weight===n.weight?i.index-n.index:i.weight-n.weight})}function tn(e,t,s,i){return Math.max(e[s],t[s])+Math.max(e[i],t[i])}function sn(e,t){e.top=Math.max(e.top,t.top),e.left=Math.max(e.left,t.left),e.bottom=Math.max(e.bottom,t.bottom),e.right=Math.max(e.right,t.right)}function nn(e,t,s,i){const{pos:n,box:o}=s,a=e.maxPadding;if(!Le(n)){s.size&&(e[n]-=s.size);const t=i[s.stack]||{size:0,count:1};t.size=Math.max(t.size,s.horizontal?o.height:o.width),s.size=t.size/t.count,e[n]+=s.size}o.getPadding&&sn(a,o.getPadding());const r=Math.max(0,t.outerWidth-tn(a,e,"left","right")),l=Math.max(0,t.outerHeight-tn(a,e,"top","bottom")),c=r!==e.w,d=l!==e.h;return e.w=r,e.h=l,s.horizontal?{same:c,other:d}:{same:d,other:c}}function on(e,t){const s=t.maxPadding;return function(e){const i={left:0,top:0,right:0,bottom:0};return e.forEach(e=>{i[e]=Math.max(t[e],s[e])}),i}(e?["left","right"]:["top","bottom"])}function an(e,t,s,i){const n=[];let o,a,r,l,c,d;for(o=0,a=e.length,c=0;o<a;++o){r=e[o],l=r.box,l.update(r.width||t.w,r.height||t.h,on(r.horizontal,t));const{same:a,other:u}=nn(t,s,r,i);c|=a&&n.length,d=d||u,l.fullSize||n.push(r)}return c&&an(n,t,s,i)||d}function rn(e,t,s,i,n){e.top=s,e.left=t,e.right=t+i,e.bottom=s+n,e.width=i,e.height=n}function ln(e,t,s,i){const n=s.padding;let{x:o,y:a}=t;for(const r of e){const e=r.box,l=i[r.stack]||{count:1,placed:0,weight:1},c=r.stackWeight/l.weight||1;if(r.horizontal){const i=t.w*c,o=l.size||e.height;Ve(l.start)&&(a=l.start),e.fullSize?rn(e,n.left,a,s.outerWidth-n.right-n.left,o):rn(e,t.left+l.placed,a,i,o),l.start=a,l.placed+=i,a=e.bottom}else{const i=t.h*c,a=l.size||e.width;Ve(l.start)&&(o=l.start),e.fullSize?rn(e,o,n.top,a,s.outerHeight-n.bottom-n.top):rn(e,o,t.top+l.placed,a,i),l.start=o,l.placed+=i,o=e.right}}t.x=o,t.y=a}var cn={addBox(e,t){e.boxes||(e.boxes=[]),t.fullSize=t.fullSize||!1,t.position=t.position||"top",t.weight=t.weight||0,t._layers=t._layers||function(){return[{z:0,draw(e){t.draw(e)}}]},e.boxes.push(t)},removeBox(e,t){const s=e.boxes?e.boxes.indexOf(t):-1;-1!==s&&e.boxes.splice(s,1)},configure(e,t,s){t.fullSize=s.fullSize,t.position=s.position,t.weight=s.weight},update(e,t,s,i){if(!e)return;const n=vs(e.options.layout.padding),o=Math.max(t-n.width,0),a=Math.max(s-n.height,0),r=function(e){const t=function(e){const t=[];let s,i,n,o,a,r;for(s=0,i=(e||[]).length;s<i;++s)n=e[s],({position:o,options:{stack:a,stackWeight:r=1}}=n),t.push({index:s,box:n,pos:o,horizontal:n.isHorizontal(),weight:n.weight,stack:a&&o+a,stackWeight:r});return t}(e),s=en(t.filter(e=>e.box.fullSize),!0),i=en(Ki(t,"left"),!0),n=en(Ki(t,"right")),o=en(Ki(t,"top"),!0),a=en(Ki(t,"bottom")),r=Zi(t,"x"),l=Zi(t,"y");return{fullSize:s,leftAndTop:i.concat(o),rightAndBottom:n.concat(l).concat(a).concat(r),chartArea:Ki(t,"chartArea"),vertical:i.concat(n).concat(l),horizontal:o.concat(a).concat(r)}}(e.boxes),l=r.vertical,c=r.horizontal;Me(e.boxes,e=>{"function"==typeof e.beforeLayout&&e.beforeLayout()});const d=l.reduce((e,t)=>t.box.options&&!1===t.box.options.display?e:e+1,0)||1,u=Object.freeze({outerWidth:t,outerHeight:s,padding:n,availableWidth:o,availableHeight:a,vBoxMaxWidth:o/2/d,hBoxMaxHeight:a/2}),h=Object.assign({},n);sn(h,vs(i));const p=Object.assign({maxPadding:h,w:o,h:a,x:n.left,y:n.top},n),m=function(e,t){const s=function(e){const t={};for(const s of e){const{stack:e,pos:i,stackWeight:n}=s;if(!e||!Yi.includes(i))continue;const o=t[e]||(t[e]={count:0,placed:0,weight:0,size:0});o.count++,o.weight+=n}return t}(e),{vBoxMaxWidth:i,hBoxMaxHeight:n}=t;let o,a,r;for(o=0,a=e.length;o<a;++o){r=e[o];const{fullSize:a}=r.box,l=s[r.stack],c=l&&r.stackWeight/l.weight;r.horizontal?(r.width=c?c*i:a&&t.availableWidth,r.height=n):(r.width=i,r.height=c?c*n:a&&t.availableHeight)}return s}(l.concat(c),u);an(r.fullSize,p,u,m),an(l,p,u,m),an(c,p,u,m)&&an(l,p,u,m),function(e){const t=e.maxPadding;function s(s){const i=Math.max(t[s]-e[s],0);return e[s]+=i,i}e.y+=s("top"),e.x+=s("left"),s("right"),s("bottom")}(p),ln(r.leftAndTop,p,u,m),p.x+=p.w,p.y+=p.h,ln(r.rightAndBottom,p,u,m),e.chartArea={left:p.left,top:p.top,right:p.left+p.w,bottom:p.top+p.h,height:p.h,width:p.w},Me(r.chartArea,t=>{const s=t.box;Object.assign(s,e.chartArea),s.update(p.w,p.h,{left:0,top:0,right:0,bottom:0})})}};class dn{acquireContext(e,t){}releaseContext(e){return!1}addEventListener(e,t,s){}removeEventListener(e,t,s){}getDevicePixelRatio(){return 1}getMaximumSize(e,t,s,i){return t=Math.max(0,t||e.width),s=s||e.height,{width:t,height:Math.max(0,i?Math.floor(t/i):s)}}isAttached(e){return!0}updateConfig(e){}}class un extends dn{acquireContext(e){return e&&e.getContext&&e.getContext("2d")||null}updateConfig(e){e.options.animation=!1}}const hn="$chartjs",pn={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup",pointerenter:"mouseenter",pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointerleave:"mouseout",pointerout:"mouseout"},mn=e=>null===e||""===e,gn=!!Ys&&{passive:!0};function fn(e,t,s){e&&e.canvas&&e.canvas.removeEventListener(t,s,gn)}function bn(e,t){for(const s of e)if(s===t||s.contains(t))return!0}function vn(e,t,s){const i=e.canvas,n=new MutationObserver(e=>{let t=!1;for(const s of e)t=t||bn(s.addedNodes,i),t=t&&!bn(s.removedNodes,i);t&&s()});return n.observe(document,{childList:!0,subtree:!0}),n}function yn(e,t,s){const i=e.canvas,n=new MutationObserver(e=>{let t=!1;for(const s of e)t=t||bn(s.removedNodes,i),t=t&&!bn(s.addedNodes,i);t&&s()});return n.observe(document,{childList:!0,subtree:!0}),n}const wn=new Map;let xn=0;function Sn(){const e=window.devicePixelRatio;e!==xn&&(xn=e,wn.forEach((t,s)=>{s.currentDevicePixelRatio!==e&&t()}))}function Cn(e,t,s){const i=e.canvas,n=i&&Rs(i);if(!n)return;const o=At((e,t)=>{const i=n.clientWidth;s(e,t),i<n.clientWidth&&s()},window),a=new ResizeObserver(e=>{const t=e[0],s=t.contentRect.width,i=t.contentRect.height;0===s&&0===i||o(s,i)});return a.observe(n),function(e,t){wn.size||window.addEventListener("resize",Sn),wn.set(e,t)}(e,o),a}function kn(e,t,s){s&&s.disconnect(),"resize"===t&&function(e){wn.delete(e),wn.size||window.removeEventListener("resize",Sn)}(e)}function An(e,t,s){const i=e.canvas,n=At(t=>{null!==e.ctx&&s(function(e,t){const s=pn[e.type]||e.type,{x:i,y:n}=Xs(e,t);return{type:s,chart:t,native:e,x:void 0!==i?i:null,y:void 0!==n?n:null}}(t,e))},e);return function(e,t,s){e&&e.addEventListener(t,s,gn)}(i,t,n),n}class En extends dn{acquireContext(e,t){const s=e&&e.getContext&&e.getContext("2d");return s&&s.canvas===e?(function(e,t){const s=e.style,i=e.getAttribute("height"),n=e.getAttribute("width");if(e[hn]={initial:{height:i,width:n,style:{display:s.display,height:s.height,width:s.width}}},s.display=s.display||"block",s.boxSizing=s.boxSizing||"border-box",mn(n)){const t=Ks(e,"width");void 0!==t&&(e.width=t)}if(mn(i))if(""===e.style.height)e.height=e.width/(t||2);else{const t=Ks(e,"height");void 0!==t&&(e.height=t)}}(e,t),s):null}releaseContext(e){const t=e.canvas;if(!t[hn])return!1;const s=t[hn].initial;["height","width"].forEach(e=>{const i=s[e];Ee(i)?t.removeAttribute(e):t.setAttribute(e,i)});const i=s.style||{};return Object.keys(i).forEach(e=>{t.style[e]=i[e]}),t.width=t.width,delete t[hn],!0}addEventListener(e,t,s){this.removeEventListener(e,t);const i=e.$proxies||(e.$proxies={}),n={attach:vn,detach:yn,resize:Cn}[t]||An;i[t]=n(e,t,s)}removeEventListener(e,t){const s=e.$proxies||(e.$proxies={}),i=s[t];i&&(({attach:kn,detach:kn,resize:kn}[t]||fn)(e,t,i),s[t]=void 0)}getDevicePixelRatio(){return window.devicePixelRatio}getMaximumSize(e,t,s,i){return function(e,t,s,i){const n=js(e),o=Us(n,"margin"),a=Ws(n.maxWidth,e,"clientWidth")||Ke,r=Ws(n.maxHeight,e,"clientHeight")||Ke,l=function(e,t,s){let i,n;if(void 0===t||void 0===s){const o=e&&Rs(e);if(o){const e=o.getBoundingClientRect(),a=js(o),r=Us(a,"border","width"),l=Us(a,"padding");t=e.width-l.width-r.width,s=e.height-l.height-r.height,i=Ws(a.maxWidth,o,"clientWidth"),n=Ws(a.maxHeight,o,"clientHeight")}else t=e.clientWidth,s=e.clientHeight}return{width:t,height:s,maxWidth:i||Ke,maxHeight:n||Ke}}(e,t,s);let{width:c,height:d}=l;if("content-box"===n.boxSizing){const e=Us(n,"border","width"),t=Us(n,"padding");c-=t.width+e.width,d-=t.height+e.height}return c=Math.max(0,c-o.width),d=Math.max(0,i?c/i:d-o.height),c=Js(Math.min(c,a,l.maxWidth)),d=Js(Math.min(d,r,l.maxHeight)),c&&!d&&(d=Js(c/2)),(void 0!==t||void 0!==s)&&i&&l.height&&d>l.height&&(d=l.height,c=Js(Math.floor(d*i))),{width:c,height:d}}(e,t,s,i)}isAttached(e){const t=e&&Rs(e);return!(!t||!t.isConnected)}}class Tn{static defaults={};static defaultRoutes=void 0;x;y;active=!1;options;$animations;tooltipPosition(e){const{x:t,y:s}=this.getProps(["x","y"],e);return{x:t,y:s}}hasValue(){return rt(this.x)&&rt(this.y)}getProps(e,t){const s=this.$animations;if(!t||!s)return this;const i={};return e.forEach(e=>{i[e]=s[e]&&s[e].active()?s[e]._to:this[e]}),i}}function Ln(e,t,s,i,n){const o=qe(i,0),a=Math.min(qe(n,e.length),e.length);let r,l,c,d=0;for(s=Math.ceil(s),n&&(r=n-i,s=r/Math.floor(r/s)),c=o;c<0;)d++,c=Math.round(o+d*s);for(l=Math.max(o,0);l<a;l++)l===c&&(t.push(e[l]),d++,c=Math.round(o+d*s))}const In=(e,t,s)=>"top"===t||"left"===t?e[t]+s:e[t]-s,Dn=(e,t)=>Math.min(t||e,e);function qn(e,t){const s=[],i=e.length/t,n=e.length;let o=0;for(;o<n;o+=i)s.push(e[Math.floor(o)]);return s}function Bn(e,t,s){const i=e.ticks.length,n=Math.min(t,i-1),o=e._startPixel,a=e._endPixel,r=1e-6;let l,c=e.getPixelForTick(n);if(!(s&&(l=1===i?Math.max(c-o,a-c):0===t?(e.getPixelForTick(1)-c)/2:(c-e.getPixelForTick(n-1))/2,c+=n<t?l:-l,c<o-r||c>a+r)))return c}function Pn(e){return e.drawTicks?e.tickLength:0}function Mn(e,t){if(!e.display)return 0;const s=ys(e.font,t),i=vs(e.padding);return(Te(e.text)?e.text.length:1)*s.lineHeight+i.height}function On(e,t,s){let i=Et(e);return(s&&"right"!==t||!s&&"right"===t)&&(i=(e=>"left"===e?"right":"right"===e?"left":e)(i)),i}class zn extends Tn{constructor(e){super(),this.id=e.id,this.type=e.type,this.options=void 0,this.ctx=e.ctx,this.chart=e.chart,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this._margins={left:0,right:0,top:0,bottom:0},this.maxWidth=void 0,this.maxHeight=void 0,this.paddingTop=void 0,this.paddingBottom=void 0,this.paddingLeft=void 0,this.paddingRight=void 0,this.axis=void 0,this.labelRotation=void 0,this.min=void 0,this.max=void 0,this._range=void 0,this.ticks=[],this._gridLineItems=null,this._labelItems=null,this._labelSizes=null,this._length=0,this._maxLength=0,this._longestTextCache={},this._startPixel=void 0,this._endPixel=void 0,this._reversePixels=!1,this._userMax=void 0,this._userMin=void 0,this._suggestedMax=void 0,this._suggestedMin=void 0,this._ticksLength=0,this._borderValue=0,this._cache={},this._dataLimitsCached=!1,this.$context=void 0}init(e){this.options=e.setContext(this.getContext()),this.axis=e.axis,this._userMin=this.parse(e.min),this._userMax=this.parse(e.max),this._suggestedMin=this.parse(e.suggestedMin),this._suggestedMax=this.parse(e.suggestedMax)}parse(e,t){return e}getUserBounds(){let{_userMin:e,_userMax:t,_suggestedMin:s,_suggestedMax:i}=this;return e=De(e,Number.POSITIVE_INFINITY),t=De(t,Number.NEGATIVE_INFINITY),s=De(s,Number.POSITIVE_INFINITY),i=De(i,Number.NEGATIVE_INFINITY),{min:De(e,s),max:De(t,i),minDefined:Ie(e),maxDefined:Ie(t)}}getMinMax(e){let t,{min:s,max:i,minDefined:n,maxDefined:o}=this.getUserBounds();if(n&&o)return{min:s,max:i};const a=this.getMatchingVisibleMetas();for(let r=0,l=a.length;r<l;++r)t=a[r].controller.getMinMax(this,e),n||(s=Math.min(s,t.min)),o||(i=Math.max(i,t.max));return s=o&&s>i?i:s,i=n&&s>i?s:i,{min:De(s,De(i,s)),max:De(i,De(s,i))}}getPadding(){return{left:this.paddingLeft||0,top:this.paddingTop||0,right:this.paddingRight||0,bottom:this.paddingBottom||0}}getTicks(){return this.ticks}getLabels(){const e=this.chart.data;return this.options.labels||(this.isHorizontal()?e.xLabels:e.yLabels)||e.labels||[]}getLabelItems(e=this.chart.chartArea){return this._labelItems||(this._labelItems=this._computeLabelItems(e))}beforeLayout(){this._cache={},this._dataLimitsCached=!1}beforeUpdate(){Pe(this.options.beforeUpdate,[this])}update(e,t,s){const{beginAtZero:i,grace:n,ticks:o}=this.options,a=o.sampleSize;this.beforeUpdate(),this.maxWidth=e,this.maxHeight=t,this._margins=s=Object.assign({left:0,right:0,top:0,bottom:0},s),this.ticks=null,this._labelSizes=null,this._gridLineItems=null,this._labelItems=null,this.beforeSetDimensions(),this.setDimensions(),this.afterSetDimensions(),this._maxLength=this.isHorizontal()?this.width+s.left+s.right:this.height+s.top+s.bottom,this._dataLimitsCached||(this.beforeDataLimits(),this.determineDataLimits(),this.afterDataLimits(),this._range=function(e,t,s){const{min:i,max:n}=e,o=Be(t,(n-i)/2),a=(e,t)=>s&&0===e?0:e+t;return{min:a(i,-Math.abs(o)),max:a(n,o)}}(this,n,i),this._dataLimitsCached=!0),this.beforeBuildTicks(),this.ticks=this.buildTicks()||[],this.afterBuildTicks();const r=a<this.ticks.length;this._convertTicksToLabels(r?qn(this.ticks,a):this.ticks),this.configure(),this.beforeCalculateLabelRotation(),this.calculateLabelRotation(),this.afterCalculateLabelRotation(),o.display&&(o.autoSkip||"auto"===o.source)&&(this.ticks=function(e,t){const s=e.options.ticks,i=function(e){const t=e.options.offset,s=e._tickSize(),i=e._length/s+(t?0:1),n=e._maxLength/s;return Math.floor(Math.min(i,n))}(e),n=Math.min(s.maxTicksLimit||i,i),o=s.major.enabled?function(e){const t=[];let s,i;for(s=0,i=e.length;s<i;s++)e[s].major&&t.push(s);return t}(t):[],a=o.length,r=o[0],l=o[a-1],c=[];if(a>n)return function(e,t,s,i){let n,o=0,a=s[0];for(i=Math.ceil(i),n=0;n<e.length;n++)n===a&&(t.push(e[n]),o++,a=s[o*i])}(t,c,o,a/n),c;const d=function(e,t,s){const i=function(e){const t=e.length;let s,i;if(t<2)return!1;for(i=e[0],s=1;s<t;++s)if(e[s]-e[s-1]!==i)return!1;return i}(e),n=t.length/s;if(!i)return Math.max(n,1);const o=function(e){const t=[],s=Math.sqrt(e);let i;for(i=1;i<s;i++)e%i===0&&(t.push(i),t.push(e/i));return s===(0|s)&&t.push(s),t.sort((e,t)=>e-t).pop(),t}(i);for(let e=0,t=o.length-1;e<t;e++){const t=o[e];if(t>n)return t}return Math.max(n,1)}(o,t,n);if(a>0){let e,s;const i=a>1?Math.round((l-r)/(a-1)):null;for(Ln(t,c,d,Ee(i)?0:r-i,r),e=0,s=a-1;e<s;e++)Ln(t,c,d,o[e],o[e+1]);return Ln(t,c,d,l,Ee(i)?t.length:l+i),c}return Ln(t,c,d),c}(this,this.ticks),this._labelSizes=null,this.afterAutoSkip()),r&&this._convertTicksToLabels(this.ticks),this.beforeFit(),this.fit(),this.afterFit(),this.afterUpdate()}configure(){let e,t,s=this.options.reverse;this.isHorizontal()?(e=this.left,t=this.right):(e=this.top,t=this.bottom,s=!s),this._startPixel=e,this._endPixel=t,this._reversePixels=s,this._length=t-e,this._alignToPixels=this.options.alignToPixels}afterUpdate(){Pe(this.options.afterUpdate,[this])}beforeSetDimensions(){Pe(this.options.beforeSetDimensions,[this])}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=0,this.right=this.width):(this.height=this.maxHeight,this.top=0,this.bottom=this.height),this.paddingLeft=0,this.paddingTop=0,this.paddingRight=0,this.paddingBottom=0}afterSetDimensions(){Pe(this.options.afterSetDimensions,[this])}_callHooks(e){this.chart.notifyPlugins(e,this.getContext()),Pe(this.options[e],[this])}beforeDataLimits(){this._callHooks("beforeDataLimits")}determineDataLimits(){}afterDataLimits(){this._callHooks("afterDataLimits")}beforeBuildTicks(){this._callHooks("beforeBuildTicks")}buildTicks(){return[]}afterBuildTicks(){this._callHooks("afterBuildTicks")}beforeTickToLabelConversion(){Pe(this.options.beforeTickToLabelConversion,[this])}generateTickLabels(e){const t=this.options.ticks;let s,i,n;for(s=0,i=e.length;s<i;s++)n=e[s],n.label=Pe(t.callback,[n.value,s,e],this)}afterTickToLabelConversion(){Pe(this.options.afterTickToLabelConversion,[this])}beforeCalculateLabelRotation(){Pe(this.options.beforeCalculateLabelRotation,[this])}calculateLabelRotation(){const e=this.options,t=e.ticks,s=Dn(this.ticks.length,e.ticks.maxTicksLimit),i=t.minRotation||0,n=t.maxRotation;let o,a,r,l=i;if(!this._isVisible()||!t.display||i>=n||s<=1||!this.isHorizontal())return void(this.labelRotation=i);const c=this._getLabelSizes(),d=c.widest.width,u=c.highest.height,h=bt(this.chart.width-d,0,this.maxWidth);o=e.offset?this.maxWidth/s:h/(s-1),d+6>o&&(o=h/(s-(e.offset?.5:1)),a=this.maxHeight-Pn(e.grid)-t.padding-Mn(e.title,this.chart.options.font),r=Math.sqrt(d*d+u*u),l=dt(Math.min(Math.asin(bt((c.highest.height+6)/o,-1,1)),Math.asin(bt(a/r,-1,1))-Math.asin(bt(u/r,-1,1)))),l=Math.max(i,Math.min(n,l))),this.labelRotation=l}afterCalculateLabelRotation(){Pe(this.options.afterCalculateLabelRotation,[this])}afterAutoSkip(){}beforeFit(){Pe(this.options.beforeFit,[this])}fit(){const e={width:0,height:0},{chart:t,options:{ticks:s,title:i,grid:n}}=this,o=this._isVisible(),a=this.isHorizontal();if(o){const o=Mn(i,t.options.font);if(a?(e.width=this.maxWidth,e.height=Pn(n)+o):(e.height=this.maxHeight,e.width=Pn(n)+o),s.display&&this.ticks.length){const{first:t,last:i,widest:n,highest:o}=this._getLabelSizes(),r=2*s.padding,l=ct(this.labelRotation),c=Math.cos(l),d=Math.sin(l);if(a){const t=s.mirror?0:d*n.width+c*o.height;e.height=Math.min(this.maxHeight,e.height+t+r)}else{const t=s.mirror?0:c*n.width+d*o.height;e.width=Math.min(this.maxWidth,e.width+t+r)}this._calculatePadding(t,i,d,c)}}this._handleMargins(),a?(this.width=this._length=t.width-this._margins.left-this._margins.right,this.height=e.height):(this.width=e.width,this.height=this._length=t.height-this._margins.top-this._margins.bottom)}_calculatePadding(e,t,s,i){const{ticks:{align:n,padding:o},position:a}=this.options,r=0!==this.labelRotation,l="top"!==a&&"x"===this.axis;if(this.isHorizontal()){const a=this.getPixelForTick(0)-this.left,c=this.right-this.getPixelForTick(this.ticks.length-1);let d=0,u=0;r?l?(d=i*e.width,u=s*t.height):(d=s*e.height,u=i*t.width):"start"===n?u=t.width:"end"===n?d=e.width:"inner"!==n&&(d=e.width/2,u=t.width/2),this.paddingLeft=Math.max((d-a+o)*this.width/(this.width-a),0),this.paddingRight=Math.max((u-c+o)*this.width/(this.width-c),0)}else{let s=t.height/2,i=e.height/2;"start"===n?(s=0,i=e.height):"end"===n&&(s=t.height,i=0),this.paddingTop=s+o,this.paddingBottom=i+o}}_handleMargins(){this._margins&&(this._margins.left=Math.max(this.paddingLeft,this._margins.left),this._margins.top=Math.max(this.paddingTop,this._margins.top),this._margins.right=Math.max(this.paddingRight,this._margins.right),this._margins.bottom=Math.max(this.paddingBottom,this._margins.bottom))}afterFit(){Pe(this.options.afterFit,[this])}isHorizontal(){const{axis:e,position:t}=this.options;return"top"===t||"bottom"===t||"x"===e}isFullSize(){return this.options.fullSize}_convertTicksToLabels(e){let t,s;for(this.beforeTickToLabelConversion(),this.generateTickLabels(e),t=0,s=e.length;t<s;t++)Ee(e[t].label)&&(e.splice(t,1),s--,t--);this.afterTickToLabelConversion()}_getLabelSizes(){let e=this._labelSizes;if(!e){const t=this.options.ticks.sampleSize;let s=this.ticks;t<s.length&&(s=qn(s,t)),this._labelSizes=e=this._computeLabelSizes(s,s.length,this.options.ticks.maxTicksLimit)}return e}_computeLabelSizes(e,t,s){const{ctx:i,_longestTextCache:n}=this,o=[],a=[],r=Math.floor(t/Dn(t,s));let l,c,d,u,h,p,m,g,f,b,v,y=0,w=0;for(l=0;l<t;l+=r){if(u=e[l].label,h=this._resolveTickFontOptions(l),i.font=p=h.string,m=n[p]=n[p]||{data:{},gc:[]},g=h.lineHeight,f=b=0,Ee(u)||Te(u)){if(Te(u))for(c=0,d=u.length;c<d;++c)v=u[c],Ee(v)||Te(v)||(f=Gt(i,m.data,m.gc,f,v),b+=g)}else f=Gt(i,m.data,m.gc,f,u),b=g;o.push(f),a.push(b),y=Math.max(f,y),w=Math.max(b,w)}!function(e,t){Me(e,e=>{const s=e.gc,i=s.length/2;let n;if(i>t){for(n=0;n<i;++n)delete e.data[s[n]];s.splice(0,i)}})}(n,t);const _=o.indexOf(y),x=a.indexOf(w),S=e=>({width:o[e]||0,height:a[e]||0});return{first:S(0),last:S(t-1),widest:S(_),highest:S(x),widths:o,heights:a}}getLabelForValue(e){return e}getPixelForValue(e,t){return NaN}getValueForPixel(e){}getPixelForTick(e){const t=this.ticks;return e<0||e>t.length-1?null:this.getPixelForValue(t[e].value)}getPixelForDecimal(e){this._reversePixels&&(e=1-e);const t=this._startPixel+e*this._length;return bt(this._alignToPixels?Kt(this.chart,t,0):t,-32768,32767)}getDecimalForPixel(e){const t=(e-this._startPixel)/this._length;return this._reversePixels?1-t:t}getBasePixel(){return this.getPixelForValue(this.getBaseValue())}getBaseValue(){const{min:e,max:t}=this;return e<0&&t<0?t:e>0&&t>0?e:0}getContext(e){const t=this.ticks||[];if(e>=0&&e<t.length){const s=t[e];return s.$context||(s.$context=function(e,t,s){return _s(e,{tick:s,index:t,type:"tick"})}(this.getContext(),e,s))}return this.$context||(this.$context=_s(this.chart.getContext(),{scale:this,type:"scale"}))}_tickSize(){const e=this.options.ticks,t=ct(this.labelRotation),s=Math.abs(Math.cos(t)),i=Math.abs(Math.sin(t)),n=this._getLabelSizes(),o=e.autoSkipPadding||0,a=n?n.widest.width+o:0,r=n?n.highest.height+o:0;return this.isHorizontal()?r*s>a*i?a/s:r/i:r*i<a*s?r/s:a/i}_isVisible(){const e=this.options.display;return"auto"!==e?!!e:this.getMatchingVisibleMetas().length>0}_computeGridLineItems(e){const t=this.axis,s=this.chart,i=this.options,{grid:n,position:o,border:a}=i,r=n.offset,l=this.isHorizontal(),c=this.ticks.length+(r?1:0),d=Pn(n),u=[],h=a.setContext(this.getContext()),p=h.display?h.width:0,m=p/2,g=function(e){return Kt(s,e,p)};let f,b,v,y,w,_,x,S,C,k,A,E;if("top"===o)f=g(this.bottom),_=this.bottom-d,S=f-m,k=g(e.top)+m,E=e.bottom;else if("bottom"===o)f=g(this.top),k=e.top,E=g(e.bottom)-m,_=f+m,S=this.top+d;else if("left"===o)f=g(this.right),w=this.right-d,x=f-m,C=g(e.left)+m,A=e.right;else if("right"===o)f=g(this.left),C=e.left,A=g(e.right)-m,w=f+m,x=this.left+d;else if("x"===t){if("center"===o)f=g((e.top+e.bottom)/2+.5);else if(Le(o)){const e=Object.keys(o)[0],t=o[e];f=g(this.chart.scales[e].getPixelForValue(t))}k=e.top,E=e.bottom,_=f+m,S=_+d}else if("y"===t){if("center"===o)f=g((e.left+e.right)/2);else if(Le(o)){const e=Object.keys(o)[0],t=o[e];f=g(this.chart.scales[e].getPixelForValue(t))}w=f-m,x=w-d,C=e.left,A=e.right}const T=qe(i.ticks.maxTicksLimit,c),L=Math.max(1,Math.ceil(c/T));for(b=0;b<c;b+=L){const e=this.getContext(b),t=n.setContext(e),i=a.setContext(e),o=t.lineWidth,c=t.color,d=i.dash||[],h=i.dashOffset,p=t.tickWidth,m=t.tickColor,g=t.tickBorderDash||[],f=t.tickBorderDashOffset;v=Bn(this,b,r),void 0!==v&&(y=Kt(s,v,o),l?w=x=C=A=y:_=S=k=E=y,u.push({tx1:w,ty1:_,tx2:x,ty2:S,x1:C,y1:k,x2:A,y2:E,width:o,color:c,borderDash:d,borderDashOffset:h,tickWidth:p,tickColor:m,tickBorderDash:g,tickBorderDashOffset:f}))}return this._ticksLength=c,this._borderValue=f,u}_computeLabelItems(e){const t=this.axis,s=this.options,{position:i,ticks:n}=s,o=this.isHorizontal(),a=this.ticks,{align:r,crossAlign:l,padding:c,mirror:d}=n,u=Pn(s.grid),h=u+c,p=d?-c:h,m=-ct(this.labelRotation),g=[];let f,b,v,y,w,_,x,S,C,k,A,E,T="middle";if("top"===i)_=this.bottom-p,x=this._getXAxisLabelAlignment();else if("bottom"===i)_=this.top+p,x=this._getXAxisLabelAlignment();else if("left"===i){const e=this._getYAxisLabelAlignment(u);x=e.textAlign,w=e.x}else if("right"===i){const e=this._getYAxisLabelAlignment(u);x=e.textAlign,w=e.x}else if("x"===t){if("center"===i)_=(e.top+e.bottom)/2+h;else if(Le(i)){const e=Object.keys(i)[0],t=i[e];_=this.chart.scales[e].getPixelForValue(t)+h}x=this._getXAxisLabelAlignment()}else if("y"===t){if("center"===i)w=(e.left+e.right)/2-h;else if(Le(i)){const e=Object.keys(i)[0],t=i[e];w=this.chart.scales[e].getPixelForValue(t)}x=this._getYAxisLabelAlignment(u).textAlign}"y"===t&&("start"===r?T="top":"end"===r&&(T="bottom"));const L=this._getLabelSizes();for(f=0,b=a.length;f<b;++f){v=a[f],y=v.label;const e=n.setContext(this.getContext(f));S=this.getPixelForTick(f)+n.labelOffset,C=this._resolveTickFontOptions(f),k=C.lineHeight,A=Te(y)?y.length:1;const t=A/2,s=e.color,r=e.textStrokeColor,c=e.textStrokeWidth;let u,h=x;if(o?(w=S,"inner"===x&&(h=f===b-1?this.options.reverse?"left":"right":0===f?this.options.reverse?"right":"left":"center"),E="top"===i?"near"===l||0!==m?-A*k+k/2:"center"===l?-L.highest.height/2-t*k+k:-L.highest.height+k/2:"near"===l||0!==m?k/2:"center"===l?L.highest.height/2-t*k:L.highest.height-A*k,d&&(E*=-1),0===m||e.showLabelBackdrop||(w+=k/2*Math.sin(m))):(_=S,E=(1-A)*k/2),e.showLabelBackdrop){const t=vs(e.backdropPadding),s=L.heights[f],i=L.widths[f];let n=E-t.top,o=0-t.left;switch(T){case"middle":n-=s/2;break;case"bottom":n-=s}switch(x){case"center":o-=i/2;break;case"right":o-=i;break;case"inner":f===b-1?o-=i:f>0&&(o-=i/2)}u={left:o,top:n,width:i+t.width,height:s+t.height,color:e.backdropColor}}g.push({label:y,font:C,textOffset:E,options:{rotation:m,color:s,strokeColor:r,strokeWidth:c,textAlign:h,textBaseline:T,translation:[w,_],backdrop:u}})}return g}_getXAxisLabelAlignment(){const{position:e,ticks:t}=this.options;if(-ct(this.labelRotation))return"top"===e?"left":"right";let s="center";return"start"===t.align?s="left":"end"===t.align?s="right":"inner"===t.align&&(s="inner"),s}_getYAxisLabelAlignment(e){const{position:t,ticks:{crossAlign:s,mirror:i,padding:n}}=this.options,o=e+n,a=this._getLabelSizes().widest.width;let r,l;return"left"===t?i?(l=this.right+n,"near"===s?r="left":"center"===s?(r="center",l+=a/2):(r="right",l+=a)):(l=this.right-o,"near"===s?r="right":"center"===s?(r="center",l-=a/2):(r="left",l=this.left)):"right"===t?i?(l=this.left+n,"near"===s?r="right":"center"===s?(r="center",l-=a/2):(r="left",l-=a)):(l=this.left+o,"near"===s?r="left":"center"===s?(r="center",l+=a/2):(r="right",l=this.right)):r="right",{textAlign:r,x:l}}_computeLabelArea(){if(this.options.ticks.mirror)return;const e=this.chart,t=this.options.position;return"left"===t||"right"===t?{top:0,left:this.left,bottom:e.height,right:this.right}:"top"===t||"bottom"===t?{top:this.top,left:0,bottom:this.bottom,right:e.width}:void 0}drawBackground(){const{ctx:e,options:{backgroundColor:t},left:s,top:i,width:n,height:o}=this;t&&(e.save(),e.fillStyle=t,e.fillRect(s,i,n,o),e.restore())}getLineWidthForValue(e){const t=this.options.grid;if(!this._isVisible()||!t.display)return 0;const s=this.ticks.findIndex(t=>t.value===e);return s>=0?t.setContext(this.getContext(s)).lineWidth:0}drawGrid(e){const t=this.options.grid,s=this.ctx,i=this._gridLineItems||(this._gridLineItems=this._computeGridLineItems(e));let n,o;const a=(e,t,i)=>{i.width&&i.color&&(s.save(),s.lineWidth=i.width,s.strokeStyle=i.color,s.setLineDash(i.borderDash||[]),s.lineDashOffset=i.borderDashOffset,s.beginPath(),s.moveTo(e.x,e.y),s.lineTo(t.x,t.y),s.stroke(),s.restore())};if(t.display)for(n=0,o=i.length;n<o;++n){const e=i[n];t.drawOnChartArea&&a({x:e.x1,y:e.y1},{x:e.x2,y:e.y2},e),t.drawTicks&&a({x:e.tx1,y:e.ty1},{x:e.tx2,y:e.ty2},{color:e.tickColor,width:e.tickWidth,borderDash:e.tickBorderDash,borderDashOffset:e.tickBorderDashOffset})}}drawBorder(){const{chart:e,ctx:t,options:{border:s,grid:i}}=this,n=s.setContext(this.getContext()),o=s.display?n.width:0;if(!o)return;const a=i.setContext(this.getContext(0)).lineWidth,r=this._borderValue;let l,c,d,u;this.isHorizontal()?(l=Kt(e,this.left,o)-o/2,c=Kt(e,this.right,a)+a/2,d=u=r):(d=Kt(e,this.top,o)-o/2,u=Kt(e,this.bottom,a)+a/2,l=c=r),t.save(),t.lineWidth=n.width,t.strokeStyle=n.color,t.beginPath(),t.moveTo(l,d),t.lineTo(c,u),t.stroke(),t.restore()}drawLabels(e){if(!this.options.ticks.display)return;const t=this.ctx,s=this._computeLabelArea();s&&is(t,s);const i=this.getLabelItems(e);for(const e of i){const s=e.options,i=e.font;cs(t,e.label,0,e.textOffset,i,s)}s&&ns(t)}drawTitle(){const{ctx:e,options:{position:t,title:s,reverse:i}}=this;if(!s.display)return;const n=ys(s.font),o=vs(s.padding),a=s.align;let r=n.lineHeight/2;"bottom"===t||"center"===t||Le(t)?(r+=o.bottom,Te(s.text)&&(r+=n.lineHeight*(s.text.length-1))):r+=o.top;const{titleX:l,titleY:c,maxWidth:d,rotation:u}=function(e,t,s,i){const{top:n,left:o,bottom:a,right:r,chart:l}=e,{chartArea:c,scales:d}=l;let u,h,p,m=0;const g=a-n,f=r-o;if(e.isHorizontal()){if(h=Tt(i,o,r),Le(s)){const e=Object.keys(s)[0],i=s[e];p=d[e].getPixelForValue(i)+g-t}else p="center"===s?(c.bottom+c.top)/2+g-t:In(e,s,t);u=r-o}else{if(Le(s)){const e=Object.keys(s)[0],i=s[e];h=d[e].getPixelForValue(i)-f+t}else h="center"===s?(c.left+c.right)/2-f+t:In(e,s,t);p=Tt(i,a,n),m="left"===s?-et:et}return{titleX:h,titleY:p,maxWidth:u,rotation:m}}(this,r,t,a);cs(e,s.text,0,0,n,{color:s.color,maxWidth:d,rotation:u,textAlign:On(a,t,i),textBaseline:"middle",translation:[l,c]})}draw(e){this._isVisible()&&(this.drawBackground(),this.drawGrid(e),this.drawBorder(),this.drawTitle(),this.drawLabels(e))}_layers(){const e=this.options,t=e.ticks&&e.ticks.z||0,s=qe(e.grid&&e.grid.z,-1),i=qe(e.border&&e.border.z,0);return this._isVisible()&&this.draw===zn.prototype.draw?[{z:s,draw:e=>{this.drawBackground(),this.drawGrid(e),this.drawTitle()}},{z:i,draw:()=>{this.drawBorder()}},{z:t,draw:e=>{this.drawLabels(e)}}]:[{z:t,draw:e=>{this.draw(e)}}]}getMatchingVisibleMetas(e){const t=this.chart.getSortedVisibleDatasetMetas(),s=this.axis+"AxisID",i=[];let n,o;for(n=0,o=t.length;n<o;++n){const o=t[n];o[s]!==this.id||e&&o.type!==e||i.push(o)}return i}_resolveTickFontOptions(e){return ys(this.options.ticks.setContext(this.getContext(e)).font)}_maxDigits(){const e=this._resolveTickFontOptions(0).lineHeight;return(this.isHorizontal()?this.width:this.height)/e}}class $n{constructor(e,t,s){this.type=e,this.scope=t,this.override=s,this.items=Object.create(null)}isForType(e){return Object.prototype.isPrototypeOf.call(this.type.prototype,e.prototype)}register(e){const t=Object.getPrototypeOf(e);let s;(function(e){return"id"in e&&"defaults"in e})(t)&&(s=this.register(t));const i=this.items,n=e.id,o=this.scope+"."+n;if(!n)throw new Error("class does not have id: "+e);return n in i||(i[n]=e,function(e,t,s){const i=He(Object.create(null),[s?Jt.get(s):{},Jt.get(t),e.defaults]);Jt.set(t,i),e.defaultRoutes&&function(e,t){Object.keys(t).forEach(s=>{const i=s.split("."),n=i.pop(),o=[e].concat(i).join("."),a=t[s].split("."),r=a.pop(),l=a.join(".");Jt.route(o,n,l,r)})}(t,e.defaultRoutes),e.descriptors&&Jt.describe(t,e.descriptors)}(e,o,s),this.override&&Jt.override(e.id,e.overrides)),o}get(e){return this.items[e]}unregister(e){const t=this.items,s=e.id,i=this.scope;s in t&&delete t[s],i&&s in Jt[i]&&(delete Jt[i][s],this.override&&delete Wt[s])}}class Fn{constructor(){this.controllers=new $n(Ii,"datasets",!0),this.elements=new $n(Tn,"elements"),this.plugins=new $n(Object,"plugins"),this.scales=new $n(zn,"scales"),this._typedRegistries=[this.controllers,this.scales,this.elements]}add(...e){this._each("register",e)}remove(...e){this._each("unregister",e)}addControllers(...e){this._each("register",e,this.controllers)}addElements(...e){this._each("register",e,this.elements)}addPlugins(...e){this._each("register",e,this.plugins)}addScales(...e){this._each("register",e,this.scales)}getController(e){return this._get(e,this.controllers,"controller")}getElement(e){return this._get(e,this.elements,"element")}getPlugin(e){return this._get(e,this.plugins,"plugin")}getScale(e){return this._get(e,this.scales,"scale")}removeControllers(...e){this._each("unregister",e,this.controllers)}removeElements(...e){this._each("unregister",e,this.elements)}removePlugins(...e){this._each("unregister",e,this.plugins)}removeScales(...e){this._each("unregister",e,this.scales)}_each(e,t,s){[...t].forEach(t=>{const i=s||this._getRegistryForType(t);s||i.isForType(t)||i===this.plugins&&t.id?this._exec(e,i,t):Me(t,t=>{const i=s||this._getRegistryForType(t);this._exec(e,i,t)})})}_exec(e,t,s){const i=je(e);Pe(s["before"+i],[],s),t[e](s),Pe(s["after"+i],[],s)}_getRegistryForType(e){for(let t=0;t<this._typedRegistries.length;t++){const s=this._typedRegistries[t];if(s.isForType(e))return s}return this.plugins}_get(e,t,s){const i=t.get(e);if(void 0===i)throw new Error('"'+e+'" is not a registered '+s+".");return i}}var Hn=new Fn;class Qn{constructor(){this._init=void 0}notify(e,t,s,i){if("beforeInit"===t&&(this._init=this._createDescriptors(e,!0),this._notify(this._init,e,"install")),void 0===this._init)return;const n=i?this._descriptors(e).filter(i):this._descriptors(e),o=this._notify(n,e,t,s);return"afterDestroy"===t&&(this._notify(n,e,"stop"),this._notify(this._init,e,"uninstall"),this._init=void 0),o}_notify(e,t,s,i){i=i||{};for(const n of e){const e=n.plugin;if(!1===Pe(e[s],[t,i,n.options],e)&&i.cancelable)return!1}return!0}invalidate(){Ee(this._cache)||(this._oldCache=this._cache,this._cache=void 0)}_descriptors(e){if(this._cache)return this._cache;const t=this._cache=this._createDescriptors(e);return this._notifyStateChanges(e),t}_createDescriptors(e,t){const s=e&&e.config,i=qe(s.options&&s.options.plugins,{}),n=function(e){const t={},s=[],i=Object.keys(Hn.plugins.items);for(let e=0;e<i.length;e++)s.push(Hn.getPlugin(i[e]));const n=e.plugins||[];for(let e=0;e<n.length;e++){const i=n[e];-1===s.indexOf(i)&&(s.push(i),t[i.id]=!0)}return{plugins:s,localIds:t}}(s);return!1!==i||t?function(e,{plugins:t,localIds:s},i,n){const o=[],a=e.getContext();for(const r of t){const t=r.id,l=Nn(i[t],n);null!==l&&o.push({plugin:r,options:Rn(e.config,{plugin:r,local:s[t]},l,a)})}return o}(e,n,i,t):[]}_notifyStateChanges(e){const t=this._oldCache||[],s=this._cache,i=(e,t)=>e.filter(e=>!t.some(t=>e.plugin.id===t.plugin.id));this._notify(i(t,s),e,"stop"),this._notify(i(s,t),e,"start")}}function Nn(e,t){return t||!1!==e?!0===e?{}:e:null}function Rn(e,{plugin:t,local:s},i,n){const o=e.pluginScopeKeys(t),a=e.getOptionScopes(i,o);return s&&t.defaults&&a.push(t.defaults),e.createResolver(a,n,[""],{scriptable:!1,indexable:!1,allKeys:!0})}function Wn(e,t){const s=Jt.datasets[e]||{};return((t.datasets||{})[e]||{}).indexAxis||t.indexAxis||s.indexAxis||"x"}function jn(e){if("x"===e||"y"===e||"r"===e)return e}function Vn(e){return"top"===e||"bottom"===e?"x":"left"===e||"right"===e?"y":void 0}function Un(e,...t){if(jn(e))return e;for(const s of t){const t=s.axis||Vn(s.position)||e.length>1&&jn(e[0].toLowerCase());if(t)return t}throw new Error(`Cannot determine type of '${e}' axis. Please provide 'axis' or 'position' option.`)}function Xn(e,t,s){if(s[t+"AxisID"]===e)return{axis:t}}function Jn(e){const t=e.options||(e.options={});t.plugins=qe(t.plugins,{}),t.scales=function(e,t){const s=Wt[e.type]||{scales:{}},i=t.scales||{},n=Wn(e.type,t),o=Object.create(null);return Object.keys(i).forEach(t=>{const a=i[t];if(!Le(a))return console.error(`Invalid scale configuration for scale: ${t}`);if(a._proxy)return console.warn(`Ignoring resolver passed as options for scale: ${t}`);const r=Un(t,a,function(e,t){if(t.data&&t.data.datasets){const s=t.data.datasets.filter(t=>t.xAxisID===e||t.yAxisID===e);if(s.length)return Xn(e,"x",s[0])||Xn(e,"y",s[0])}return{}}(t,e),Jt.scales[a.type]),l=function(e,t){return e===t?"_index_":"_value_"}(r,n),c=s.scales||{};o[t]=Qe(Object.create(null),[{axis:r},a,c[r],c[l]])}),e.data.datasets.forEach(s=>{const n=s.type||e.type,a=s.indexAxis||Wn(n,t),r=(Wt[n]||{}).scales||{};Object.keys(r).forEach(e=>{const t=function(e,t){let s=e;return"_index_"===e?s=t:"_value_"===e&&(s="x"===t?"y":"x"),s}(e,a),n=s[t+"AxisID"]||t;o[n]=o[n]||Object.create(null),Qe(o[n],[{axis:t},i[n],r[e]])})}),Object.keys(o).forEach(e=>{const t=o[e];Qe(t,[Jt.scales[t.type],Jt.scale])}),o}(e,t)}function Gn(e){return(e=e||{}).datasets=e.datasets||[],e.labels=e.labels||[],e}const Yn=new Map,Kn=new Set;function Zn(e,t){let s=Yn.get(e);return s||(s=t(),Yn.set(e,s),Kn.add(s)),s}const eo=(e,t,s)=>{const i=We(t,s);void 0!==i&&e.add(i)};class to{constructor(e){this._config=function(e){return(e=e||{}).data=Gn(e.data),Jn(e),e}(e),this._scopeCache=new Map,this._resolverCache=new Map}get platform(){return this._config.platform}get type(){return this._config.type}set type(e){this._config.type=e}get data(){return this._config.data}set data(e){this._config.data=Gn(e)}get options(){return this._config.options}set options(e){this._config.options=e}get plugins(){return this._config.plugins}update(){const e=this._config;this.clearCache(),Jn(e)}clearCache(){this._scopeCache.clear(),this._resolverCache.clear()}datasetScopeKeys(e){return Zn(e,()=>[[`datasets.${e}`,""]])}datasetAnimationScopeKeys(e,t){return Zn(`${e}.transition.${t}`,()=>[[`datasets.${e}.transitions.${t}`,`transitions.${t}`],[`datasets.${e}`,""]])}datasetElementScopeKeys(e,t){return Zn(`${e}-${t}`,()=>[[`datasets.${e}.elements.${t}`,`datasets.${e}`,`elements.${t}`,""]])}pluginScopeKeys(e){const t=e.id;return Zn(`${this.type}-plugin-${t}`,()=>[[`plugins.${t}`,...e.additionalOptionScopes||[]]])}_cachedScopes(e,t){const s=this._scopeCache;let i=s.get(e);return i&&!t||(i=new Map,s.set(e,i)),i}getOptionScopes(e,t,s){const{options:i,type:n}=this,o=this._cachedScopes(e,s),a=o.get(t);if(a)return a;const r=new Set;t.forEach(t=>{e&&(r.add(e),t.forEach(t=>eo(r,e,t))),t.forEach(e=>eo(r,i,e)),t.forEach(e=>eo(r,Wt[n]||{},e)),t.forEach(e=>eo(r,Jt,e)),t.forEach(e=>eo(r,jt,e))});const l=Array.from(r);return 0===l.length&&l.push(Object.create(null)),Kn.has(t)&&o.set(t,l),l}chartOptionScopes(){const{options:e,type:t}=this;return[e,Wt[t]||{},Jt.datasets[t]||{},{type:t},Jt,jt]}resolveNamedOptions(e,t,s,i=[""]){const n={$shared:!0},{resolver:o,subPrefixes:a}=so(this._resolverCache,e,i);let r=o;(function(e,t){const{isScriptable:s,isIndexable:i}=Cs(e);for(const n of t){const t=s(n),o=i(n),a=(o||t)&&e[n];if(t&&(Ue(a)||io(a))||o&&Te(a))return!0}return!1})(o,t)&&(n.$shared=!1,r=Ss(o,s=Ue(s)?s():s,this.createResolver(e,s,a)));for(const e of t)n[e]=r[e];return n}createResolver(e,t,s=[""],i){const{resolver:n}=so(this._resolverCache,e,s);return Le(t)?Ss(n,t,void 0,i):n}}function so(e,t,s){let i=e.get(t);i||(i=new Map,e.set(t,i));const n=s.join();let o=i.get(n);return o||(o={resolver:xs(t,s),subPrefixes:s.filter(e=>!e.toLowerCase().includes("hover"))},i.set(n,o)),o}const io=e=>Le(e)&&Object.getOwnPropertyNames(e).some(t=>Ue(e[t])),no=["top","bottom","left","right","chartArea"];function oo(e,t){return"top"===e||"bottom"===e||-1===no.indexOf(e)&&"x"===t}function ao(e,t){return function(s,i){return s[e]===i[e]?s[t]-i[t]:s[e]-i[e]}}function ro(e){const t=e.chart,s=t.options.animation;t.notifyPlugins("afterRender"),Pe(s&&s.onComplete,[e],t)}function lo(e){const t=e.chart,s=t.options.animation;Pe(s&&s.onProgress,[e],t)}function co(e){return Ns()&&"string"==typeof e?e=document.getElementById(e):e&&e.length&&(e=e[0]),e&&e.canvas&&(e=e.canvas),e}const uo={},ho=e=>{const t=co(e);return Object.values(uo).filter(e=>e.canvas===t).pop()};function po(e,t,s){const i=Object.keys(e);for(const n of i){const i=+n;if(i>=t){const o=e[n];delete e[n],(s>0||i>t)&&(e[i+s]=o)}}}class mo{static defaults=Jt;static instances=uo;static overrides=Wt;static registry=Hn;static version="4.5.1";static getChart=ho;static register(...e){Hn.add(...e),go()}static unregister(...e){Hn.remove(...e),go()}constructor(e,t){const s=this.config=new to(t),i=co(e),n=ho(i);if(n)throw new Error("Canvas is already in use. Chart with ID '"+n.id+"' must be destroyed before the canvas with ID '"+n.canvas.id+"' can be reused.");const o=s.createResolver(s.chartOptionScopes(),this.getContext());this.platform=new(s.platform||function(e){return!Ns()||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas?un:En}(i)),this.platform.updateConfig(s);const a=this.platform.acquireContext(i,o.aspectRatio),r=a&&a.canvas,l=r&&r.height,c=r&&r.width;this.id=Ae(),this.ctx=a,this.canvas=r,this.width=c,this.height=l,this._options=o,this._aspectRatio=this.aspectRatio,this._layers=[],this._metasets=[],this._stacks=void 0,this.boxes=[],this.currentDevicePixelRatio=void 0,this.chartArea=void 0,this._active=[],this._lastEvent=void 0,this._listeners={},this._responsiveListeners=void 0,this._sortedMetasets=[],this.scales={},this._plugins=new Qn,this.$proxies={},this._hiddenIndices={},this.attached=!1,this._animationsDisabled=void 0,this.$context=void 0,this._doResize=function(e,t){let s;return function(...i){return t?(clearTimeout(s),s=setTimeout(e,t,i)):e.apply(this,i),t}}(e=>this.update(e),o.resizeDelay||0),this._dataChanges=[],uo[this.id]=this,a&&r?(mi.listen(this,"complete",ro),mi.listen(this,"progress",lo),this._initialize(),this.attached&&this.update()):console.error("Failed to create chart: can't acquire context from the given item")}get aspectRatio(){const{options:{aspectRatio:e,maintainAspectRatio:t},width:s,height:i,_aspectRatio:n}=this;return Ee(e)?t&&n?n:i?s/i:null:e}get data(){return this.config.data}set data(e){this.config.data=e}get options(){return this._options}set options(e){this.config.options=e}get registry(){return Hn}_initialize(){return this.notifyPlugins("beforeInit"),this.options.responsive?this.resize():Gs(this,this.options.devicePixelRatio),this.bindEvents(),this.notifyPlugins("afterInit"),this}clear(){return Zt(this.canvas,this.ctx),this}stop(){return mi.stop(this),this}resize(e,t){mi.running(this)?this._resizeBeforeDraw={width:e,height:t}:this._resize(e,t)}_resize(e,t){const s=this.options,i=this.canvas,n=s.maintainAspectRatio&&this.aspectRatio,o=this.platform.getMaximumSize(i,e,t,n),a=s.devicePixelRatio||this.platform.getDevicePixelRatio(),r=this.width?"resize":"attach";this.width=o.width,this.height=o.height,this._aspectRatio=this.aspectRatio,Gs(this,a,!0)&&(this.notifyPlugins("resize",{size:o}),Pe(s.onResize,[this,o],this),this.attached&&this._doResize(r)&&this.render())}ensureScalesHaveIDs(){Me(this.options.scales||{},(e,t)=>{e.id=t})}buildOrUpdateScales(){const e=this.options,t=e.scales,s=this.scales,i=Object.keys(s).reduce((e,t)=>(e[t]=!1,e),{});let n=[];t&&(n=n.concat(Object.keys(t).map(e=>{const s=t[e],i=Un(e,s),n="r"===i,o="x"===i;return{options:s,dposition:n?"chartArea":o?"bottom":"left",dtype:n?"radialLinear":o?"category":"linear"}}))),Me(n,t=>{const n=t.options,o=n.id,a=Un(o,n),r=qe(n.type,t.dtype);void 0!==n.position&&oo(n.position,a)===oo(t.dposition)||(n.position=t.dposition),i[o]=!0;let l=null;o in s&&s[o].type===r?l=s[o]:(l=new(Hn.getScale(r))({id:o,type:r,ctx:this.ctx,chart:this}),s[l.id]=l),l.init(n,e)}),Me(i,(e,t)=>{e||delete s[t]}),Me(s,e=>{cn.configure(this,e,e.options),cn.addBox(this,e)})}_updateMetasets(){const e=this._metasets,t=this.data.datasets.length,s=e.length;if(e.sort((e,t)=>e.index-t.index),s>t){for(let e=t;e<s;++e)this._destroyDatasetMeta(e);e.splice(t,s-t)}this._sortedMetasets=e.slice(0).sort(ao("order","index"))}_removeUnreferencedMetasets(){const{_metasets:e,data:{datasets:t}}=this;e.length>t.length&&delete this._stacks,e.forEach((e,s)=>{0===t.filter(t=>t===e._dataset).length&&this._destroyDatasetMeta(s)})}buildOrUpdateControllers(){const e=[],t=this.data.datasets;let s,i;for(this._removeUnreferencedMetasets(),s=0,i=t.length;s<i;s++){const i=t[s];let n=this.getDatasetMeta(s);const o=i.type||this.config.type;if(n.type&&n.type!==o&&(this._destroyDatasetMeta(s),n=this.getDatasetMeta(s)),n.type=o,n.indexAxis=i.indexAxis||Wn(o,this.options),n.order=i.order||0,n.index=s,n.label=""+i.label,n.visible=this.isDatasetVisible(s),n.controller)n.controller.updateIndex(s),n.controller.linkScales();else{const t=Hn.getController(o),{datasetElementType:i,dataElementType:a}=Jt.datasets[o];Object.assign(t,{dataElementType:Hn.getElement(a),datasetElementType:i&&Hn.getElement(i)}),n.controller=new t(this,s),e.push(n.controller)}}return this._updateMetasets(),e}_resetElements(){Me(this.data.datasets,(e,t)=>{this.getDatasetMeta(t).controller.reset()},this)}reset(){this._resetElements(),this.notifyPlugins("reset")}update(e){const t=this.config;t.update();const s=this._options=t.createResolver(t.chartOptionScopes(),this.getContext()),i=this._animationsDisabled=!s.animation;if(this._updateScales(),this._checkEventBindings(),this._updateHiddenIndices(),this._plugins.invalidate(),!1===this.notifyPlugins("beforeUpdate",{mode:e,cancelable:!0}))return;const n=this.buildOrUpdateControllers();this.notifyPlugins("beforeElementsUpdate");let o=0;for(let e=0,t=this.data.datasets.length;e<t;e++){const{controller:t}=this.getDatasetMeta(e),s=!i&&-1===n.indexOf(t);t.buildOrUpdateElements(s),o=Math.max(+t.getMaxOverflow(),o)}o=this._minPadding=s.layout.autoPadding?o:0,this._updateLayout(o),i||Me(n,e=>{e.reset()}),this._updateDatasets(e),this.notifyPlugins("afterUpdate",{mode:e}),this._layers.sort(ao("z","_idx"));const{_active:a,_lastEvent:r}=this;r?this._eventHandler(r,!0):a.length&&this._updateHoverStyles(a,a,!0),this.render()}_updateScales(){Me(this.scales,e=>{cn.removeBox(this,e)}),this.ensureScalesHaveIDs(),this.buildOrUpdateScales()}_checkEventBindings(){const e=this.options,t=new Set(Object.keys(this._listeners)),s=new Set(e.events);Xe(t,s)&&!!this._responsiveListeners===e.responsive||(this.unbindEvents(),this.bindEvents())}_updateHiddenIndices(){const{_hiddenIndices:e}=this,t=this._getUniformDataChanges()||[];for(const{method:s,start:i,count:n}of t)po(e,i,"_removeElements"===s?-n:n)}_getUniformDataChanges(){const e=this._dataChanges;if(!e||!e.length)return;this._dataChanges=[];const t=this.data.datasets.length,s=t=>new Set(e.filter(e=>e[0]===t).map((e,t)=>t+","+e.splice(1).join(","))),i=s(0);for(let e=1;e<t;e++)if(!Xe(i,s(e)))return;return Array.from(i).map(e=>e.split(",")).map(e=>({method:e[1],start:+e[2],count:+e[3]}))}_updateLayout(e){if(!1===this.notifyPlugins("beforeLayout",{cancelable:!0}))return;cn.update(this,this.width,this.height,e);const t=this.chartArea,s=t.width<=0||t.height<=0;this._layers=[],Me(this.boxes,e=>{s&&"chartArea"===e.position||(e.configure&&e.configure(),this._layers.push(...e._layers()))},this),this._layers.forEach((e,t)=>{e._idx=t}),this.notifyPlugins("afterLayout")}_updateDatasets(e){if(!1!==this.notifyPlugins("beforeDatasetsUpdate",{mode:e,cancelable:!0})){for(let e=0,t=this.data.datasets.length;e<t;++e)this.getDatasetMeta(e).controller.configure();for(let t=0,s=this.data.datasets.length;t<s;++t)this._updateDataset(t,Ue(e)?e({datasetIndex:t}):e);this.notifyPlugins("afterDatasetsUpdate",{mode:e})}}_updateDataset(e,t){const s=this.getDatasetMeta(e),i={meta:s,index:e,mode:t,cancelable:!0};!1!==this.notifyPlugins("beforeDatasetUpdate",i)&&(s.controller._update(t),i.cancelable=!1,this.notifyPlugins("afterDatasetUpdate",i))}render(){!1!==this.notifyPlugins("beforeRender",{cancelable:!0})&&(mi.has(this)?this.attached&&!mi.running(this)&&mi.start(this):(this.draw(),ro({chart:this})))}draw(){let e;if(this._resizeBeforeDraw){const{width:e,height:t}=this._resizeBeforeDraw;this._resizeBeforeDraw=null,this._resize(e,t)}if(this.clear(),this.width<=0||this.height<=0)return;if(!1===this.notifyPlugins("beforeDraw",{cancelable:!0}))return;const t=this._layers;for(e=0;e<t.length&&t[e].z<=0;++e)t[e].draw(this.chartArea);for(this._drawDatasets();e<t.length;++e)t[e].draw(this.chartArea);this.notifyPlugins("afterDraw")}_getSortedDatasetMetas(e){const t=this._sortedMetasets,s=[];let i,n;for(i=0,n=t.length;i<n;++i){const n=t[i];e&&!n.visible||s.push(n)}return s}getSortedVisibleDatasetMetas(){return this._getSortedDatasetMetas(!0)}_drawDatasets(){if(!1===this.notifyPlugins("beforeDatasetsDraw",{cancelable:!0}))return;const e=this.getSortedVisibleDatasetMetas();for(let t=e.length-1;t>=0;--t)this._drawDataset(e[t]);this.notifyPlugins("afterDatasetsDraw")}_drawDataset(e){const t=this.ctx,s={meta:e,index:e.index,cancelable:!0},i=hi(this,e);!1!==this.notifyPlugins("beforeDatasetDraw",s)&&(i&&is(t,i),e.controller.draw(),i&&ns(t),s.cancelable=!1,this.notifyPlugins("afterDatasetDraw",s))}isPointInArea(e){return ss(e,this.chartArea,this._minPadding)}getElementsAtEventForMode(e,t,s,i){const n=Gi.modes[t];return"function"==typeof n?n(this,e,s,i):[]}getDatasetMeta(e){const t=this.data.datasets[e],s=this._metasets;let i=s.filter(e=>e&&e._dataset===t).pop();return i||(i={type:null,data:[],dataset:null,controller:null,hidden:null,xAxisID:null,yAxisID:null,order:t&&t.order||0,index:e,_dataset:t,_parsed:[],_sorted:!1},s.push(i)),i}getContext(){return this.$context||(this.$context=_s(null,{chart:this,type:"chart"}))}getVisibleDatasetCount(){return this.getSortedVisibleDatasetMetas().length}isDatasetVisible(e){const t=this.data.datasets[e];if(!t)return!1;const s=this.getDatasetMeta(e);return"boolean"==typeof s.hidden?!s.hidden:!t.hidden}setDatasetVisibility(e,t){this.getDatasetMeta(e).hidden=!t}toggleDataVisibility(e){this._hiddenIndices[e]=!this._hiddenIndices[e]}getDataVisibility(e){return!this._hiddenIndices[e]}_updateVisibility(e,t,s){const i=s?"show":"hide",n=this.getDatasetMeta(e),o=n.controller._resolveAnimations(void 0,i);Ve(t)?(n.data[t].hidden=!s,this.update()):(this.setDatasetVisibility(e,s),o.update(n,{visible:s}),this.update(t=>t.datasetIndex===e?i:void 0))}hide(e,t){this._updateVisibility(e,t,!1)}show(e,t){this._updateVisibility(e,t,!0)}_destroyDatasetMeta(e){const t=this._metasets[e];t&&t.controller&&t.controller._destroy(),delete this._metasets[e]}_stop(){let e,t;for(this.stop(),mi.remove(this),e=0,t=this.data.datasets.length;e<t;++e)this._destroyDatasetMeta(e)}destroy(){this.notifyPlugins("beforeDestroy");const{canvas:e,ctx:t}=this;this._stop(),this.config.clearCache(),e&&(this.unbindEvents(),Zt(e,t),this.platform.releaseContext(t),this.canvas=null,this.ctx=null),delete uo[this.id],this.notifyPlugins("afterDestroy")}toBase64Image(...e){return this.canvas.toDataURL(...e)}bindEvents(){this.bindUserEvents(),this.options.responsive?this.bindResponsiveEvents():this.attached=!0}bindUserEvents(){const e=this._listeners,t=this.platform,s=(s,i)=>{t.addEventListener(this,s,i),e[s]=i},i=(e,t,s)=>{e.offsetX=t,e.offsetY=s,this._eventHandler(e)};Me(this.options.events,e=>s(e,i))}bindResponsiveEvents(){this._responsiveListeners||(this._responsiveListeners={});const e=this._responsiveListeners,t=this.platform,s=(s,i)=>{t.addEventListener(this,s,i),e[s]=i},i=(s,i)=>{e[s]&&(t.removeEventListener(this,s,i),delete e[s])},n=(e,t)=>{this.canvas&&this.resize(e,t)};let o;const a=()=>{i("attach",a),this.attached=!0,this.resize(),s("resize",n),s("detach",o)};o=()=>{this.attached=!1,i("resize",n),this._stop(),this._resize(0,0),s("attach",a)},t.isAttached(this.canvas)?a():o()}unbindEvents(){Me(this._listeners,(e,t)=>{this.platform.removeEventListener(this,t,e)}),this._listeners={},Me(this._responsiveListeners,(e,t)=>{this.platform.removeEventListener(this,t,e)}),this._responsiveListeners=void 0}updateHoverStyle(e,t,s){const i=s?"set":"remove";let n,o,a,r;for("dataset"===t&&(n=this.getDatasetMeta(e[0].datasetIndex),n.controller["_"+i+"DatasetHoverStyle"]()),a=0,r=e.length;a<r;++a){o=e[a];const t=o&&this.getDatasetMeta(o.datasetIndex).controller;t&&t[i+"HoverStyle"](o.element,o.datasetIndex,o.index)}}getActiveElements(){return this._active||[]}setActiveElements(e){const t=this._active||[],s=e.map(({datasetIndex:e,index:t})=>{const s=this.getDatasetMeta(e);if(!s)throw new Error("No dataset found at index "+e);return{datasetIndex:e,element:s.data[t],index:t}});!Oe(s,t)&&(this._active=s,this._lastEvent=null,this._updateHoverStyles(s,t))}notifyPlugins(e,t,s){return this._plugins.notify(this,e,t,s)}isPluginEnabled(e){return 1===this._plugins._cache.filter(t=>t.plugin.id===e).length}_updateHoverStyles(e,t,s){const i=this.options.hover,n=(e,t)=>e.filter(e=>!t.some(t=>e.datasetIndex===t.datasetIndex&&e.index===t.index)),o=n(t,e),a=s?e:n(e,t);o.length&&this.updateHoverStyle(o,i.mode,!1),a.length&&i.mode&&this.updateHoverStyle(a,i.mode,!0)}_eventHandler(e,t){const s={event:e,replay:t,cancelable:!0,inChartArea:this.isPointInArea(e)},i=t=>(t.options.events||this.options.events).includes(e.native.type);if(!1===this.notifyPlugins("beforeEvent",s,i))return;const n=this._handleEvent(e,t,s.inChartArea);return s.cancelable=!1,this.notifyPlugins("afterEvent",s,i),(n||s.changed)&&this.render(),this}_handleEvent(e,t,s){const{_active:i=[],options:n}=this,o=t,a=this._getActiveElements(e,i,s,o),r=function(e){return"mouseup"===e.type||"click"===e.type||"contextmenu"===e.type}(e),l=function(e,t,s,i){return s&&"mouseout"!==e.type?i?t:e:null}(e,this._lastEvent,s,r);s&&(this._lastEvent=null,Pe(n.onHover,[e,a,this],this),r&&Pe(n.onClick,[e,a,this],this));const c=!Oe(a,i);return(c||t)&&(this._active=a,this._updateHoverStyles(a,i,t)),this._lastEvent=l,c}_getActiveElements(e,t,s,i){if("mouseout"===e.type)return[];if(!s)return t;const n=this.options.hover;return this.getElementsAtEventForMode(e,n.mode,n,i)}}function go(){return Me(mo.instances,e=>e._plugins.invalidate())}function fo(e,t,s,i){return{x:s+e*Math.cos(t),y:i+e*Math.sin(t)}}function bo(e,t,s,i,n,o){const{x:a,y:r,startAngle:l,pixelMargin:c,innerRadius:d}=t,u=Math.max(t.outerRadius+i+s-c,0),h=d>0?d+i+s+c:0;let p=0;const m=n-l;if(i){const e=((d>0?d-i:0)+(u>0?u-i:0))/2;p=(m-(0!==e?m*e/(e+i):m))/2}const g=(m-Math.max(.001,m*u-s/Je)/u)/2,f=l+g+p,b=n-g-p,{outerStart:v,outerEnd:y,innerStart:w,innerEnd:_}=function(e,t,s,i){const n=gs(e.options.borderRadius,["outerStart","outerEnd","innerStart","innerEnd"]),o=(s-t)/2,a=Math.min(o,i*t/2),r=e=>{const t=(s-Math.min(o,e))*i/2;return bt(e,0,Math.min(o,t))};return{outerStart:r(n.outerStart),outerEnd:r(n.outerEnd),innerStart:bt(n.innerStart,0,a),innerEnd:bt(n.innerEnd,0,a)}}(t,h,u,b-f),x=u-v,S=u-y,C=f+v/x,k=b-y/S,A=h+w,E=h+_,T=f+w/A,L=b-_/E;if(e.beginPath(),o){const t=(C+k)/2;if(e.arc(a,r,u,C,t),e.arc(a,r,u,t,k),y>0){const t=fo(S,k,a,r);e.arc(t.x,t.y,y,k,b+et)}const s=fo(E,b,a,r);if(e.lineTo(s.x,s.y),_>0){const t=fo(E,L,a,r);e.arc(t.x,t.y,_,b+et,L+Math.PI)}const i=(b-_/h+(f+w/h))/2;if(e.arc(a,r,h,b-_/h,i,!0),e.arc(a,r,h,i,f+w/h,!0),w>0){const t=fo(A,T,a,r);e.arc(t.x,t.y,w,T+Math.PI,f-et)}const n=fo(x,f,a,r);if(e.lineTo(n.x,n.y),v>0){const t=fo(x,C,a,r);e.arc(t.x,t.y,v,f-et,C)}}else{e.moveTo(a,r);const t=Math.cos(C)*u+a,s=Math.sin(C)*u+r;e.lineTo(t,s);const i=Math.cos(k)*u+a,n=Math.sin(k)*u+r;e.lineTo(i,n)}e.closePath()}function vo(e,t,s=t){e.lineCap=qe(s.borderCapStyle,t.borderCapStyle),e.setLineDash(qe(s.borderDash,t.borderDash)),e.lineDashOffset=qe(s.borderDashOffset,t.borderDashOffset),e.lineJoin=qe(s.borderJoinStyle,t.borderJoinStyle),e.lineWidth=qe(s.borderWidth,t.borderWidth),e.strokeStyle=qe(s.borderColor,t.borderColor)}function yo(e,t,s){e.lineTo(s.x,s.y)}function wo(e,t,s={}){const i=e.length,{start:n=0,end:o=i-1}=s,{start:a,end:r}=t,l=Math.max(n,a),c=Math.min(o,r),d=n<a&&o<a||n>r&&o>r;return{count:i,start:l,loop:t.loop,ilen:c<l&&!d?i+c-l:c-l}}function _o(e,t,s,i){const{points:n,options:o}=t,{count:a,start:r,loop:l,ilen:c}=wo(n,s,i),d=function(e){return e.stepped?os:e.tension||"monotone"===e.cubicInterpolationMode?as:yo}(o);let u,h,p,{move:m=!0,reverse:g}=i||{};for(u=0;u<=c;++u)h=n[(r+(g?c-u:u))%a],h.skip||(m?(e.moveTo(h.x,h.y),m=!1):d(e,p,h,g,o.stepped),p=h);return l&&(h=n[(r+(g?c:0))%a],d(e,p,h,g,o.stepped)),!!l}function xo(e,t,s,i){const n=t.points,{count:o,start:a,ilen:r}=wo(n,s,i),{move:l=!0,reverse:c}=i||{};let d,u,h,p,m,g,f=0,b=0;const v=e=>(a+(c?r-e:e))%o,y=()=>{p!==m&&(e.lineTo(f,m),e.lineTo(f,p),e.lineTo(f,g))};for(l&&(u=n[v(0)],e.moveTo(u.x,u.y)),d=0;d<=r;++d){if(u=n[v(d)],u.skip)continue;const t=u.x,s=u.y,i=0|t;i===h?(s<p?p=s:s>m&&(m=s),f=(b*f+t)/++b):(y(),e.lineTo(t,s),h=i,b=0,p=m=s),g=s}y()}function So(e){const t=e.options,s=t.borderDash&&t.borderDash.length;return e._decimated||e._loop||t.tension||"monotone"===t.cubicInterpolationMode||t.stepped||s?_o:xo}const Co="function"==typeof Path2D;class ko extends Tn{static id="line";static defaults={borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:3,capBezierPoints:!0,cubicInterpolationMode:"default",fill:!1,spanGaps:!1,stepped:!1,tension:0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};static descriptors={_scriptable:!0,_indexable:e=>"borderDash"!==e&&"fill"!==e};constructor(e){super(),this.animated=!0,this.options=void 0,this._chart=void 0,this._loop=void 0,this._fullLoop=void 0,this._path=void 0,this._points=void 0,this._segments=void 0,this._decimated=!1,this._pointsUpdated=!1,this._datasetIndex=void 0,e&&Object.assign(this,e)}updateControlPoints(e,t){const s=this.options;if((s.tension||"monotone"===s.cubicInterpolationMode)&&!s.stepped&&!this._pointsUpdated){const i=s.spanGaps?this._loop:this._fullLoop;Qs(this._points,s,e,i,t),this._pointsUpdated=!0}}set points(e){this._points=e,delete this._segments,delete this._path,this._pointsUpdated=!1}get points(){return this._points}get segments(){return this._segments||(this._segments=function(e,t){const s=e.points,i=e.options.spanGaps,n=s.length;if(!n)return[];const o=!!e._loop,{start:a,end:r}=function(e,t,s,i){let n=0,o=t-1;if(s&&!i)for(;n<t&&!e[n].skip;)n++;for(;n<t&&e[n].skip;)n++;for(n%=t,s&&(o+=n);o>n&&e[o%t].skip;)o--;return o%=t,{start:n,end:o}}(s,n,o,i);return function(e,t,s,i){return i&&i.setContext&&s?function(e,t,s,i){const n=e._chart.getContext(),o=ci(e.options),{_datasetIndex:a,options:{spanGaps:r}}=e,l=s.length,c=[];let d=o,u=t[0].start,h=u;function p(e,t,i,n){const o=r?-1:1;if(e!==t){for(e+=l;s[e%l].skip;)e-=o;for(;s[t%l].skip;)t+=o;e%l!==t%l&&(c.push({start:e%l,end:t%l,loop:i,style:n}),d=n,u=t%l)}}for(const e of t){u=r?u:e.start;let t,o=s[u%l];for(h=u+1;h<=e.end;h++){const r=s[h%l];t=ci(i.setContext(_s(n,{type:"segment",p0:o,p1:r,p0DataIndex:(h-1)%l,p1DataIndex:h%l,datasetIndex:a}))),di(t,d)&&p(u,h-1,e.loop,d),o=r,d=t}u<h-1&&p(u,h-1,e.loop,d)}return c}(e,t,s,i):t}(e,!0===i?[{start:a,end:r,loop:o}]:function(e,t,s,i){const n=e.length,o=[];let a,r=t,l=e[t];for(a=t+1;a<=s;++a){const s=e[a%n];s.skip||s.stop?l.skip||(i=!1,o.push({start:t%n,end:(a-1)%n,loop:i}),t=r=s.stop?a:null):(r=a,l.skip&&(t=a)),l=s}return null!==r&&o.push({start:t%n,end:r%n,loop:i}),o}(s,a,r<a?r+n:r,!!e._fullLoop&&0===a&&r===n-1),s,t)}(this,this.options.segment))}first(){const e=this.segments,t=this.points;return e.length&&t[e[0].start]}last(){const e=this.segments,t=this.points,s=e.length;return s&&t[e[s-1].end]}interpolate(e,t){const s=this.options,i=e[t],n=this.points,o=li(this,{property:t,start:i,end:i});if(!o.length)return;const a=[],r=function(e){return e.stepped?ei:e.tension||"monotone"===e.cubicInterpolationMode?ti:Zs}(s);let l,c;for(l=0,c=o.length;l<c;++l){const{start:c,end:d}=o[l],u=n[c],h=n[d];if(u===h){a.push(u);continue}const p=r(u,h,Math.abs((i-u[t])/(h[t]-u[t])),s.stepped);p[t]=e[t],a.push(p)}return 1===a.length?a[0]:a}pathSegment(e,t,s){return So(this)(e,this,t,s)}path(e,t,s){const i=this.segments,n=So(this);let o=this._loop;t=t||0,s=s||this.points.length-t;for(const a of i)o&=n(e,this,a,{start:t,end:t+s-1});return!!o}draw(e,t,s,i){const n=this.options||{};(this.points||[]).length&&n.borderWidth&&(e.save(),function(e,t,s,i){Co&&!t.options.segment?function(e,t,s,i){let n=t._path;n||(n=t._path=new Path2D,t.path(n,s,i)&&n.closePath()),vo(e,t.options),e.stroke(n)}(e,t,s,i):function(e,t,s,i){const{segments:n,options:o}=t,a=So(t);for(const r of n)vo(e,o,r.style),e.beginPath(),a(e,t,r,{start:s,end:s+i-1})&&e.closePath(),e.stroke()}(e,t,s,i)}(e,this,s,i),e.restore()),this.animated&&(this._pointsUpdated=!1,this._path=void 0)}}function Ao(e,t,s,i){const n=e.options,{[s]:o}=e.getProps([s],i);return Math.abs(t-o)<n.radius+n.hitRadius}function Eo(e,t){const{x:s,y:i,base:n,width:o,height:a}=e.getProps(["x","y","base","width","height"],t);let r,l,c,d,u;return e.horizontal?(u=a/2,r=Math.min(s,n),l=Math.max(s,n),c=i-u,d=i+u):(u=o/2,r=s-u,l=s+u,c=Math.min(i,n),d=Math.max(i,n)),{left:r,top:c,right:l,bottom:d}}function To(e,t,s,i){return e?0:bt(t,s,i)}function Lo(e,t,s,i){const n=null===t,o=null===s,a=e&&!(n&&o)&&Eo(e,i);return a&&(n||vt(t,a.left,a.right))&&(o||vt(s,a.top,a.bottom))}function Io(e,t){e.rect(t.x,t.y,t.w,t.h)}function Do(e,t,s={}){const i=e.x!==s.x?-t:0,n=e.y!==s.y?-t:0,o=(e.x+e.w!==s.x+s.w?t:0)-i,a=(e.y+e.h!==s.y+s.h?t:0)-n;return{x:e.x+i,y:e.y+n,w:e.w+o,h:e.h+a,radius:e.radius}}var qo=Object.freeze({__proto__:null,ArcElement:class extends Tn{static id="arc";static defaults={borderAlign:"center",borderColor:"#fff",borderDash:[],borderDashOffset:0,borderJoinStyle:void 0,borderRadius:0,borderWidth:2,offset:0,spacing:0,angle:void 0,circular:!0,selfJoin:!1};static defaultRoutes={backgroundColor:"backgroundColor"};static descriptors={_scriptable:!0,_indexable:e=>"borderDash"!==e};circumference;endAngle;fullCircles;innerRadius;outerRadius;pixelMargin;startAngle;constructor(e){super(),this.options=void 0,this.circumference=void 0,this.startAngle=void 0,this.endAngle=void 0,this.innerRadius=void 0,this.outerRadius=void 0,this.pixelMargin=0,this.fullCircles=0,e&&Object.assign(this,e)}inRange(e,t,s){const i=this.getProps(["x","y"],s),{angle:n,distance:o}=ht(i,{x:e,y:t}),{startAngle:a,endAngle:r,innerRadius:l,outerRadius:c,circumference:d}=this.getProps(["startAngle","endAngle","innerRadius","outerRadius","circumference"],s),u=(this.options.spacing+this.options.borderWidth)/2,h=qe(d,r-a),p=ft(n,a,r)&&a!==r,m=h>=Ge||p,g=vt(o,l+u,c+u);return m&&g}getCenterPoint(e){const{x:t,y:s,startAngle:i,endAngle:n,innerRadius:o,outerRadius:a}=this.getProps(["x","y","startAngle","endAngle","innerRadius","outerRadius"],e),{offset:r,spacing:l}=this.options,c=(i+n)/2,d=(o+a+l+r)/2;return{x:t+Math.cos(c)*d,y:s+Math.sin(c)*d}}tooltipPosition(e){return this.getCenterPoint(e)}draw(e){const{options:t,circumference:s}=this,i=(t.offset||0)/4,n=(t.spacing||0)/2,o=t.circular;if(this.pixelMargin="inner"===t.borderAlign?.33:0,this.fullCircles=s>Ge?Math.floor(s/Ge):0,0===s||this.innerRadius<0||this.outerRadius<0)return;e.save();const a=(this.startAngle+this.endAngle)/2;e.translate(Math.cos(a)*i,Math.sin(a)*i);const r=i*(1-Math.sin(Math.min(Je,s||0)));e.fillStyle=t.backgroundColor,e.strokeStyle=t.borderColor,function(e,t,s,i,n){const{fullCircles:o,startAngle:a,circumference:r}=t;let l=t.endAngle;if(o){bo(e,t,s,i,l,n);for(let t=0;t<o;++t)e.fill();isNaN(r)||(l=a+(r%Ge||Ge))}bo(e,t,s,i,l,n),e.fill()}(e,this,r,n,o),function(e,t,s,i,n){const{fullCircles:o,startAngle:a,circumference:r,options:l}=t,{borderWidth:c,borderJoinStyle:d,borderDash:u,borderDashOffset:h,borderRadius:p}=l,m="inner"===l.borderAlign;if(!c)return;e.setLineDash(u||[]),e.lineDashOffset=h,m?(e.lineWidth=2*c,e.lineJoin=d||"round"):(e.lineWidth=c,e.lineJoin=d||"bevel");let g=t.endAngle;if(o){bo(e,t,s,i,g,n);for(let t=0;t<o;++t)e.stroke();isNaN(r)||(g=a+(r%Ge||Ge))}m&&function(e,t,s){const{startAngle:i,pixelMargin:n,x:o,y:a,outerRadius:r,innerRadius:l}=t;let c=n/r;e.beginPath(),e.arc(o,a,r,i-c,s+c),l>n?(c=n/l,e.arc(o,a,l,s+c,i-c,!0)):e.arc(o,a,n,s+et,i-et),e.closePath(),e.clip()}(e,t,g),l.selfJoin&&g-a>=Je&&0===p&&"miter"!==d&&function(e,t,s){const{startAngle:i,x:n,y:o,outerRadius:a,innerRadius:r,options:l}=t,{borderWidth:c,borderJoinStyle:d}=l,u=Math.min(c/a,gt(i-s));if(e.beginPath(),e.arc(n,o,a-c/2,i+u/2,s-u/2),r>0){const t=Math.min(c/r,gt(i-s));e.arc(n,o,r+c/2,s-t/2,i+t/2,!0)}else{const t=Math.min(c/2,a*gt(i-s));if("round"===d)e.arc(n,o,t,s-Je/2,i+Je/2,!0);else if("bevel"===d){const a=2*t*t,r=-a*Math.cos(s+Je/2)+n,l=-a*Math.sin(s+Je/2)+o,c=a*Math.cos(i+Je/2)+n,d=a*Math.sin(i+Je/2)+o;e.lineTo(r,l),e.lineTo(c,d)}}e.closePath(),e.moveTo(0,0),e.rect(0,0,e.canvas.width,e.canvas.height),e.clip("evenodd")}(e,t,g),o||(bo(e,t,s,i,g,n),e.stroke())}(e,this,r,n,o),e.restore()}},BarElement:class extends Tn{static id="bar";static defaults={borderSkipped:"start",borderWidth:0,borderRadius:0,inflateAmount:"auto",pointStyle:void 0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};constructor(e){super(),this.options=void 0,this.horizontal=void 0,this.base=void 0,this.width=void 0,this.height=void 0,this.inflateAmount=void 0,e&&Object.assign(this,e)}draw(e){const{inflateAmount:t,options:{borderColor:s,backgroundColor:i}}=this,{inner:n,outer:o}=function(e){const t=Eo(e),s=t.right-t.left,i=t.bottom-t.top,n=function(e,t,s){const i=e.options.borderWidth,n=e.borderSkipped,o=fs(i);return{t:To(n.top,o.top,0,s),r:To(n.right,o.right,0,t),b:To(n.bottom,o.bottom,0,s),l:To(n.left,o.left,0,t)}}(e,s/2,i/2),o=function(e,t,s){const{enableBorderRadius:i}=e.getProps(["enableBorderRadius"]),n=e.options.borderRadius,o=bs(n),a=Math.min(t,s),r=e.borderSkipped,l=i||Le(n);return{topLeft:To(!l||r.top||r.left,o.topLeft,0,a),topRight:To(!l||r.top||r.right,o.topRight,0,a),bottomLeft:To(!l||r.bottom||r.left,o.bottomLeft,0,a),bottomRight:To(!l||r.bottom||r.right,o.bottomRight,0,a)}}(e,s/2,i/2);return{outer:{x:t.left,y:t.top,w:s,h:i,radius:o},inner:{x:t.left+n.l,y:t.top+n.t,w:s-n.l-n.r,h:i-n.t-n.b,radius:{topLeft:Math.max(0,o.topLeft-Math.max(n.t,n.l)),topRight:Math.max(0,o.topRight-Math.max(n.t,n.r)),bottomLeft:Math.max(0,o.bottomLeft-Math.max(n.b,n.l)),bottomRight:Math.max(0,o.bottomRight-Math.max(n.b,n.r))}}}}(this),a=(r=o.radius).topLeft||r.topRight||r.bottomLeft||r.bottomRight?ds:Io;var r;e.save(),o.w===n.w&&o.h===n.h||(e.beginPath(),a(e,Do(o,t,n)),e.clip(),a(e,Do(n,-t,o)),e.fillStyle=s,e.fill("evenodd")),e.beginPath(),a(e,Do(n,t)),e.fillStyle=i,e.fill(),e.restore()}inRange(e,t,s){return Lo(this,e,t,s)}inXRange(e,t){return Lo(this,e,null,t)}inYRange(e,t){return Lo(this,null,e,t)}getCenterPoint(e){const{x:t,y:s,base:i,horizontal:n}=this.getProps(["x","y","base","horizontal"],e);return{x:n?(t+i)/2:t,y:n?s:(s+i)/2}}getRange(e){return"x"===e?this.width/2:this.height/2}},LineElement:ko,PointElement:class extends Tn{static id="point";parsed;skip;stop;static defaults={borderWidth:1,hitRadius:1,hoverBorderWidth:1,hoverRadius:4,pointStyle:"circle",radius:3,rotation:0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};constructor(e){super(),this.options=void 0,this.parsed=void 0,this.skip=void 0,this.stop=void 0,e&&Object.assign(this,e)}inRange(e,t,s){const i=this.options,{x:n,y:o}=this.getProps(["x","y"],s);return Math.pow(e-n,2)+Math.pow(t-o,2)<Math.pow(i.hitRadius+i.radius,2)}inXRange(e,t){return Ao(this,e,"x",t)}inYRange(e,t){return Ao(this,e,"y",t)}getCenterPoint(e){const{x:t,y:s}=this.getProps(["x","y"],e);return{x:t,y:s}}size(e){let t=(e=e||this.options||{}).radius||0;return t=Math.max(t,t&&e.hoverRadius||0),2*(t+(t&&e.borderWidth||0))}draw(e,t){const s=this.options;this.skip||s.radius<.1||!ss(this,t,this.size(s)/2)||(e.strokeStyle=s.borderColor,e.lineWidth=s.borderWidth,e.fillStyle=s.backgroundColor,es(e,s,this.x,this.y))}getRange(){const e=this.options||{};return e.radius+e.hitRadius}}});const Bo=["rgb(54, 162, 235)","rgb(255, 99, 132)","rgb(255, 159, 64)","rgb(255, 205, 86)","rgb(75, 192, 192)","rgb(153, 102, 255)","rgb(201, 203, 207)"],Po=Bo.map(e=>e.replace("rgb(","rgba(").replace(")",", 0.5)"));function Mo(e){return Bo[e%Bo.length]}function Oo(e){return Po[e%Po.length]}function zo(e){let t;for(t in e)if(e[t].borderColor||e[t].backgroundColor)return!0;return!1}var $o={id:"colors",defaults:{enabled:!0,forceOverride:!1},beforeLayout(e,t,s){if(!s.enabled)return;const{data:{datasets:i},options:n}=e.config,{elements:o}=n,a=zo(i)||(r=n)&&(r.borderColor||r.backgroundColor)||o&&zo(o)||"rgba(0,0,0,0.1)"!==Jt.borderColor||"rgba(0,0,0,0.1)"!==Jt.backgroundColor;var r;if(!s.forceOverride&&a)return;const l=function(e){let t=0;return(s,i)=>{const n=e.getDatasetMeta(i).controller;n instanceof Fi?t=function(e,t){return e.backgroundColor=e.data.map(()=>Mo(t++)),t}(s,t):n instanceof Hi?t=function(e,t){return e.backgroundColor=e.data.map(()=>Oo(t++)),t}(s,t):n&&(t=function(e,t){return e.borderColor=Mo(t),e.backgroundColor=Oo(t),++t}(s,t))}}(e);i.forEach(l)}};function Fo(e){if(e._decimated){const t=e._data;delete e._decimated,delete e._data,Object.defineProperty(e,"data",{configurable:!0,enumerable:!0,writable:!0,value:t})}}function Ho(e){e.data.datasets.forEach(e=>{Fo(e)})}var Qo={id:"decimation",defaults:{algorithm:"min-max",enabled:!1},beforeElementsUpdate:(e,t,s)=>{if(!s.enabled)return void Ho(e);const i=e.width;e.data.datasets.forEach((t,n)=>{const{_data:o,indexAxis:a}=t,r=e.getDatasetMeta(n),l=o||t.data;if("y"===ws([a,e.options.indexAxis]))return;if(!r.controller.supportsDecimation)return;const c=e.scales[r.xAxisID];if("linear"!==c.type&&"time"!==c.type)return;if(e.options.parsing)return;let d,{start:u,count:h}=function(e,t){const s=t.length;let i,n=0;const{iScale:o}=e,{min:a,max:r,minDefined:l,maxDefined:c}=o.getUserBounds();return l&&(n=bt(wt(t,o.axis,a).lo,0,s-1)),i=c?bt(wt(t,o.axis,r).hi+1,n,s)-n:s-n,{start:n,count:i}}(r,l);if(h<=(s.threshold||4*i))Fo(t);else{switch(Ee(o)&&(t._data=l,delete t.data,Object.defineProperty(t,"data",{configurable:!0,enumerable:!0,get:function(){return this._decimated},set:function(e){this._data=e}})),s.algorithm){case"lttb":d=function(e,t,s,i,n){const o=n.samples||i;if(o>=s)return e.slice(t,t+s);const a=[],r=(s-2)/(o-2);let l=0;const c=t+s-1;let d,u,h,p,m,g=t;for(a[l++]=e[g],d=0;d<o-2;d++){let i,n=0,o=0;const c=Math.floor((d+1)*r)+1+t,f=Math.min(Math.floor((d+2)*r)+1,s)+t,b=f-c;for(i=c;i<f;i++)n+=e[i].x,o+=e[i].y;n/=b,o/=b;const v=Math.floor(d*r)+1+t,y=Math.min(Math.floor((d+1)*r)+1,s)+t,{x:w,y:_}=e[g];for(h=p=-1,i=v;i<y;i++)p=.5*Math.abs((w-n)*(e[i].y-_)-(w-e[i].x)*(o-_)),p>h&&(h=p,u=e[i],m=i);a[l++]=u,g=m}return a[l++]=e[c],a}(l,u,h,i,s);break;case"min-max":d=function(e,t,s,i){let n,o,a,r,l,c,d,u,h,p,m=0,g=0;const f=[],b=t+s-1,v=e[t].x,y=e[b].x-v;for(n=t;n<t+s;++n){o=e[n],a=(o.x-v)/y*i,r=o.y;const t=0|a;if(t===l)r<h?(h=r,c=n):r>p&&(p=r,d=n),m=(g*m+o.x)/++g;else{const s=n-1;if(!Ee(c)&&!Ee(d)){const t=Math.min(c,d),i=Math.max(c,d);t!==u&&t!==s&&f.push({...e[t],x:m}),i!==u&&i!==s&&f.push({...e[i],x:m})}n>0&&s!==u&&f.push(e[s]),f.push(o),l=t,g=0,h=p=r,c=d=u=n}}return f}(l,u,h,i);break;default:throw new Error(`Unsupported decimation algorithm '${s.algorithm}'`)}t._decimated=d}})},destroy(e){Ho(e)}};function No(e,t,s,i){if(i)return;let n=t[e],o=s[e];return"angle"===e&&(n=gt(n),o=gt(o)),{property:e,start:n,end:o}}function Ro(e,t,s){for(;t>e;t--){const e=s[t];if(!isNaN(e.x)&&!isNaN(e.y))break}return t}function Wo(e,t,s,i){return e&&t?i(e[s],t[s]):e?e[s]:t?t[s]:0}function jo(e,t){let s=[],i=!1;return Te(e)?(i=!0,s=e):s=function(e,t){const{x:s=null,y:i=null}=e||{},n=t.points,o=[];return t.segments.forEach(({start:e,end:t})=>{t=Ro(e,t,n);const a=n[e],r=n[t];null!==i?(o.push({x:a.x,y:i}),o.push({x:r.x,y:i})):null!==s&&(o.push({x:s,y:a.y}),o.push({x:s,y:r.y}))}),o}(e,t),s.length?new ko({points:s,options:{tension:0},_loop:i,_fullLoop:i}):null}function Vo(e){return e&&!1!==e.fill}function Uo(e,t,s){let i=e[t].fill;const n=[t];let o;if(!s)return i;for(;!1!==i&&-1===n.indexOf(i);){if(!Ie(i))return i;if(o=e[i],!o)return!1;if(o.visible)return i;n.push(i),i=o.fill}return!1}function Xo(e,t,s){const i=function(e){const t=e.options,s=t.fill;let i=qe(s&&s.target,s);return void 0===i&&(i=!!t.backgroundColor),!1!==i&&null!==i&&(!0===i?"origin":i)}(e);if(Le(i))return!isNaN(i.value)&&i;let n=parseFloat(i);return Ie(n)&&Math.floor(n)===n?function(e,t,s,i){return"-"!==e&&"+"!==e||(s=t+s),!(s===t||s<0||s>=i)&&s}(i[0],t,n,s):["origin","start","end","stack","shape"].indexOf(i)>=0&&i}function Jo(e,t,s){const i=[];for(let n=0;n<s.length;n++){const o=s[n],{first:a,last:r,point:l}=Go(o,t,"x");if(!(!l||a&&r))if(a)i.unshift(l);else if(e.push(l),!r)break}e.push(...i)}function Go(e,t,s){const i=e.interpolate(t,s);if(!i)return{};const n=i[s],o=e.segments,a=e.points;let r=!1,l=!1;for(let e=0;e<o.length;e++){const t=o[e],i=a[t.start][s],c=a[t.end][s];if(vt(n,i,c)){r=n===i,l=n===c;break}}return{first:r,last:l,point:i}}class Yo{constructor(e){this.x=e.x,this.y=e.y,this.radius=e.radius}pathSegment(e,t,s){const{x:i,y:n,radius:o}=this;return t=t||{start:0,end:Ge},e.arc(i,n,o,t.end,t.start,!0),!s.bounds}interpolate(e){const{x:t,y:s,radius:i}=this,n=e.angle;return{x:t+Math.cos(n)*i,y:s+Math.sin(n)*i,angle:n}}}function Ko(e,t,s){const i=function(e){const{chart:t,fill:s,line:i}=e;if(Ie(s))return function(e,t){const s=e.getDatasetMeta(t);return s&&e.isDatasetVisible(t)?s.dataset:null}(t,s);if("stack"===s)return function(e){const{scale:t,index:s,line:i}=e,n=[],o=i.segments,a=i.points,r=function(e,t){const s=[],i=e.getMatchingVisibleMetas("line");for(let e=0;e<i.length;e++){const n=i[e];if(n.index===t)break;n.hidden||s.unshift(n.dataset)}return s}(t,s);r.push(jo({x:null,y:t.bottom},i));for(let e=0;e<o.length;e++){const t=o[e];for(let e=t.start;e<=t.end;e++)Jo(n,a[e],r)}return new ko({points:n,options:{}})}(e);if("shape"===s)return!0;const n=function(e){return(e.scale||{}).getPointPositionForValue?function(e){const{scale:t,fill:s}=e,i=t.options,n=t.getLabels().length,o=i.reverse?t.max:t.min,a=function(e,t,s){let i;return i="start"===e?s:"end"===e?t.options.reverse?t.min:t.max:Le(e)?e.value:t.getBaseValue(),i}(s,t,o),r=[];if(i.grid.circular){const e=t.getPointPositionForValue(0,o);return new Yo({x:e.x,y:e.y,radius:t.getDistanceFromCenterForValue(a)})}for(let e=0;e<n;++e)r.push(t.getPointPositionForValue(e,a));return r}(e):function(e){const{scale:t={},fill:s}=e,i=function(e,t){let s=null;return"start"===e?s=t.bottom:"end"===e?s=t.top:Le(e)?s=t.getPixelForValue(e.value):t.getBasePixel&&(s=t.getBasePixel()),s}(s,t);if(Ie(i)){const e=t.isHorizontal();return{x:e?i:null,y:e?null:i}}return null}(e)}(e);return n instanceof Yo?n:jo(n,i)}(t),{chart:n,index:o,line:a,scale:r,axis:l}=t,c=a.options,d=c.fill,u=c.backgroundColor,{above:h=u,below:p=u}=d||{},m=n.getDatasetMeta(o),g=hi(n,m);i&&a.points.length&&(is(e,s),function(e,t){const{line:s,target:i,above:n,below:o,area:a,scale:r,clip:l}=t,c=s._loop?"angle":t.axis;e.save();let d=o;o!==n&&("x"===c?(Zo(e,i,a.top),ta(e,{line:s,target:i,color:n,scale:r,property:c,clip:l}),e.restore(),e.save(),Zo(e,i,a.bottom)):"y"===c&&(ea(e,i,a.left),ta(e,{line:s,target:i,color:o,scale:r,property:c,clip:l}),e.restore(),e.save(),ea(e,i,a.right),d=n)),ta(e,{line:s,target:i,color:d,scale:r,property:c,clip:l}),e.restore()}(e,{line:a,target:i,above:h,below:p,area:s,scale:r,axis:l,clip:g}),ns(e))}function Zo(e,t,s){const{segments:i,points:n}=t;let o=!0,a=!1;e.beginPath();for(const r of i){const{start:i,end:l}=r,c=n[i],d=n[Ro(i,l,n)];o?(e.moveTo(c.x,c.y),o=!1):(e.lineTo(c.x,s),e.lineTo(c.x,c.y)),a=!!t.pathSegment(e,r,{move:a}),a?e.closePath():e.lineTo(d.x,s)}e.lineTo(t.first().x,s),e.closePath(),e.clip()}function ea(e,t,s){const{segments:i,points:n}=t;let o=!0,a=!1;e.beginPath();for(const r of i){const{start:i,end:l}=r,c=n[i],d=n[Ro(i,l,n)];o?(e.moveTo(c.x,c.y),o=!1):(e.lineTo(s,c.y),e.lineTo(c.x,c.y)),a=!!t.pathSegment(e,r,{move:a}),a?e.closePath():e.lineTo(s,d.y)}e.lineTo(s,t.first().y),e.closePath(),e.clip()}function ta(e,t){const{line:s,target:i,property:n,color:o,scale:a,clip:r}=t,l=function(e,t,s){const i=e.segments,n=e.points,o=t.points,a=[];for(const e of i){let{start:i,end:r}=e;r=Ro(i,r,n);const l=No(s,n[i],n[r],e.loop);if(!t.segments){a.push({source:e,target:l,start:n[i],end:n[r]});continue}const c=li(t,l);for(const t of c){const i=No(s,o[t.start],o[t.end],t.loop),r=ri(e,n,i);for(const e of r)a.push({source:e,target:t,start:{[s]:Wo(l,i,"start",Math.max)},end:{[s]:Wo(l,i,"end",Math.min)}})}}return a}(s,i,n);for(const{source:t,target:c,start:d,end:u}of l){const{style:{backgroundColor:l=o}={}}=t,h=!0!==i;e.save(),e.fillStyle=l,sa(e,a,r,h&&No(n,d,u)),e.beginPath();const p=!!s.pathSegment(e,t);let m;if(h){p?e.closePath():ia(e,i,u,n);const t=!!i.pathSegment(e,c,{move:p,reverse:!0});m=p&&t,m||ia(e,i,d,n)}e.closePath(),e.fill(m?"evenodd":"nonzero"),e.restore()}}function sa(e,t,s,i){const n=t.chart.chartArea,{property:o,start:a,end:r}=i||{};if("x"===o||"y"===o){let t,i,l,c;"x"===o?(t=a,i=n.top,l=r,c=n.bottom):(t=n.left,i=a,l=n.right,c=r),e.beginPath(),s&&(t=Math.max(t,s.left),l=Math.min(l,s.right),i=Math.max(i,s.top),c=Math.min(c,s.bottom)),e.rect(t,i,l-t,c-i),e.clip()}}function ia(e,t,s,i){const n=t.interpolate(s,i);n&&e.lineTo(n.x,n.y)}var na={id:"filler",afterDatasetsUpdate(e,t,s){const i=(e.data.datasets||[]).length,n=[];let o,a,r,l;for(a=0;a<i;++a)o=e.getDatasetMeta(a),r=o.dataset,l=null,r&&r.options&&r instanceof ko&&(l={visible:e.isDatasetVisible(a),index:a,fill:Xo(r,a,i),chart:e,axis:o.controller.options.indexAxis,scale:o.vScale,line:r}),o.$filler=l,n.push(l);for(a=0;a<i;++a)l=n[a],l&&!1!==l.fill&&(l.fill=Uo(n,a,s.propagate))},beforeDraw(e,t,s){const i="beforeDraw"===s.drawTime,n=e.getSortedVisibleDatasetMetas(),o=e.chartArea;for(let t=n.length-1;t>=0;--t){const s=n[t].$filler;s&&(s.line.updateControlPoints(o,s.axis),i&&s.fill&&Ko(e.ctx,s,o))}},beforeDatasetsDraw(e,t,s){if("beforeDatasetsDraw"!==s.drawTime)return;const i=e.getSortedVisibleDatasetMetas();for(let t=i.length-1;t>=0;--t){const s=i[t].$filler;Vo(s)&&Ko(e.ctx,s,e.chartArea)}},beforeDatasetDraw(e,t,s){const i=t.meta.$filler;Vo(i)&&"beforeDatasetDraw"===s.drawTime&&Ko(e.ctx,i,e.chartArea)},defaults:{propagate:!0,drawTime:"beforeDatasetDraw"}};const oa=(e,t)=>{let{boxHeight:s=t,boxWidth:i=t}=e;return e.usePointStyle&&(s=Math.min(s,t),i=e.pointStyleWidth||Math.min(i,t)),{boxWidth:i,boxHeight:s,itemHeight:Math.max(t,s)}};class aa extends Tn{constructor(e){super(),this._added=!1,this.legendHitBoxes=[],this._hoveredItem=null,this.doughnutMode=!1,this.chart=e.chart,this.options=e.options,this.ctx=e.ctx,this.legendItems=void 0,this.columnSizes=void 0,this.lineWidths=void 0,this.maxHeight=void 0,this.maxWidth=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.height=void 0,this.width=void 0,this._margins=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(e,t,s){this.maxWidth=e,this.maxHeight=t,this._margins=s,this.setDimensions(),this.buildLabels(),this.fit()}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=this._margins.left,this.right=this.width):(this.height=this.maxHeight,this.top=this._margins.top,this.bottom=this.height)}buildLabels(){const e=this.options.labels||{};let t=Pe(e.generateLabels,[this.chart],this)||[];e.filter&&(t=t.filter(t=>e.filter(t,this.chart.data))),e.sort&&(t=t.sort((t,s)=>e.sort(t,s,this.chart.data))),this.options.reverse&&t.reverse(),this.legendItems=t}fit(){const{options:e,ctx:t}=this;if(!e.display)return void(this.width=this.height=0);const s=e.labels,i=ys(s.font),n=i.size,o=this._computeTitleHeight(),{boxWidth:a,itemHeight:r}=oa(s,n);let l,c;t.font=i.string,this.isHorizontal()?(l=this.maxWidth,c=this._fitRows(o,n,a,r)+10):(c=this.maxHeight,l=this._fitCols(o,i,a,r)+10),this.width=Math.min(l,e.maxWidth||this.maxWidth),this.height=Math.min(c,e.maxHeight||this.maxHeight)}_fitRows(e,t,s,i){const{ctx:n,maxWidth:o,options:{labels:{padding:a}}}=this,r=this.legendHitBoxes=[],l=this.lineWidths=[0],c=i+a;let d=e;n.textAlign="left",n.textBaseline="middle";let u=-1,h=-c;return this.legendItems.forEach((e,p)=>{const m=s+t/2+n.measureText(e.text).width;(0===p||l[l.length-1]+m+2*a>o)&&(d+=c,l[l.length-(p>0?0:1)]=0,h+=c,u++),r[p]={left:0,top:h,row:u,width:m,height:i},l[l.length-1]+=m+a}),d}_fitCols(e,t,s,i){const{ctx:n,maxHeight:o,options:{labels:{padding:a}}}=this,r=this.legendHitBoxes=[],l=this.columnSizes=[],c=o-e;let d=a,u=0,h=0,p=0,m=0;return this.legendItems.forEach((e,o)=>{const{itemWidth:g,itemHeight:f}=function(e,t,s,i,n){const o=function(e,t,s,i){let n=e.text;return n&&"string"!=typeof n&&(n=n.reduce((e,t)=>e.length>t.length?e:t)),t+s.size/2+i.measureText(n).width}(i,e,t,s),a=function(e,t,s){let i=e;return"string"!=typeof t.text&&(i=ra(t,s)),i}(n,i,t.lineHeight);return{itemWidth:o,itemHeight:a}}(s,t,n,e,i);o>0&&h+f+2*a>c&&(d+=u+a,l.push({width:u,height:h}),p+=u+a,m++,u=h=0),r[o]={left:p,top:h,col:m,width:g,height:f},u=Math.max(u,g),h+=f+a}),d+=u,l.push({width:u,height:h}),d}adjustHitBoxes(){if(!this.options.display)return;const e=this._computeTitleHeight(),{legendHitBoxes:t,options:{align:s,labels:{padding:i},rtl:n}}=this,o=si(n,this.left,this.width);if(this.isHorizontal()){let n=0,a=Tt(s,this.left+i,this.right-this.lineWidths[n]);for(const r of t)n!==r.row&&(n=r.row,a=Tt(s,this.left+i,this.right-this.lineWidths[n])),r.top+=this.top+e+i,r.left=o.leftForLtr(o.x(a),r.width),a+=r.width+i}else{let n=0,a=Tt(s,this.top+e+i,this.bottom-this.columnSizes[n].height);for(const r of t)r.col!==n&&(n=r.col,a=Tt(s,this.top+e+i,this.bottom-this.columnSizes[n].height)),r.top=a,r.left+=this.left+i,r.left=o.leftForLtr(o.x(r.left),r.width),a+=r.height+i}}isHorizontal(){return"top"===this.options.position||"bottom"===this.options.position}draw(){if(this.options.display){const e=this.ctx;is(e,this),this._draw(),ns(e)}}_draw(){const{options:e,columnSizes:t,lineWidths:s,ctx:i}=this,{align:n,labels:o}=e,a=Jt.color,r=si(e.rtl,this.left,this.width),l=ys(o.font),{padding:c}=o,d=l.size,u=d/2;let h;this.drawTitle(),i.textAlign=r.textAlign("left"),i.textBaseline="middle",i.lineWidth=.5,i.font=l.string;const{boxWidth:p,boxHeight:m,itemHeight:g}=oa(o,d),f=this.isHorizontal(),b=this._computeTitleHeight();h=f?{x:Tt(n,this.left+c,this.right-s[0]),y:this.top+c+b,line:0}:{x:this.left+c,y:Tt(n,this.top+b+c,this.bottom-t[0].height),line:0},ii(this.ctx,e.textDirection);const v=g+c;this.legendItems.forEach((y,w)=>{i.strokeStyle=y.fontColor,i.fillStyle=y.fontColor;const _=i.measureText(y.text).width,x=r.textAlign(y.textAlign||(y.textAlign=o.textAlign)),S=p+u+_;let C=h.x,k=h.y;if(r.setWidth(this.width),f?w>0&&C+S+c>this.right&&(k=h.y+=v,h.line++,C=h.x=Tt(n,this.left+c,this.right-s[h.line])):w>0&&k+v>this.bottom&&(C=h.x=C+t[h.line].width+c,h.line++,k=h.y=Tt(n,this.top+b+c,this.bottom-t[h.line].height)),function(e,t,s){if(isNaN(p)||p<=0||isNaN(m)||m<0)return;i.save();const n=qe(s.lineWidth,1);if(i.fillStyle=qe(s.fillStyle,a),i.lineCap=qe(s.lineCap,"butt"),i.lineDashOffset=qe(s.lineDashOffset,0),i.lineJoin=qe(s.lineJoin,"miter"),i.lineWidth=n,i.strokeStyle=qe(s.strokeStyle,a),i.setLineDash(qe(s.lineDash,[])),o.usePointStyle){const a={radius:m*Math.SQRT2/2,pointStyle:s.pointStyle,rotation:s.rotation,borderWidth:n},l=r.xPlus(e,p/2);ts(i,a,l,t+u,o.pointStyleWidth&&p)}else{const o=t+Math.max((d-m)/2,0),a=r.leftForLtr(e,p),l=bs(s.borderRadius);i.beginPath(),Object.values(l).some(e=>0!==e)?ds(i,{x:a,y:o,w:p,h:m,radius:l}):i.rect(a,o,p,m),i.fill(),0!==n&&i.stroke()}i.restore()}(r.x(C),k,y),C=((e,t,s,i)=>e===(i?"left":"right")?s:"center"===e?(t+s)/2:t)(x,C+p+u,f?C+S:this.right,e.rtl),function(e,t,s){cs(i,s.text,e,t+g/2,l,{strikethrough:s.hidden,textAlign:r.textAlign(s.textAlign)})}(r.x(C),k,y),f)h.x+=S+c;else if("string"!=typeof y.text){const e=l.lineHeight;h.y+=ra(y,e)+c}else h.y+=v}),ni(this.ctx,e.textDirection)}drawTitle(){const e=this.options,t=e.title,s=ys(t.font),i=vs(t.padding);if(!t.display)return;const n=si(e.rtl,this.left,this.width),o=this.ctx,a=t.position,r=s.size/2,l=i.top+r;let c,d=this.left,u=this.width;if(this.isHorizontal())u=Math.max(...this.lineWidths),c=this.top+l,d=Tt(e.align,d,this.right-u);else{const t=this.columnSizes.reduce((e,t)=>Math.max(e,t.height),0);c=l+Tt(e.align,this.top,this.bottom-t-e.labels.padding-this._computeTitleHeight())}const h=Tt(a,d,d+u);o.textAlign=n.textAlign(Et(a)),o.textBaseline="middle",o.strokeStyle=t.color,o.fillStyle=t.color,o.font=s.string,cs(o,t.text,h,c,s)}_computeTitleHeight(){const e=this.options.title,t=ys(e.font),s=vs(e.padding);return e.display?t.lineHeight+s.height:0}_getLegendItemAt(e,t){let s,i,n;if(vt(e,this.left,this.right)&&vt(t,this.top,this.bottom))for(n=this.legendHitBoxes,s=0;s<n.length;++s)if(i=n[s],vt(e,i.left,i.left+i.width)&&vt(t,i.top,i.top+i.height))return this.legendItems[s];return null}handleEvent(e){const t=this.options;if(!function(e,t){return!("mousemove"!==e&&"mouseout"!==e||!t.onHover&&!t.onLeave)||!(!t.onClick||"click"!==e&&"mouseup"!==e)}(e.type,t))return;const s=this._getLegendItemAt(e.x,e.y);if("mousemove"===e.type||"mouseout"===e.type){const o=this._hoveredItem,a=(n=s,null!==(i=o)&&null!==n&&i.datasetIndex===n.datasetIndex&&i.index===n.index);o&&!a&&Pe(t.onLeave,[e,o,this],this),this._hoveredItem=s,s&&!a&&Pe(t.onHover,[e,s,this],this)}else s&&Pe(t.onClick,[e,s,this],this);var i,n}}function ra(e,t){return t*(e.text?e.text.length:0)}var la={id:"legend",_element:aa,start(e,t,s){const i=e.legend=new aa({ctx:e.ctx,options:s,chart:e});cn.configure(e,i,s),cn.addBox(e,i)},stop(e){cn.removeBox(e,e.legend),delete e.legend},beforeUpdate(e,t,s){const i=e.legend;cn.configure(e,i,s),i.options=s},afterUpdate(e){const t=e.legend;t.buildLabels(),t.adjustHitBoxes()},afterEvent(e,t){t.replay||e.legend.handleEvent(t.event)},defaults:{display:!0,position:"top",align:"center",fullSize:!0,reverse:!1,weight:1e3,onClick(e,t,s){const i=t.datasetIndex,n=s.chart;n.isDatasetVisible(i)?(n.hide(i),t.hidden=!0):(n.show(i),t.hidden=!1)},onHover:null,onLeave:null,labels:{color:e=>e.chart.options.color,boxWidth:40,padding:10,generateLabels(e){const t=e.data.datasets,{labels:{usePointStyle:s,pointStyle:i,textAlign:n,color:o,useBorderRadius:a,borderRadius:r}}=e.legend.options;return e._getSortedDatasetMetas().map(e=>{const l=e.controller.getStyle(s?0:void 0),c=vs(l.borderWidth);return{text:t[e.index].label,fillStyle:l.backgroundColor,fontColor:o,hidden:!e.visible,lineCap:l.borderCapStyle,lineDash:l.borderDash,lineDashOffset:l.borderDashOffset,lineJoin:l.borderJoinStyle,lineWidth:(c.width+c.height)/4,strokeStyle:l.borderColor,pointStyle:i||l.pointStyle,rotation:l.rotation,textAlign:n||l.textAlign,borderRadius:a&&(r||l.borderRadius),datasetIndex:e.index}},this)}},title:{color:e=>e.chart.options.color,display:!1,position:"center",text:""}},descriptors:{_scriptable:e=>!e.startsWith("on"),labels:{_scriptable:e=>!["generateLabels","filter","sort"].includes(e)}}};class ca extends Tn{constructor(e){super(),this.chart=e.chart,this.options=e.options,this.ctx=e.ctx,this._padding=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(e,t){const s=this.options;if(this.left=0,this.top=0,!s.display)return void(this.width=this.height=this.right=this.bottom=0);this.width=this.right=e,this.height=this.bottom=t;const i=Te(s.text)?s.text.length:1;this._padding=vs(s.padding);const n=i*ys(s.font).lineHeight+this._padding.height;this.isHorizontal()?this.height=n:this.width=n}isHorizontal(){const e=this.options.position;return"top"===e||"bottom"===e}_drawArgs(e){const{top:t,left:s,bottom:i,right:n,options:o}=this,a=o.align;let r,l,c,d=0;return this.isHorizontal()?(l=Tt(a,s,n),c=t+e,r=n-s):("left"===o.position?(l=s+e,c=Tt(a,i,t),d=-.5*Je):(l=n-e,c=Tt(a,t,i),d=.5*Je),r=i-t),{titleX:l,titleY:c,maxWidth:r,rotation:d}}draw(){const e=this.ctx,t=this.options;if(!t.display)return;const s=ys(t.font),i=s.lineHeight/2+this._padding.top,{titleX:n,titleY:o,maxWidth:a,rotation:r}=this._drawArgs(i);cs(e,t.text,0,0,s,{color:t.color,maxWidth:a,rotation:r,textAlign:Et(t.align),textBaseline:"middle",translation:[n,o]})}}var da={id:"title",_element:ca,start(e,t,s){!function(e,t){const s=new ca({ctx:e.ctx,options:t,chart:e});cn.configure(e,s,t),cn.addBox(e,s),e.titleBlock=s}(e,s)},stop(e){const t=e.titleBlock;cn.removeBox(e,t),delete e.titleBlock},beforeUpdate(e,t,s){const i=e.titleBlock;cn.configure(e,i,s),i.options=s},defaults:{align:"center",display:!1,font:{weight:"bold"},fullSize:!0,padding:10,position:"top",text:"",weight:2e3},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}};const ua=new WeakMap;var ha={id:"subtitle",start(e,t,s){const i=new ca({ctx:e.ctx,options:s,chart:e});cn.configure(e,i,s),cn.addBox(e,i),ua.set(e,i)},stop(e){cn.removeBox(e,ua.get(e)),ua.delete(e)},beforeUpdate(e,t,s){const i=ua.get(e);cn.configure(e,i,s),i.options=s},defaults:{align:"center",display:!1,font:{weight:"normal"},fullSize:!0,padding:0,position:"top",text:"",weight:1500},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}};const pa={average(e){if(!e.length)return!1;let t,s,i=new Set,n=0,o=0;for(t=0,s=e.length;t<s;++t){const s=e[t].element;if(s&&s.hasValue()){const e=s.tooltipPosition();i.add(e.x),n+=e.y,++o}}return 0!==o&&0!==i.size&&{x:[...i].reduce((e,t)=>e+t)/i.size,y:n/o}},nearest(e,t){if(!e.length)return!1;let s,i,n,o=t.x,a=t.y,r=Number.POSITIVE_INFINITY;for(s=0,i=e.length;s<i;++s){const i=e[s].element;if(i&&i.hasValue()){const e=pt(t,i.getCenterPoint());e<r&&(r=e,n=i)}}if(n){const e=n.tooltipPosition();o=e.x,a=e.y}return{x:o,y:a}}};function ma(e,t){return t&&(Te(t)?Array.prototype.push.apply(e,t):e.push(t)),e}function ga(e){return("string"==typeof e||e instanceof String)&&e.indexOf("\n")>-1?e.split("\n"):e}function fa(e,t){const{element:s,datasetIndex:i,index:n}=t,o=e.getDatasetMeta(i).controller,{label:a,value:r}=o.getLabelAndValue(n);return{chart:e,label:a,parsed:o.getParsed(n),raw:e.data.datasets[i].data[n],formattedValue:r,dataset:o.getDataset(),dataIndex:n,datasetIndex:i,element:s}}function ba(e,t){const s=e.chart.ctx,{body:i,footer:n,title:o}=e,{boxWidth:a,boxHeight:r}=t,l=ys(t.bodyFont),c=ys(t.titleFont),d=ys(t.footerFont),u=o.length,h=n.length,p=i.length,m=vs(t.padding);let g=m.height,f=0,b=i.reduce((e,t)=>e+t.before.length+t.lines.length+t.after.length,0);b+=e.beforeBody.length+e.afterBody.length,u&&(g+=u*c.lineHeight+(u-1)*t.titleSpacing+t.titleMarginBottom),b&&(g+=p*(t.displayColors?Math.max(r,l.lineHeight):l.lineHeight)+(b-p)*l.lineHeight+(b-1)*t.bodySpacing),h&&(g+=t.footerMarginTop+h*d.lineHeight+(h-1)*t.footerSpacing);let v=0;const y=function(e){f=Math.max(f,s.measureText(e).width+v)};return s.save(),s.font=c.string,Me(e.title,y),s.font=l.string,Me(e.beforeBody.concat(e.afterBody),y),v=t.displayColors?a+2+t.boxPadding:0,Me(i,e=>{Me(e.before,y),Me(e.lines,y),Me(e.after,y)}),v=0,s.font=d.string,Me(e.footer,y),s.restore(),f+=m.width,{width:f,height:g}}function va(e,t,s,i){const{x:n,width:o}=s,{width:a,chartArea:{left:r,right:l}}=e;let c="center";return"center"===i?c=n<=(r+l)/2?"left":"right":n<=o/2?c="left":n>=a-o/2&&(c="right"),function(e,t,s,i){const{x:n,width:o}=i,a=s.caretSize+s.caretPadding;return"left"===e&&n+o+a>t.width||"right"===e&&n-o-a<0||void 0}(c,e,t,s)&&(c="center"),c}function ya(e,t,s){const i=s.yAlign||t.yAlign||function(e,t){const{y:s,height:i}=t;return s<i/2?"top":s>e.height-i/2?"bottom":"center"}(e,s);return{xAlign:s.xAlign||t.xAlign||va(e,t,s,i),yAlign:i}}function wa(e,t,s,i){const{caretSize:n,caretPadding:o,cornerRadius:a}=e,{xAlign:r,yAlign:l}=s,c=n+o,{topLeft:d,topRight:u,bottomLeft:h,bottomRight:p}=bs(a);let m=function(e,t){let{x:s,width:i}=e;return"right"===t?s-=i:"center"===t&&(s-=i/2),s}(t,r);const g=function(e,t,s){let{y:i,height:n}=e;return"top"===t?i+=s:i-="bottom"===t?n+s:n/2,i}(t,l,c);return"center"===l?"left"===r?m+=c:"right"===r&&(m-=c):"left"===r?m-=Math.max(d,h)+n:"right"===r&&(m+=Math.max(u,p)+n),{x:bt(m,0,i.width-t.width),y:bt(g,0,i.height-t.height)}}function _a(e,t,s){const i=vs(s.padding);return"center"===t?e.x+e.width/2:"right"===t?e.x+e.width-i.right:e.x+i.left}function xa(e){return ma([],ga(e))}function Sa(e,t){const s=t&&t.dataset&&t.dataset.tooltip&&t.dataset.tooltip.callbacks;return s?e.override(s):e}const Ca={beforeTitle:ke,title(e){if(e.length>0){const t=e[0],s=t.chart.data.labels,i=s?s.length:0;if(this&&this.options&&"dataset"===this.options.mode)return t.dataset.label||"";if(t.label)return t.label;if(i>0&&t.dataIndex<i)return s[t.dataIndex]}return""},afterTitle:ke,beforeBody:ke,beforeLabel:ke,label(e){if(this&&this.options&&"dataset"===this.options.mode)return e.label+": "+e.formattedValue||e.formattedValue;let t=e.dataset.label||"";t&&(t+=": ");const s=e.formattedValue;return Ee(s)||(t+=s),t},labelColor(e){const t=e.chart.getDatasetMeta(e.datasetIndex).controller.getStyle(e.dataIndex);return{borderColor:t.borderColor,backgroundColor:t.backgroundColor,borderWidth:t.borderWidth,borderDash:t.borderDash,borderDashOffset:t.borderDashOffset,borderRadius:0}},labelTextColor(){return this.options.bodyColor},labelPointStyle(e){const t=e.chart.getDatasetMeta(e.datasetIndex).controller.getStyle(e.dataIndex);return{pointStyle:t.pointStyle,rotation:t.rotation}},afterLabel:ke,afterBody:ke,beforeFooter:ke,footer:ke,afterFooter:ke};function ka(e,t,s,i){const n=e[t].call(s,i);return void 0===n?Ca[t].call(s,i):n}class Aa extends Tn{static positioners=pa;constructor(e){super(),this.opacity=0,this._active=[],this._eventPosition=void 0,this._size=void 0,this._cachedAnimations=void 0,this._tooltipItems=[],this.$animations=void 0,this.$context=void 0,this.chart=e.chart,this.options=e.options,this.dataPoints=void 0,this.title=void 0,this.beforeBody=void 0,this.body=void 0,this.afterBody=void 0,this.footer=void 0,this.xAlign=void 0,this.yAlign=void 0,this.x=void 0,this.y=void 0,this.height=void 0,this.width=void 0,this.caretX=void 0,this.caretY=void 0,this.labelColors=void 0,this.labelPointStyles=void 0,this.labelTextColors=void 0}initialize(e){this.options=e,this._cachedAnimations=void 0,this.$context=void 0}_resolveAnimations(){const e=this._cachedAnimations;if(e)return e;const t=this.chart,s=this.options.setContext(this.getContext()),i=s.enabled&&t.options.animation&&s.animations,n=new vi(this.chart,i);return i._cacheable&&(this._cachedAnimations=Object.freeze(n)),n}getContext(){return this.$context||(this.$context=_s(this.chart.getContext(),{tooltip:this,tooltipItems:this._tooltipItems,type:"tooltip"}))}getTitle(e,t){const{callbacks:s}=t,i=ka(s,"beforeTitle",this,e),n=ka(s,"title",this,e),o=ka(s,"afterTitle",this,e);let a=[];return a=ma(a,ga(i)),a=ma(a,ga(n)),a=ma(a,ga(o)),a}getBeforeBody(e,t){return xa(ka(t.callbacks,"beforeBody",this,e))}getBody(e,t){const{callbacks:s}=t,i=[];return Me(e,e=>{const t={before:[],lines:[],after:[]},n=Sa(s,e);ma(t.before,ga(ka(n,"beforeLabel",this,e))),ma(t.lines,ka(n,"label",this,e)),ma(t.after,ga(ka(n,"afterLabel",this,e))),i.push(t)}),i}getAfterBody(e,t){return xa(ka(t.callbacks,"afterBody",this,e))}getFooter(e,t){const{callbacks:s}=t,i=ka(s,"beforeFooter",this,e),n=ka(s,"footer",this,e),o=ka(s,"afterFooter",this,e);let a=[];return a=ma(a,ga(i)),a=ma(a,ga(n)),a=ma(a,ga(o)),a}_createItems(e){const t=this._active,s=this.chart.data,i=[],n=[],o=[];let a,r,l=[];for(a=0,r=t.length;a<r;++a)l.push(fa(this.chart,t[a]));return e.filter&&(l=l.filter((t,i,n)=>e.filter(t,i,n,s))),e.itemSort&&(l=l.sort((t,i)=>e.itemSort(t,i,s))),Me(l,t=>{const s=Sa(e.callbacks,t);i.push(ka(s,"labelColor",this,t)),n.push(ka(s,"labelPointStyle",this,t)),o.push(ka(s,"labelTextColor",this,t))}),this.labelColors=i,this.labelPointStyles=n,this.labelTextColors=o,this.dataPoints=l,l}update(e,t){const s=this.options.setContext(this.getContext()),i=this._active;let n,o=[];if(i.length){const e=pa[s.position].call(this,i,this._eventPosition);o=this._createItems(s),this.title=this.getTitle(o,s),this.beforeBody=this.getBeforeBody(o,s),this.body=this.getBody(o,s),this.afterBody=this.getAfterBody(o,s),this.footer=this.getFooter(o,s);const t=this._size=ba(this,s),a=Object.assign({},e,t),r=ya(this.chart,s,a),l=wa(s,a,r,this.chart);this.xAlign=r.xAlign,this.yAlign=r.yAlign,n={opacity:1,x:l.x,y:l.y,width:t.width,height:t.height,caretX:e.x,caretY:e.y}}else 0!==this.opacity&&(n={opacity:0});this._tooltipItems=o,this.$context=void 0,n&&this._resolveAnimations().update(this,n),e&&s.external&&s.external.call(this,{chart:this.chart,tooltip:this,replay:t})}drawCaret(e,t,s,i){const n=this.getCaretPosition(e,s,i);t.lineTo(n.x1,n.y1),t.lineTo(n.x2,n.y2),t.lineTo(n.x3,n.y3)}getCaretPosition(e,t,s){const{xAlign:i,yAlign:n}=this,{caretSize:o,cornerRadius:a}=s,{topLeft:r,topRight:l,bottomLeft:c,bottomRight:d}=bs(a),{x:u,y:h}=e,{width:p,height:m}=t;let g,f,b,v,y,w;return"center"===n?(y=h+m/2,"left"===i?(g=u,f=g-o,v=y+o,w=y-o):(g=u+p,f=g+o,v=y-o,w=y+o),b=g):(f="left"===i?u+Math.max(r,c)+o:"right"===i?u+p-Math.max(l,d)-o:this.caretX,"top"===n?(v=h,y=v-o,g=f-o,b=f+o):(v=h+m,y=v+o,g=f+o,b=f-o),w=v),{x1:g,x2:f,x3:b,y1:v,y2:y,y3:w}}drawTitle(e,t,s){const i=this.title,n=i.length;let o,a,r;if(n){const l=si(s.rtl,this.x,this.width);for(e.x=_a(this,s.titleAlign,s),t.textAlign=l.textAlign(s.titleAlign),t.textBaseline="middle",o=ys(s.titleFont),a=s.titleSpacing,t.fillStyle=s.titleColor,t.font=o.string,r=0;r<n;++r)t.fillText(i[r],l.x(e.x),e.y+o.lineHeight/2),e.y+=o.lineHeight+a,r+1===n&&(e.y+=s.titleMarginBottom-a)}}_drawColorBox(e,t,s,i,n){const o=this.labelColors[s],a=this.labelPointStyles[s],{boxHeight:r,boxWidth:l}=n,c=ys(n.bodyFont),d=_a(this,"left",n),u=i.x(d),h=r<c.lineHeight?(c.lineHeight-r)/2:0,p=t.y+h;if(n.usePointStyle){const t={radius:Math.min(l,r)/2,pointStyle:a.pointStyle,rotation:a.rotation,borderWidth:1},s=i.leftForLtr(u,l)+l/2,c=p+r/2;e.strokeStyle=n.multiKeyBackground,e.fillStyle=n.multiKeyBackground,es(e,t,s,c),e.strokeStyle=o.borderColor,e.fillStyle=o.backgroundColor,es(e,t,s,c)}else{e.lineWidth=Le(o.borderWidth)?Math.max(...Object.values(o.borderWidth)):o.borderWidth||1,e.strokeStyle=o.borderColor,e.setLineDash(o.borderDash||[]),e.lineDashOffset=o.borderDashOffset||0;const t=i.leftForLtr(u,l),s=i.leftForLtr(i.xPlus(u,1),l-2),a=bs(o.borderRadius);Object.values(a).some(e=>0!==e)?(e.beginPath(),e.fillStyle=n.multiKeyBackground,ds(e,{x:t,y:p,w:l,h:r,radius:a}),e.fill(),e.stroke(),e.fillStyle=o.backgroundColor,e.beginPath(),ds(e,{x:s,y:p+1,w:l-2,h:r-2,radius:a}),e.fill()):(e.fillStyle=n.multiKeyBackground,e.fillRect(t,p,l,r),e.strokeRect(t,p,l,r),e.fillStyle=o.backgroundColor,e.fillRect(s,p+1,l-2,r-2))}e.fillStyle=this.labelTextColors[s]}drawBody(e,t,s){const{body:i}=this,{bodySpacing:n,bodyAlign:o,displayColors:a,boxHeight:r,boxWidth:l,boxPadding:c}=s,d=ys(s.bodyFont);let u=d.lineHeight,h=0;const p=si(s.rtl,this.x,this.width),m=function(s){t.fillText(s,p.x(e.x+h),e.y+u/2),e.y+=u+n},g=p.textAlign(o);let f,b,v,y,w,_,x;for(t.textAlign=o,t.textBaseline="middle",t.font=d.string,e.x=_a(this,g,s),t.fillStyle=s.bodyColor,Me(this.beforeBody,m),h=a&&"right"!==g?"center"===o?l/2+c:l+2+c:0,y=0,_=i.length;y<_;++y){for(f=i[y],b=this.labelTextColors[y],t.fillStyle=b,Me(f.before,m),v=f.lines,a&&v.length&&(this._drawColorBox(t,e,y,p,s),u=Math.max(d.lineHeight,r)),w=0,x=v.length;w<x;++w)m(v[w]),u=d.lineHeight;Me(f.after,m)}h=0,u=d.lineHeight,Me(this.afterBody,m),e.y-=n}drawFooter(e,t,s){const i=this.footer,n=i.length;let o,a;if(n){const r=si(s.rtl,this.x,this.width);for(e.x=_a(this,s.footerAlign,s),e.y+=s.footerMarginTop,t.textAlign=r.textAlign(s.footerAlign),t.textBaseline="middle",o=ys(s.footerFont),t.fillStyle=s.footerColor,t.font=o.string,a=0;a<n;++a)t.fillText(i[a],r.x(e.x),e.y+o.lineHeight/2),e.y+=o.lineHeight+s.footerSpacing}}drawBackground(e,t,s,i){const{xAlign:n,yAlign:o}=this,{x:a,y:r}=e,{width:l,height:c}=s,{topLeft:d,topRight:u,bottomLeft:h,bottomRight:p}=bs(i.cornerRadius);t.fillStyle=i.backgroundColor,t.strokeStyle=i.borderColor,t.lineWidth=i.borderWidth,t.beginPath(),t.moveTo(a+d,r),"top"===o&&this.drawCaret(e,t,s,i),t.lineTo(a+l-u,r),t.quadraticCurveTo(a+l,r,a+l,r+u),"center"===o&&"right"===n&&this.drawCaret(e,t,s,i),t.lineTo(a+l,r+c-p),t.quadraticCurveTo(a+l,r+c,a+l-p,r+c),"bottom"===o&&this.drawCaret(e,t,s,i),t.lineTo(a+h,r+c),t.quadraticCurveTo(a,r+c,a,r+c-h),"center"===o&&"left"===n&&this.drawCaret(e,t,s,i),t.lineTo(a,r+d),t.quadraticCurveTo(a,r,a+d,r),t.closePath(),t.fill(),i.borderWidth>0&&t.stroke()}_updateAnimationTarget(e){const t=this.chart,s=this.$animations,i=s&&s.x,n=s&&s.y;if(i||n){const s=pa[e.position].call(this,this._active,this._eventPosition);if(!s)return;const o=this._size=ba(this,e),a=Object.assign({},s,this._size),r=ya(t,e,a),l=wa(e,a,r,t);i._to===l.x&&n._to===l.y||(this.xAlign=r.xAlign,this.yAlign=r.yAlign,this.width=o.width,this.height=o.height,this.caretX=s.x,this.caretY=s.y,this._resolveAnimations().update(this,l))}}_willRender(){return!!this.opacity}draw(e){const t=this.options.setContext(this.getContext());let s=this.opacity;if(!s)return;this._updateAnimationTarget(t);const i={width:this.width,height:this.height},n={x:this.x,y:this.y};s=Math.abs(s)<.001?0:s;const o=vs(t.padding),a=this.title.length||this.beforeBody.length||this.body.length||this.afterBody.length||this.footer.length;t.enabled&&a&&(e.save(),e.globalAlpha=s,this.drawBackground(n,e,i,t),ii(e,t.textDirection),n.y+=o.top,this.drawTitle(n,e,t),this.drawBody(n,e,t),this.drawFooter(n,e,t),ni(e,t.textDirection),e.restore())}getActiveElements(){return this._active||[]}setActiveElements(e,t){const s=this._active,i=e.map(({datasetIndex:e,index:t})=>{const s=this.chart.getDatasetMeta(e);if(!s)throw new Error("Cannot find a dataset at index "+e);return{datasetIndex:e,element:s.data[t],index:t}}),n=!Oe(s,i),o=this._positionChanged(i,t);(n||o)&&(this._active=i,this._eventPosition=t,this._ignoreReplayEvents=!0,this.update(!0))}handleEvent(e,t,s=!0){if(t&&this._ignoreReplayEvents)return!1;this._ignoreReplayEvents=!1;const i=this.options,n=this._active||[],o=this._getActiveElements(e,n,t,s),a=this._positionChanged(o,e),r=t||!Oe(o,n)||a;return r&&(this._active=o,(i.enabled||i.external)&&(this._eventPosition={x:e.x,y:e.y},this.update(!0,t))),r}_getActiveElements(e,t,s,i){const n=this.options;if("mouseout"===e.type)return[];if(!i)return t.filter(e=>this.chart.data.datasets[e.datasetIndex]&&void 0!==this.chart.getDatasetMeta(e.datasetIndex).controller.getParsed(e.index));const o=this.chart.getElementsAtEventForMode(e,n.mode,n,s);return n.reverse&&o.reverse(),o}_positionChanged(e,t){const{caretX:s,caretY:i,options:n}=this,o=pa[n.position].call(this,e,t);return!1!==o&&(s!==o.x||i!==o.y)}}var Ea={id:"tooltip",_element:Aa,positioners:pa,afterInit(e,t,s){s&&(e.tooltip=new Aa({chart:e,options:s}))},beforeUpdate(e,t,s){e.tooltip&&e.tooltip.initialize(s)},reset(e,t,s){e.tooltip&&e.tooltip.initialize(s)},afterDraw(e){const t=e.tooltip;if(t&&t._willRender()){const s={tooltip:t};if(!1===e.notifyPlugins("beforeTooltipDraw",{...s,cancelable:!0}))return;t.draw(e.ctx),e.notifyPlugins("afterTooltipDraw",s)}},afterEvent(e,t){if(e.tooltip){const s=t.replay;e.tooltip.handleEvent(t.event,s,t.inChartArea)&&(t.changed=!0)}},defaults:{enabled:!0,external:null,position:"average",backgroundColor:"rgba(0,0,0,0.8)",titleColor:"#fff",titleFont:{weight:"bold"},titleSpacing:2,titleMarginBottom:6,titleAlign:"left",bodyColor:"#fff",bodySpacing:2,bodyFont:{},bodyAlign:"left",footerColor:"#fff",footerSpacing:2,footerMarginTop:6,footerFont:{weight:"bold"},footerAlign:"left",padding:6,caretPadding:2,caretSize:5,cornerRadius:6,boxHeight:(e,t)=>t.bodyFont.size,boxWidth:(e,t)=>t.bodyFont.size,multiKeyBackground:"#fff",displayColors:!0,boxPadding:0,borderColor:"rgba(0,0,0,0)",borderWidth:0,animation:{duration:400,easing:"easeOutQuart"},animations:{numbers:{type:"number",properties:["x","y","width","height","caretX","caretY"]},opacity:{easing:"linear",duration:200}},callbacks:Ca},defaultRoutes:{bodyFont:"font",footerFont:"font",titleFont:"font"},descriptors:{_scriptable:e=>"filter"!==e&&"itemSort"!==e&&"external"!==e,_indexable:!1,callbacks:{_scriptable:!1,_indexable:!1},animation:{_fallback:!1},animations:{_fallback:"animation"}},additionalOptionScopes:["interaction"]},Ta=Object.freeze({__proto__:null,Colors:$o,Decimation:Qo,Filler:na,Legend:la,SubTitle:ha,Title:da,Tooltip:Ea});function La(e){const t=this.getLabels();return e>=0&&e<t.length?t[e]:e}function Ia(e,t,{horizontal:s,minRotation:i}){const n=ct(i),o=(s?Math.sin(n):Math.cos(n))||.001,a=.75*t*(""+e).length;return Math.min(t/o,a)}class Da extends zn{constructor(e){super(e),this.start=void 0,this.end=void 0,this._startValue=void 0,this._endValue=void 0,this._valueRange=0}parse(e,t){return Ee(e)||("number"==typeof e||e instanceof Number)&&!isFinite(+e)?null:+e}handleTickRangeOptions(){const{beginAtZero:e}=this.options,{minDefined:t,maxDefined:s}=this.getUserBounds();let{min:i,max:n}=this;const o=e=>i=t?i:e,a=e=>n=s?n:e;if(e){const e=nt(i),t=nt(n);e<0&&t<0?a(0):e>0&&t>0&&o(0)}if(i===n){let t=0===n?1:Math.abs(.05*n);a(n+t),e||o(i-t)}this.min=i,this.max=n}getTickLimit(){const e=this.options.ticks;let t,{maxTicksLimit:s,stepSize:i}=e;return i?(t=Math.ceil(this.max/i)-Math.floor(this.min/i)+1,t>1e3&&(console.warn(`scales.${this.id}.ticks.stepSize: ${i} would result generating up to ${t} ticks. Limiting to 1000.`),t=1e3)):(t=this.computeTickLimit(),s=s||11),s&&(t=Math.min(s,t)),t}computeTickLimit(){return Number.POSITIVE_INFINITY}buildTicks(){const e=this.options,t=e.ticks;let s=this.getTickLimit();s=Math.max(2,s);const i=function(e,t){const s=[],{bounds:i,step:n,min:o,max:a,precision:r,count:l,maxTicks:c,maxDigits:d,includeBounds:u}=e,h=n||1,p=c-1,{min:m,max:g}=t,f=!Ee(o),b=!Ee(a),v=!Ee(l),y=(g-m)/(d+1);let w,_,x,S,C=at((g-m)/p/h)*h;if(C<1e-14&&!f&&!b)return[{value:m},{value:g}];S=Math.ceil(g/C)-Math.floor(m/C),S>p&&(C=at(S*C/p/h)*h),Ee(r)||(w=Math.pow(10,r),C=Math.ceil(C*w)/w),"ticks"===i?(_=Math.floor(m/C)*C,x=Math.ceil(g/C)*C):(_=m,x=g),f&&b&&n&&function(e,t){const s=Math.round(e);return s-t<=e&&s+t>=e}((a-o)/n,C/1e3)?(S=Math.round(Math.min((a-o)/C,c)),C=(a-o)/S,_=o,x=a):v?(_=f?o:_,x=b?a:x,S=l-1,C=(x-_)/S):(S=(x-_)/C,S=ot(S,Math.round(S),C/1e3)?Math.round(S):Math.ceil(S));const k=Math.max(ut(C),ut(_));w=Math.pow(10,Ee(r)?k:r),_=Math.round(_*w)/w,x=Math.round(x*w)/w;let A=0;for(f&&(u&&_!==o?(s.push({value:o}),_<o&&A++,ot(Math.round((_+A*C)*w)/w,o,Ia(o,y,e))&&A++):_<o&&A++);A<S;++A){const e=Math.round((_+A*C)*w)/w;if(b&&e>a)break;s.push({value:e})}return b&&u&&x!==a?s.length&&ot(s[s.length-1].value,a,Ia(a,y,e))?s[s.length-1].value=a:s.push({value:a}):b&&x!==a||s.push({value:x}),s}({maxTicks:s,bounds:e.bounds,min:e.min,max:e.max,precision:t.precision,step:t.stepSize,count:t.count,maxDigits:this._maxDigits(),horizontal:this.isHorizontal(),minRotation:t.minRotation||0,includeBounds:!1!==t.includeBounds},this._range||this);return"ticks"===e.bounds&<(i,this,"value"),e.reverse?(i.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),i}configure(){const e=this.ticks;let t=this.min,s=this.max;if(super.configure(),this.options.offset&&e.length){const i=(s-t)/Math.max(e.length-1,1)/2;t-=i,s+=i}this._startValue=t,this._endValue=s,this._valueRange=s-t}getLabelForValue(e){return Qt(e,this.chart.options.locale,this.options.ticks.format)}}class qa extends Da{static id="linear";static defaults={ticks:{callback:Rt.formatters.numeric}};determineDataLimits(){const{min:e,max:t}=this.getMinMax(!0);this.min=Ie(e)?e:0,this.max=Ie(t)?t:1,this.handleTickRangeOptions()}computeTickLimit(){const e=this.isHorizontal(),t=e?this.width:this.height,s=ct(this.options.ticks.minRotation),i=(e?Math.sin(s):Math.cos(s))||.001,n=this._resolveTickFontOptions(0);return Math.ceil(t/Math.min(40,n.lineHeight/i))}getPixelForValue(e){return null===e?NaN:this.getPixelForDecimal((e-this._startValue)/this._valueRange)}getValueForPixel(e){return this._startValue+this.getDecimalForPixel(e)*this._valueRange}}const Ba=e=>Math.floor(it(e)),Pa=(e,t)=>Math.pow(10,Ba(e)+t);function Ma(e){return 1===e/Math.pow(10,Ba(e))}function Oa(e,t,s){const i=Math.pow(10,s),n=Math.floor(e/i);return Math.ceil(t/i)-n}class za extends zn{static id="logarithmic";static defaults={ticks:{callback:Rt.formatters.logarithmic,major:{enabled:!0}}};constructor(e){super(e),this.start=void 0,this.end=void 0,this._startValue=void 0,this._valueRange=0}parse(e,t){const s=Da.prototype.parse.apply(this,[e,t]);if(0!==s)return Ie(s)&&s>0?s:null;this._zero=!0}determineDataLimits(){const{min:e,max:t}=this.getMinMax(!0);this.min=Ie(e)?Math.max(0,e):null,this.max=Ie(t)?Math.max(0,t):null,this.options.beginAtZero&&(this._zero=!0),this._zero&&this.min!==this._suggestedMin&&!Ie(this._userMin)&&(this.min=e===Pa(this.min,0)?Pa(this.min,-1):Pa(this.min,0)),this.handleTickRangeOptions()}handleTickRangeOptions(){const{minDefined:e,maxDefined:t}=this.getUserBounds();let s=this.min,i=this.max;const n=t=>s=e?s:t,o=e=>i=t?i:e;s===i&&(s<=0?(n(1),o(10)):(n(Pa(s,-1)),o(Pa(i,1)))),s<=0&&n(Pa(i,-1)),i<=0&&o(Pa(s,1)),this.min=s,this.max=i}buildTicks(){const e=this.options,t=function(e,{min:t,max:s}){t=De(e.min,t);const i=[],n=Ba(t);let o=function(e,t){let s=Ba(t-e);for(;Oa(e,t,s)>10;)s++;for(;Oa(e,t,s)<10;)s--;return Math.min(s,Ba(e))}(t,s),a=o<0?Math.pow(10,Math.abs(o)):1;const r=Math.pow(10,o),l=n>o?Math.pow(10,n):0,c=Math.round((t-l)*a)/a,d=Math.floor((t-l)/r/10)*r*10;let u=Math.floor((c-d)/Math.pow(10,o)),h=De(e.min,Math.round((l+d+u*Math.pow(10,o))*a)/a);for(;h<s;)i.push({value:h,major:Ma(h),significand:u}),u>=10?u=u<15?15:20:u++,u>=20&&(o++,u=2,a=o>=0?1:a),h=Math.round((l+d+u*Math.pow(10,o))*a)/a;const p=De(e.max,h);return i.push({value:p,major:Ma(p),significand:u}),i}({min:this._userMin,max:this._userMax},this);return"ticks"===e.bounds&<(t,this,"value"),e.reverse?(t.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),t}getLabelForValue(e){return void 0===e?"0":Qt(e,this.chart.options.locale,this.options.ticks.format)}configure(){const e=this.min;super.configure(),this._startValue=it(e),this._valueRange=it(this.max)-it(e)}getPixelForValue(e){return void 0!==e&&0!==e||(e=this.min),null===e||isNaN(e)?NaN:this.getPixelForDecimal(e===this.min?0:(it(e)-this._startValue)/this._valueRange)}getValueForPixel(e){const t=this.getDecimalForPixel(e);return Math.pow(10,this._startValue+t*this._valueRange)}}function $a(e){const t=e.ticks;if(t.display&&e.display){const e=vs(t.backdropPadding);return qe(t.font&&t.font.size,Jt.font.size)+e.height}return 0}function Fa(e,t,s){return s=Te(s)?s:[s],{w:Yt(e,t.string,s),h:s.length*t.lineHeight}}function Ha(e,t,s,i,n){return e===i||e===n?{start:t-s/2,end:t+s/2}:e<i||e>n?{start:t-s,end:t}:{start:t,end:t+s}}function Qa(e,t,s,i,n){const o=Math.abs(Math.sin(s)),a=Math.abs(Math.cos(s));let r=0,l=0;i.start<t.l?(r=(t.l-i.start)/o,e.l=Math.min(e.l,t.l-r)):i.end>t.r&&(r=(i.end-t.r)/o,e.r=Math.max(e.r,t.r+r)),n.start<t.t?(l=(t.t-n.start)/a,e.t=Math.min(e.t,t.t-l)):n.end>t.b&&(l=(n.end-t.b)/a,e.b=Math.max(e.b,t.b+l))}function Na(e,t,s){const i=e.drawingArea,{extra:n,additionalAngle:o,padding:a,size:r}=s,l=e.getPointPosition(t,i+n+a,o),c=Math.round(dt(gt(l.angle+et))),d=function(e,t,s){return 90===s||270===s?e-=t/2:(s>270||s<90)&&(e-=t),e}(l.y,r.h,c),u=function(e){return 0===e||180===e?"center":e<180?"left":"right"}(c),h=(p=l.x,m=r.w,"right"===(g=u)?p-=m:"center"===g&&(p-=m/2),p);var p,m,g;return{visible:!0,x:l.x,y:d,textAlign:u,left:h,top:d,right:h+r.w,bottom:d+r.h}}function Ra(e,t){if(!t)return!0;const{left:s,top:i,right:n,bottom:o}=e;return!(ss({x:s,y:i},t)||ss({x:s,y:o},t)||ss({x:n,y:i},t)||ss({x:n,y:o},t))}function Wa(e,t,s){const{left:i,top:n,right:o,bottom:a}=s,{backdropColor:r}=t;if(!Ee(r)){const s=bs(t.borderRadius),l=vs(t.backdropPadding);e.fillStyle=r;const c=i-l.left,d=n-l.top,u=o-i+l.width,h=a-n+l.height;Object.values(s).some(e=>0!==e)?(e.beginPath(),ds(e,{x:c,y:d,w:u,h,radius:s}),e.fill()):e.fillRect(c,d,u,h)}}function ja(e,t,s,i){const{ctx:n}=e;if(s)n.arc(e.xCenter,e.yCenter,t,0,Ge);else{let s=e.getPointPosition(0,t);n.moveTo(s.x,s.y);for(let o=1;o<i;o++)s=e.getPointPosition(o,t),n.lineTo(s.x,s.y)}}class Va extends Da{static id="radialLinear";static defaults={display:!0,animate:!0,position:"chartArea",angleLines:{display:!0,lineWidth:1,borderDash:[],borderDashOffset:0},grid:{circular:!1},startAngle:0,ticks:{showLabelBackdrop:!0,callback:Rt.formatters.numeric},pointLabels:{backdropColor:void 0,backdropPadding:2,display:!0,font:{size:10},callback:e=>e,padding:5,centerPointLabels:!1}};static defaultRoutes={"angleLines.color":"borderColor","pointLabels.color":"color","ticks.color":"color"};static descriptors={angleLines:{_fallback:"grid"}};constructor(e){super(e),this.xCenter=void 0,this.yCenter=void 0,this.drawingArea=void 0,this._pointLabels=[],this._pointLabelItems=[]}setDimensions(){const e=this._padding=vs($a(this.options)/2),t=this.width=this.maxWidth-e.width,s=this.height=this.maxHeight-e.height;this.xCenter=Math.floor(this.left+t/2+e.left),this.yCenter=Math.floor(this.top+s/2+e.top),this.drawingArea=Math.floor(Math.min(t,s)/2)}determineDataLimits(){const{min:e,max:t}=this.getMinMax(!1);this.min=Ie(e)&&!isNaN(e)?e:0,this.max=Ie(t)&&!isNaN(t)?t:0,this.handleTickRangeOptions()}computeTickLimit(){return Math.ceil(this.drawingArea/$a(this.options))}generateTickLabels(e){Da.prototype.generateTickLabels.call(this,e),this._pointLabels=this.getLabels().map((e,t)=>{const s=Pe(this.options.pointLabels.callback,[e,t],this);return s||0===s?s:""}).filter((e,t)=>this.chart.getDataVisibility(t))}fit(){const e=this.options;e.display&&e.pointLabels.display?function(e){const t={l:e.left+e._padding.left,r:e.right-e._padding.right,t:e.top+e._padding.top,b:e.bottom-e._padding.bottom},s=Object.assign({},t),i=[],n=[],o=e._pointLabels.length,a=e.options.pointLabels,r=a.centerPointLabels?Je/o:0;for(let l=0;l<o;l++){const o=a.setContext(e.getPointLabelContext(l));n[l]=o.padding;const c=e.getPointPosition(l,e.drawingArea+n[l],r),d=ys(o.font),u=Fa(e.ctx,d,e._pointLabels[l]);i[l]=u;const h=gt(e.getIndexAngle(l)+r),p=Math.round(dt(h));Qa(s,t,h,Ha(p,c.x,u.w,0,180),Ha(p,c.y,u.h,90,270))}e.setCenterPoint(t.l-s.l,s.r-t.r,t.t-s.t,s.b-t.b),e._pointLabelItems=function(e,t,s){const i=[],n=e._pointLabels.length,o=e.options,{centerPointLabels:a,display:r}=o.pointLabels,l={extra:$a(o)/2,additionalAngle:a?Je/n:0};let c;for(let o=0;o<n;o++){l.padding=s[o],l.size=t[o];const n=Na(e,o,l);i.push(n),"auto"===r&&(n.visible=Ra(n,c),n.visible&&(c=n))}return i}(e,i,n)}(this):this.setCenterPoint(0,0,0,0)}setCenterPoint(e,t,s,i){this.xCenter+=Math.floor((e-t)/2),this.yCenter+=Math.floor((s-i)/2),this.drawingArea-=Math.min(this.drawingArea/2,Math.max(e,t,s,i))}getIndexAngle(e){return gt(e*(Ge/(this._pointLabels.length||1))+ct(this.options.startAngle||0))}getDistanceFromCenterForValue(e){if(Ee(e))return NaN;const t=this.drawingArea/(this.max-this.min);return this.options.reverse?(this.max-e)*t:(e-this.min)*t}getValueForDistanceFromCenter(e){if(Ee(e))return NaN;const t=e/(this.drawingArea/(this.max-this.min));return this.options.reverse?this.max-t:this.min+t}getPointLabelContext(e){const t=this._pointLabels||[];if(e>=0&&e<t.length){const s=t[e];return function(e,t,s){return _s(e,{label:s,index:t,type:"pointLabel"})}(this.getContext(),e,s)}}getPointPosition(e,t,s=0){const i=this.getIndexAngle(e)-et+s;return{x:Math.cos(i)*t+this.xCenter,y:Math.sin(i)*t+this.yCenter,angle:i}}getPointPositionForValue(e,t){return this.getPointPosition(e,this.getDistanceFromCenterForValue(t))}getBasePosition(e){return this.getPointPositionForValue(e||0,this.getBaseValue())}getPointLabelPosition(e){const{left:t,top:s,right:i,bottom:n}=this._pointLabelItems[e];return{left:t,top:s,right:i,bottom:n}}drawBackground(){const{backgroundColor:e,grid:{circular:t}}=this.options;if(e){const s=this.ctx;s.save(),s.beginPath(),ja(this,this.getDistanceFromCenterForValue(this._endValue),t,this._pointLabels.length),s.closePath(),s.fillStyle=e,s.fill(),s.restore()}}drawGrid(){const e=this.ctx,t=this.options,{angleLines:s,grid:i,border:n}=t,o=this._pointLabels.length;let a,r,l;if(t.pointLabels.display&&function(e,t){const{ctx:s,options:{pointLabels:i}}=e;for(let n=t-1;n>=0;n--){const t=e._pointLabelItems[n];if(!t.visible)continue;const o=i.setContext(e.getPointLabelContext(n));Wa(s,o,t);const a=ys(o.font),{x:r,y:l,textAlign:c}=t;cs(s,e._pointLabels[n],r,l+a.lineHeight/2,a,{color:o.color,textAlign:c,textBaseline:"middle"})}}(this,o),i.display&&this.ticks.forEach((e,t)=>{if(0!==t||0===t&&this.min<0){r=this.getDistanceFromCenterForValue(e.value);const s=this.getContext(t),a=i.setContext(s),l=n.setContext(s);!function(e,t,s,i,n){const o=e.ctx,a=t.circular,{color:r,lineWidth:l}=t;!a&&!i||!r||!l||s<0||(o.save(),o.strokeStyle=r,o.lineWidth=l,o.setLineDash(n.dash||[]),o.lineDashOffset=n.dashOffset,o.beginPath(),ja(e,s,a,i),o.closePath(),o.stroke(),o.restore())}(this,a,r,o,l)}}),s.display){for(e.save(),a=o-1;a>=0;a--){const i=s.setContext(this.getPointLabelContext(a)),{color:n,lineWidth:o}=i;o&&n&&(e.lineWidth=o,e.strokeStyle=n,e.setLineDash(i.borderDash),e.lineDashOffset=i.borderDashOffset,r=this.getDistanceFromCenterForValue(t.reverse?this.min:this.max),l=this.getPointPosition(a,r),e.beginPath(),e.moveTo(this.xCenter,this.yCenter),e.lineTo(l.x,l.y),e.stroke())}e.restore()}}drawBorder(){}drawLabels(){const e=this.ctx,t=this.options,s=t.ticks;if(!s.display)return;const i=this.getIndexAngle(0);let n,o;e.save(),e.translate(this.xCenter,this.yCenter),e.rotate(i),e.textAlign="center",e.textBaseline="middle",this.ticks.forEach((i,a)=>{if(0===a&&this.min>=0&&!t.reverse)return;const r=s.setContext(this.getContext(a)),l=ys(r.font);if(n=this.getDistanceFromCenterForValue(this.ticks[a].value),r.showLabelBackdrop){e.font=l.string,o=e.measureText(i.label).width,e.fillStyle=r.backdropColor;const t=vs(r.backdropPadding);e.fillRect(-o/2-t.left,-n-l.size/2-t.top,o+t.width,l.size+t.height)}cs(e,i.label,0,-n,l,{color:r.color,strokeColor:r.textStrokeColor,strokeWidth:r.textStrokeWidth})}),e.restore()}drawTitle(){}}const Ua={millisecond:{common:!0,size:1,steps:1e3},second:{common:!0,size:1e3,steps:60},minute:{common:!0,size:6e4,steps:60},hour:{common:!0,size:36e5,steps:24},day:{common:!0,size:864e5,steps:30},week:{common:!1,size:6048e5,steps:4},month:{common:!0,size:2628e6,steps:12},quarter:{common:!1,size:7884e6,steps:4},year:{common:!0,size:3154e7}},Xa=Object.keys(Ua);function Ja(e,t){return e-t}function Ga(e,t){if(Ee(t))return null;const s=e._adapter,{parser:i,round:n,isoWeekday:o}=e._parseOpts;let a=t;return"function"==typeof i&&(a=i(a)),Ie(a)||(a="string"==typeof i?s.parse(a,i):s.parse(a)),null===a?null:(n&&(a="week"!==n||!rt(o)&&!0!==o?s.startOf(a,n):s.startOf(a,"isoWeek",o)),+a)}function Ya(e,t,s,i){const n=Xa.length;for(let o=Xa.indexOf(e);o<n-1;++o){const e=Ua[Xa[o]],n=e.steps?e.steps:Number.MAX_SAFE_INTEGER;if(e.common&&Math.ceil((s-t)/(n*e.size))<=i)return Xa[o]}return Xa[n-1]}function Ka(e,t,s){if(s){if(s.length){const{lo:i,hi:n}=yt(s,t);e[s[i]>=t?s[i]:s[n]]=!0}}else e[t]=!0}function Za(e,t,s){const i=[],n={},o=t.length;let a,r;for(a=0;a<o;++a)r=t[a],n[r]=a,i.push({value:r,major:!1});return 0!==o&&s?function(e,t,s,i){const n=e._adapter,o=+n.startOf(t[0].value,i),a=t[t.length-1].value;let r,l;for(r=o;r<=a;r=+n.add(r,1,i))l=s[r],l>=0&&(t[l].major=!0);return t}(e,i,n,s):i}class er extends zn{static id="time";static defaults={bounds:"data",adapters:{},time:{parser:!1,unit:!1,round:!1,isoWeekday:!1,minUnit:"millisecond",displayFormats:{}},ticks:{source:"auto",callback:!1,major:{enabled:!1}}};constructor(e){super(e),this._cache={data:[],labels:[],all:[]},this._unit="day",this._majorUnit=void 0,this._offsets={},this._normalized=!1,this._parseOpts=void 0}init(e,t={}){const s=e.time||(e.time={}),i=this._adapter=new Wi(e.adapters.date);i.init(t),Qe(s.displayFormats,i.formats()),this._parseOpts={parser:s.parser,round:s.round,isoWeekday:s.isoWeekday},super.init(e),this._normalized=t.normalized}parse(e,t){return void 0===e?null:Ga(this,e)}beforeLayout(){super.beforeLayout(),this._cache={data:[],labels:[],all:[]}}determineDataLimits(){const e=this.options,t=this._adapter,s=e.time.unit||"day";let{min:i,max:n,minDefined:o,maxDefined:a}=this.getUserBounds();function r(e){o||isNaN(e.min)||(i=Math.min(i,e.min)),a||isNaN(e.max)||(n=Math.max(n,e.max))}o&&a||(r(this._getLabelBounds()),"ticks"===e.bounds&&"labels"===e.ticks.source||r(this.getMinMax(!1))),i=Ie(i)&&!isNaN(i)?i:+t.startOf(Date.now(),s),n=Ie(n)&&!isNaN(n)?n:+t.endOf(Date.now(),s)+1,this.min=Math.min(i,n-1),this.max=Math.max(i+1,n)}_getLabelBounds(){const e=this.getLabelTimestamps();let t=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY;return e.length&&(t=e[0],s=e[e.length-1]),{min:t,max:s}}buildTicks(){const e=this.options,t=e.time,s=e.ticks,i="labels"===s.source?this.getLabelTimestamps():this._generate();"ticks"===e.bounds&&i.length&&(this.min=this._userMin||i[0],this.max=this._userMax||i[i.length-1]);const n=this.min,o=function(e,t,s){let i=0,n=e.length;for(;i<n&&e[i]<t;)i++;for(;n>i&&e[n-1]>s;)n--;return i>0||n<e.length?e.slice(i,n):e}(i,n,this.max);return this._unit=t.unit||(s.autoSkip?Ya(t.minUnit,this.min,this.max,this._getLabelCapacity(n)):function(e,t,s,i,n){for(let o=Xa.length-1;o>=Xa.indexOf(s);o--){const s=Xa[o];if(Ua[s].common&&e._adapter.diff(n,i,s)>=t-1)return s}return Xa[s?Xa.indexOf(s):0]}(this,o.length,t.minUnit,this.min,this.max)),this._majorUnit=s.major.enabled&&"year"!==this._unit?function(e){for(let t=Xa.indexOf(e)+1,s=Xa.length;t<s;++t)if(Ua[Xa[t]].common)return Xa[t]}(this._unit):void 0,this.initOffsets(i),e.reverse&&o.reverse(),Za(this,o,this._majorUnit)}afterAutoSkip(){this.options.offsetAfterAutoskip&&this.initOffsets(this.ticks.map(e=>+e.value))}initOffsets(e=[]){let t,s,i=0,n=0;this.options.offset&&e.length&&(t=this.getDecimalForValue(e[0]),i=1===e.length?1-t:(this.getDecimalForValue(e[1])-t)/2,s=this.getDecimalForValue(e[e.length-1]),n=1===e.length?s:(s-this.getDecimalForValue(e[e.length-2]))/2);const o=e.length<3?.5:.25;i=bt(i,0,o),n=bt(n,0,o),this._offsets={start:i,end:n,factor:1/(i+1+n)}}_generate(){const e=this._adapter,t=this.min,s=this.max,i=this.options,n=i.time,o=n.unit||Ya(n.minUnit,t,s,this._getLabelCapacity(t)),a=qe(i.ticks.stepSize,1),r="week"===o&&n.isoWeekday,l=rt(r)||!0===r,c={};let d,u,h=t;if(l&&(h=+e.startOf(h,"isoWeek",r)),h=+e.startOf(h,l?"day":o),e.diff(s,t,o)>1e5*a)throw new Error(t+" and "+s+" are too far apart with stepSize of "+a+" "+o);const p="data"===i.ticks.source&&this.getDataTimestamps();for(d=h,u=0;d<s;d=+e.add(d,a,o),u++)Ka(c,d,p);return d!==s&&"ticks"!==i.bounds&&1!==u||Ka(c,d,p),Object.keys(c).sort(Ja).map(e=>+e)}getLabelForValue(e){const t=this._adapter,s=this.options.time;return s.tooltipFormat?t.format(e,s.tooltipFormat):t.format(e,s.displayFormats.datetime)}format(e,t){const s=this.options.time.displayFormats,i=this._unit,n=t||s[i];return this._adapter.format(e,n)}_tickFormatFunction(e,t,s,i){const n=this.options,o=n.ticks.callback;if(o)return Pe(o,[e,t,s],this);const a=n.time.displayFormats,r=this._unit,l=this._majorUnit,c=r&&a[r],d=l&&a[l],u=s[t],h=l&&d&&u&&u.major;return this._adapter.format(e,i||(h?d:c))}generateTickLabels(e){let t,s,i;for(t=0,s=e.length;t<s;++t)i=e[t],i.label=this._tickFormatFunction(i.value,t,e)}getDecimalForValue(e){return null===e?NaN:(e-this.min)/(this.max-this.min)}getPixelForValue(e){const t=this._offsets,s=this.getDecimalForValue(e);return this.getPixelForDecimal((t.start+s)*t.factor)}getValueForPixel(e){const t=this._offsets,s=this.getDecimalForPixel(e)/t.factor-t.end;return this.min+s*(this.max-this.min)}_getLabelSize(e){const t=this.options.ticks,s=this.ctx.measureText(e).width,i=ct(this.isHorizontal()?t.maxRotation:t.minRotation),n=Math.cos(i),o=Math.sin(i),a=this._resolveTickFontOptions(0).size;return{w:s*n+a*o,h:s*o+a*n}}_getLabelCapacity(e){const t=this.options.time,s=t.displayFormats,i=s[t.unit]||s.millisecond,n=this._tickFormatFunction(e,0,Za(this,[e],this._majorUnit),i),o=this._getLabelSize(n),a=Math.floor(this.isHorizontal()?this.width/o.w:this.height/o.h)-1;return a>0?a:1}getDataTimestamps(){let e,t,s=this._cache.data||[];if(s.length)return s;const i=this.getMatchingVisibleMetas();if(this._normalized&&i.length)return this._cache.data=i[0].controller.getAllParsedValues(this);for(e=0,t=i.length;e<t;++e)s=s.concat(i[e].controller.getAllParsedValues(this));return this._cache.data=this.normalize(s)}getLabelTimestamps(){const e=this._cache.labels||[];let t,s;if(e.length)return e;const i=this.getLabels();for(t=0,s=i.length;t<s;++t)e.push(Ga(this,i[t]));return this._cache.labels=this._normalized?e:this.normalize(e)}normalize(e){return Ct(e.sort(Ja))}}function tr(e,t,s){let i,n,o,a,r=0,l=e.length-1;s?(t>=e[r].pos&&t<=e[l].pos&&({lo:r,hi:l}=wt(e,"pos",t)),({pos:i,time:o}=e[r]),({pos:n,time:a}=e[l])):(t>=e[r].time&&t<=e[l].time&&({lo:r,hi:l}=wt(e,"time",t)),({time:i,pos:o}=e[r]),({time:n,pos:a}=e[l]));const c=n-i;return c?o+(a-o)*(t-i)/c:o}var sr=Object.freeze({__proto__:null,CategoryScale:class extends zn{static id="category";static defaults={ticks:{callback:La}};constructor(e){super(e),this._startValue=void 0,this._valueRange=0,this._addedLabels=[]}init(e){const t=this._addedLabels;if(t.length){const e=this.getLabels();for(const{index:s,label:i}of t)e[s]===i&&e.splice(s,1);this._addedLabels=[]}super.init(e)}parse(e,t){if(Ee(e))return null;const s=this.getLabels();return((e,t)=>null===e?null:bt(Math.round(e),0,t))(t=isFinite(t)&&s[t]===e?t:function(e,t,s,i){const n=e.indexOf(t);return-1===n?((e,t,s,i)=>("string"==typeof t?(s=e.push(t)-1,i.unshift({index:s,label:t})):isNaN(t)&&(s=null),s))(e,t,s,i):n!==e.lastIndexOf(t)?s:n}(s,e,qe(t,e),this._addedLabels),s.length-1)}determineDataLimits(){const{minDefined:e,maxDefined:t}=this.getUserBounds();let{min:s,max:i}=this.getMinMax(!0);"ticks"===this.options.bounds&&(e||(s=0),t||(i=this.getLabels().length-1)),this.min=s,this.max=i}buildTicks(){const e=this.min,t=this.max,s=this.options.offset,i=[];let n=this.getLabels();n=0===e&&t===n.length-1?n:n.slice(e,t+1),this._valueRange=Math.max(n.length-(s?0:1),1),this._startValue=this.min-(s?.5:0);for(let s=e;s<=t;s++)i.push({value:s});return i}getLabelForValue(e){return La.call(this,e)}configure(){super.configure(),this.isHorizontal()||(this._reversePixels=!this._reversePixels)}getPixelForValue(e){return"number"!=typeof e&&(e=this.parse(e)),null===e?NaN:this.getPixelForDecimal((e-this._startValue)/this._valueRange)}getPixelForTick(e){const t=this.ticks;return e<0||e>t.length-1?null:this.getPixelForValue(t[e].value)}getValueForPixel(e){return Math.round(this._startValue+this.getDecimalForPixel(e)*this._valueRange)}getBasePixel(){return this.bottom}},LinearScale:qa,LogarithmicScale:za,RadialLinearScale:Va,TimeScale:er,TimeSeriesScale:class extends er{static id="timeseries";static defaults=er.defaults;constructor(e){super(e),this._table=[],this._minPos=void 0,this._tableRange=void 0}initOffsets(){const e=this._getTimestampsForTable(),t=this._table=this.buildLookupTable(e);this._minPos=tr(t,this.min),this._tableRange=tr(t,this.max)-this._minPos,super.initOffsets(e)}buildLookupTable(e){const{min:t,max:s}=this,i=[],n=[];let o,a,r,l,c;for(o=0,a=e.length;o<a;++o)l=e[o],l>=t&&l<=s&&i.push(l);if(i.length<2)return[{time:t,pos:0},{time:s,pos:1}];for(o=0,a=i.length;o<a;++o)c=i[o+1],r=i[o-1],l=i[o],Math.round((c+r)/2)!==l&&n.push({time:l,pos:o/(a-1)});return n}_generate(){const e=this.min,t=this.max;let s=super.getDataTimestamps();return s.includes(e)&&s.length||s.splice(0,0,e),s.includes(t)&&1!==s.length||s.push(t),s.sort((e,t)=>e-t)}_getTimestampsForTable(){let e=this._cache.all||[];if(e.length)return e;const t=this.getDataTimestamps(),s=this.getLabelTimestamps();return e=t.length&&s.length?this.normalize(t.concat(s)):t.length?t:s,e=this._cache.all=e,e}getDecimalForValue(e){return(tr(this._table,e)-this._minPos)/this._tableRange}getValueForPixel(e){const t=this._offsets,s=this.getDecimalForPixel(e)/t.factor-t.end;return tr(this._table,s*this._tableRange+this._minPos,!0)}}});const ir=[Qi,qo,Ta,sr];mo.register(...ir);const nr=mo;class or{constructor(){this.charts={},this.init()}init(){const e=document.getElementById("lp-cb-dashboard-chart-data");if(e){try{this.chartData=JSON.parse(e.textContent)}catch(e){return void console.warn("Dashboard: Failed to parse chart data",e)}this.initSalesChart(),this.initStudentsChart(),this.bindFilterEvents()}}createGradient(e,t){const s=e.createLinearGradient(0,0,0,e.canvas.height);return s.addColorStop(0,t+"40"),s.addColorStop(1,t+"05"),s}getChartConfig(e,t,s,i="",n=!1){return{type:"line",data:{labels:e,datasets:[{data:t,borderColor:s,borderWidth:2.5,backgroundColor:e=>{const{ctx:t}=e.chart;return this.createGradient(t,s)},fill:!0,tension:.4,pointBackgroundColor:s,pointBorderColor:"#fff",pointBorderWidth:2,pointRadius:0,pointHoverRadius:6,pointHoverBorderWidth:2}]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{backgroundColor:"#1e1e1e",titleColor:"#fff",bodyColor:"#fff",borderColor:"rgba(255,255,255,0.1)",borderWidth:1,cornerRadius:8,padding:12,displayColors:!1,callbacks:{label:e=>{const t=e.parsed.y||0;return i+t.toLocaleString()}}}},scales:{x:{grid:{display:!1},ticks:{color:"#9ca3af",font:{size:11},maxRotation:0},border:{display:!1}},y:{grid:{color:"rgba(0,0,0,0.04)",drawBorder:!1},ticks:{stepSize:n?1:void 0,color:"#9ca3af",font:{size:11},callback:e=>i+e.toLocaleString()},border:{display:!1},beginAtZero:!0}},interaction:{intersect:!1,mode:"index"}}}}initSalesChart(){const e=document.getElementById("lp-cb-chart-sales");if(!e)return;const{labels:t=[],data:s=[]}=this.chartData.sales||{},i=this.getChartConfig(t,s,"#10b981","$");this.charts.sales=new nr(e,i)}initStudentsChart(){const e=document.getElementById("lp-cb-chart-students");if(!e)return;const{labels:t=[],data:s=[]}=this.chartData.students||{},i=this.getChartConfig(t,s,"#f59e0b","",!0);this.charts.students=new nr(e,i)}bindFilterEvents(){document.querySelectorAll(".chart-card__filter").forEach(e=>{e.addEventListener("change",e=>{const t=e.target.dataset.chart,s=e.target.value;this.fetchChartData(t,s)})})}async fetchChartData(e,t){const s=this.charts[e];if(!s)return;const i=new FormData;i.append("action","lp_cb_dashboard_chart_data"),i.append("chart_type",e),i.append("period",t),i.append("nonce",this.chartData.nonce);try{const e=await fetch(this.chartData.ajaxUrl,{method:"POST",body:i}),t=await e.json();t.success&&t.data&&(s.data.labels=t.data.labels||[],s.data.datasets[0].data=t.data.data||[],s.update("none"))}catch(e){console.warn("Dashboard: Failed to fetch chart data",e)}}}class ar{constructor(){this.form=null,this.debounceTimer=null,this.debounceDelay=600,this.isSaving=!1,this.isDirty=!1,this.shouldRetryOnCompleted=!1,this.lastSavedState="",this.mediaUploader=null,this.init()}static selectors={elForm:"#lp-cb-settings-form",elCheckbox:'input[name="hide_instructor_access_admin_screen"]',elBadge:"[data-setting-badge]",elHeaderLogoLink:".lp-cb-top-header__logo a",elLogoSetting:"[data-cb-logo-setting]",elDefaultLogoTemplate:"#lp-cb-default-logo-template",elLogoPreviewDefault:"[data-cb-logo-preview-default]",elLogoPreviewImage:"[data-cb-logo-preview-image]",elLogoChooseBtn:"[data-cb-logo-choose]",elLogoRemoveBtn:"[data-cb-logo-remove]",elLogoIdInput:'input[name="course_builder_logo_id"]',elLogoRemoveInput:'input[name="course_builder_logo_remove"]'};init(){this.form=document.querySelector(ar.selectors.elForm),this.form&&(this.cacheElements(),this.updateBadge(this.getCurrentValue()),this.hydrateDefaultLogoPreview(),this.setLogoVisibility(this.getLogoId()>0),this.lastSavedState=this.getStateFingerprint(),this.events())}cacheElements(){this.headerLogoLink=document.querySelector(ar.selectors.elHeaderLogoLink),this.logoSetting=this.form?.querySelector(ar.selectors.elLogoSetting),this.logoPreviewDefault=this.form?.querySelector(ar.selectors.elLogoPreviewDefault),this.logoPreviewImage=this.form?.querySelector(ar.selectors.elLogoPreviewImage),this.logoChooseBtn=this.form?.querySelector(ar.selectors.elLogoChooseBtn),this.logoRemoveBtn=this.form?.querySelector(ar.selectors.elLogoRemoveBtn),this.logoIdInput=this.form?.querySelector(ar.selectors.elLogoIdInput),this.logoRemoveInput=this.form?.querySelector(ar.selectors.elLogoRemoveInput),this.defaultLogoURL=this.logoSetting?.dataset?.cbDefaultLogoUrl||""}events(){ar._loadedEvents||(ar._loadedEvents=!0,this.form&&(this.form.addEventListener("change",e=>{e.target.matches(ar.selectors.elCheckbox)&&this.handleSettingChange()}),this.logoChooseBtn&&this.logoChooseBtn.addEventListener("click",e=>{e.preventDefault(),this.openLogoMediaUploader()}),this.logoRemoveBtn&&this.logoRemoveBtn.addEventListener("click",e=>{e.preventDefault(),this.removeLogo()})))}handleSettingChange(){this.isDirty=!0,this.isSaving&&(this.shouldRetryOnCompleted=!0),this.updateBadge(this.getCurrentValue()),this.queueSave()}queueSave(){window.clearTimeout(this.debounceTimer),this.debounceTimer=window.setTimeout(()=>{this.flushSave()},this.debounceDelay)}flushSave(){this.isDirty&&(this.getStateFingerprint()!==this.lastSavedState?this.isSaving||(this.isSaving=!0,this.shouldRetryOnCompleted=!1,n.W("Updating settings...","info",{duration:1800}),window.lpAJAXG.fetchAJAX(this.getPayloadForSave(),{success:e=>{"success"===e?.status?(this.applySaveResponse(e),this.isDirty=!1,this.lastSavedState=this.getStateFingerprint(),this.updateBadge(this.getCurrentValue()),n.W(e?.message||"Saved","success")):this.handleSaveError(e?.message||"Could not save changes.")},error:e=>{this.handleSaveError(e?.message||e||"An error occurred.")},completed:()=>{this.isSaving=!1,this.shouldRetryOnCompleted&&this.queueSave()}})):this.isDirty=!1)}getPayloadForSave(){return{action:"save_global_settings",args:{id_url:"save-global-settings"},hide_instructor_access_admin_screen:this.getCurrentValue(),course_builder_logo_id:this.getLogoId(),course_builder_logo_remove:this.getLogoRemoveValue()}}applySaveResponse(e){var t;const s=e?.data||{},i=parseInt(null!==(t=s.course_builder_logo_id)&&void 0!==t?t:this.getLogoId(),10)||0,n=s.course_builder_logo_url||"";this.logoIdInput&&(this.logoIdInput.value=i),this.logoRemoveInput&&(this.logoRemoveInput.value="no"),i>0&&n?(this.setLogoImageSource(n),this.setLogoVisibility(!0)):0===i&&this.clearLogoUI(),this.syncHeaderLogo(i>0?n:"")}handleSaveError(e){n.W(e,"error")}getCurrentValue(){const e=this.form?.querySelector(ar.selectors.elCheckbox);return e&&e.checked?"yes":"no"}updateBadge(e){const t=this.form?.querySelector(ar.selectors.elBadge);if(!t)return;const s="yes"===e;t.dataset.state=s?"enabled":"disabled",t.textContent=s?"Enabled":"Disabled"}getStateFingerprint(){return JSON.stringify({hide_instructor_access_admin_screen:this.getCurrentValue(),course_builder_logo_id:this.getLogoId(),course_builder_logo_remove:this.getLogoRemoveValue()})}getLogoId(){return parseInt(this.logoIdInput?.value||"0",10)||0}getLogoRemoveValue(){return"yes"===this.logoRemoveInput?.value?"yes":"no"}openLogoMediaUploader(){"undefined"!=typeof wp&&void 0!==wp.media?(this.mediaUploader||(this.mediaUploader=wp.media({title:"Select logo image",button:{text:"Use this image"},multiple:!1,library:{type:"image"}}),this.mediaUploader.on("select",()=>{const e=this.mediaUploader.state().get("selection").first().toJSON(),t=e?.sizes?.full?.url||e?.url||"";t&&(this.logoIdInput&&(this.logoIdInput.value=e?.id||0),this.logoRemoveInput&&(this.logoRemoveInput.value="no"),this.setLogoImageSource(t),this.setLogoVisibility(!0),this.handleSettingChange())})),this.mediaUploader.open()):n.W("Media library is unavailable.","error")}setLogoImageSource(e){this.logoPreviewImage&&(e?this.logoPreviewImage.src=e:this.logoPreviewImage.removeAttribute("src"))}setLogoVisibility(e){this.logoPreviewImage&&this.logoPreviewImage.classList.toggle("is-hidden",!e),this.logoPreviewDefault&&this.logoPreviewDefault.classList.toggle("is-hidden",e),this.logoRemoveBtn&&this.logoRemoveBtn.classList.toggle("is-hidden",!e)}hydrateDefaultLogoPreview(){if(!this.logoPreviewDefault||this.logoPreviewDefault.children.length>0)return;const e=document.querySelector(ar.selectors.elDefaultLogoTemplate),t=e?.content?.querySelector("svg")||e?.querySelector("svg")||document.querySelector(".lp-cb-top-header__logo svg");if(!t&&!this.defaultLogoURL)return;const s=document.createElement("img");s.classList.add("lp-cb-logo-setting__preview-default-image"),s.setAttribute("aria-hidden","true"),s.alt="Course Builder default logo",s.src=t?`data:image/svg+xml;charset=UTF-8,${encodeURIComponent(t.outerHTML)}`:this.defaultLogoURL,this.logoPreviewDefault.appendChild(s)}removeLogo(){this.logoIdInput&&(this.clearLogoUI(),this.logoRemoveInput&&(this.logoRemoveInput.value="yes"),this.handleSettingChange())}clearLogoUI(){this.logoPreviewImage&&(this.logoPreviewImage.src=""),this.logoIdInput&&(this.logoIdInput.value=0),this.setLogoVisibility(!1)}syncHeaderLogo(e=""){if(!this.headerLogoLink)return;const t=e||this.defaultLogoURL;if(!t)return;let s=this.headerLogoLink.querySelector(".lp-cb-top-header__logo-image");s||(s=document.createElement("img"),s.classList.add("lp-cb-top-header__logo-image"),s.alt="Course Builder",s.loading="eager",s.decoding="async",this.headerLogoLink.textContent="",this.headerLogoLink.appendChild(s)),s.removeAttribute("srcset"),s.removeAttribute("sizes"),s.src=t}}let rr=null,lr=null;class cr{constructor(e={}){this.options={isCourseBuilder:!1,...e},this.init()}static selectors={elBtnApplyCurriculum:".lp-btn-apply-curriculum"};init(){lpData?.enable_open_ai&&(this.options.isCourseBuilder?e.lpOnElementReady(w.selectors.idElEditCurriculum,e=>{e.querySelector(b.selectors.elCountSections).insertAdjacentHTML("beforebegin",'<button type="button"\n\t\t\t\t\t\tclass="cb-course-edit-ai-btn lp-btn-generate-with-ai"\n\t\t\t\t\t\tdata-template="#lp-tmpl-edit-course-curriculum-ai">\n\t\t\t\t\t\t<i class="lp-ico-ai"></i>\n\t\t\t\t\t</button>')}):e.lpOnElementReady(w.selectors.idElEditCurriculum,e=>{e.querySelector(b.selectors.elCountSections).insertAdjacentHTML("afterend",'<button type="button"\n\t\t\t\t\tclass="lp-btn-generate-with-ai lp-btn-ai-style"\n\t\t\t\t\tdata-template="#lp-tmpl-edit-course-curriculum-ai">\n\t\t\t\t\t<i class="lp-ico-ai"></i><span>Generate with AI</span>\n\t\t\t\t</button>')}),this.events())}events(){cr._loadedEvents||(cr._loadedEvents=!0,e.eventHandlers("click",[{selector:cr.selectors.elBtnApplyCurriculum,class:this,callBack:this.applyData.name}]))}async applyData(t){const{e:s,target:o}=t;let a=JSON.parse(o.dataset.send);if(a=e.mergeDataWithDatForm(o.closest("form"),a),!a["lp-openai-generated-data"])return;const r=JSON.parse(a["lp-openai-generated-data"])[0].sections;r&&0!==r.length||n.W("No sections found in the generated data.","error"),i().close(),await new Promise(e=>setTimeout(e,500)),rr=new b,rr.init(),lr=new f,lr.init();const l=document.querySelector(w.selectors.idElEditCurriculum);l.querySelector(b.selectors.elDivAddNewSection).scrollIntoView({behavior:"smooth",block:"center"}),await new Promise(e=>setTimeout(e,800));for(const e of r){const t=l.querySelector(b.selectors.elSectionTitleNewInput),s=l.querySelector(b.selectors.elBtnAddSection);t.value=e.section_title||"",await new Promise(t=>{rr.addSection({e:new PointerEvent("click"),target:s,callBackNest:this.updateSectionDescription({sectionData:e,elEditCurriculum:l}),resolve:t})})}}updateSectionDescription(e){const{sectionData:t,elEditCurriculum:s}=e;return{success:async e=>{const{elSection:i}=e;await new Promise(e=>setTimeout(e,1e3));const n=i.querySelector(b.selectors.elSectionDesInput);n.value=t.section_description||"",await new Promise(e=>{rr.updateSectionDescription({e:new PointerEvent("click"),target:n,callBackNest:this.addSectionItems({sectionData:t,elEditCurriculum:s}),resolve:e})}),setTimeout(e.resolve,1)},error:e=>{},completed:()=>{}}}addSectionItems(e){const{sectionData:t,elEditCurriculum:s}=e,i=t.lessons||[],n=t.quizzes||[];return{success:async e=>{const{elSection:t}=e,o=t.querySelector(`${f.selectors.elBtnSelectItemType}[data-item-type=lp_lesson]`),a=t.querySelector(`${f.selectors.elBtnSelectItemType}[data-item-type=lp_quiz]`);for(const e of i)o.click(),await this.addItemToSection({itemData:e,elSection:t,elEditCurriculum:s});for(const e of n)a.click(),await this.addItemToSection({itemData:e,elSection:t,elEditCurriculum:s});setTimeout(e.resolve,1)},error:e=>{},completed:()=>{}}}async addItemToSection(e){const{itemData:t,elSection:s,elEditCurriculum:i}=e,n=s.querySelector(f.selectors.elBtnAddItem);s.querySelector(f.selectors.elAddItemTypeTitleInput).value=t.lesson_title||t.quiz_title||"",n.scrollIntoView({behavior:"smooth",block:"center"}),await new Promise(e=>{lr.addItemToSection({e:new PointerEvent("click"),target:n,resolve:e,callBackNest:{completed:async t=>{setTimeout(e,1e3)}}})}),setTimeout(e.resolve,1)}}function dr(e,t){e.split(/\s+/).forEach(e=>{t(e)})}class ur{constructor(){this._events={}}on(e,t){dr(e,e=>{const s=this._events[e]||[];s.push(t),this._events[e]=s})}off(e,t){var s=arguments.length;0!==s?dr(e,e=>{if(1===s)return void delete this._events[e];const i=this._events[e];void 0!==i&&(i.splice(i.indexOf(t),1),this._events[e]=i)}):this._events={}}trigger(e,...t){var s=this;dr(e,e=>{const i=s._events[e];void 0!==i&&i.forEach(e=>{e.apply(s,t)})})}}const hr=e=>(e=e.filter(Boolean)).length<2?e[0]||"":1==br(e)?"["+e.join("")+"]":"(?:"+e.join("|")+")",pr=e=>{if(!gr(e))return e.join("");let t="",s=0;const i=()=>{s>1&&(t+="{"+s+"}")};return e.forEach((n,o)=>{n!==e[o-1]?(i(),t+=n,s=1):s++}),i(),t},mr=e=>{let t=Array.from(e);return hr(t)},gr=e=>new Set(e).size!==e.length,fr=e=>(e+"").replace(/([\$\(\)\*\+\.\?\[\]\^\{\|\}\\])/gu,"\\$1"),br=e=>e.reduce((e,t)=>Math.max(e,vr(t)),0),vr=e=>Array.from(e).length,yr=e=>{if(1===e.length)return[[e]];let t=[];const s=e.substring(1);return yr(s).forEach(function(s){let i=s.slice(0);i[0]=e.charAt(0)+i[0],t.push(i),i=s.slice(0),i.unshift(e.charAt(0)),t.push(i)}),t},wr=[[0,65535]];let _r,xr;const Sr={},Cr={"/":"⁄∕",0:"߀",a:"ⱥɐɑ",aa:"ꜳ",ae:"æǽǣ",ao:"ꜵ",au:"ꜷ",av:"ꜹꜻ",ay:"ꜽ",b:"ƀɓƃ",c:"ꜿƈȼↄ",d:"đɗɖᴅƌꮷԁɦ",e:"ɛǝᴇɇ",f:"ꝼƒ",g:"ǥɠꞡᵹꝿɢ",h:"ħⱨⱶɥ",i:"ɨı",j:"ɉȷ",k:"ƙⱪꝁꝃꝅꞣ",l:"łƚɫⱡꝉꝇꞁɭ",m:"ɱɯϻ",n:"ꞥƞɲꞑᴎлԉ",o:"øǿɔɵꝋꝍᴑ",oe:"œ",oi:"ƣ",oo:"ꝏ",ou:"ȣ",p:"ƥᵽꝑꝓꝕρ",q:"ꝗꝙɋ",r:"ɍɽꝛꞧꞃ",s:"ßȿꞩꞅʂ",t:"ŧƭʈⱦꞇ",th:"þ",tz:"ꜩ",u:"ʉ",v:"ʋꝟʌ",vy:"ꝡ",w:"ⱳ",y:"ƴɏỿ",z:"ƶȥɀⱬꝣ",hv:"ƕ"};for(let e in Cr){let t=Cr[e]||"";for(let s=0;s<t.length;s++){let i=t.substring(s,s+1);Sr[i]=e}}const kr=new RegExp(Object.keys(Sr).join("|")+"|[̀-ͯ·ʾʼ]","gu"),Ar=(e,t="NFKD")=>e.normalize(t),Er=e=>Array.from(e).reduce((e,t)=>e+Tr(t),""),Tr=e=>(e=Ar(e).toLowerCase().replace(kr,e=>Sr[e]||""),Ar(e,"NFC")),Lr=e=>{const t=(e=>{const t={},s=(e,s)=>{const i=t[e]||new Set,n=new RegExp("^"+mr(i)+"$","iu");s.match(n)||(i.add(fr(s)),t[e]=i)};for(let t of function*(e){for(const[t,s]of e)for(let e=t;e<=s;e++){let t=String.fromCharCode(e),s=Er(t);s!=t.toLowerCase()&&(s.length>3||0!=s.length&&(yield{folded:s,composed:t,code_point:e}))}}(e))s(t.folded,t.folded),s(t.folded,t.composed);return t})(e),s={};let i=[];for(let e in t){let n=t[e];n&&(s[e]=mr(n)),e.length>1&&i.push(fr(e))}i.sort((e,t)=>t.length-e.length);const n=hr(i);return xr=new RegExp("^"+n,"u"),s},Ir=(e,t=1)=>(t=Math.max(t,e.length-1),hr(yr(e).map(e=>((e,t=1)=>{let s=0;return e=e.map(e=>(_r[e]&&(s+=e.length),_r[e]||e)),s>=t?pr(e):""})(e,t)))),Dr=(e,t=!0)=>{let s=e.length>1?1:0;return hr(e.map(e=>{let i=[];const n=t?e.length():e.length()-1;for(let t=0;t<n;t++)i.push(Ir(e.substrs[t]||"",s));return pr(i)}))},qr=(e,t)=>{for(const s of t){if(s.start!=e.start||s.end!=e.end)continue;if(s.substrs.join("")!==e.substrs.join(""))continue;let t=e.parts;const i=e=>{for(const s of t){if(s.start===e.start&&s.substr===e.substr)return!1;if(1!=e.length&&1!=s.length){if(e.start<s.start&&e.end>s.start)return!0;if(s.start<e.start&&s.end>e.start)return!0}}return!1};if(!(s.parts.filter(i).length>0))return!0}return!1};class Br{parts;substrs;start;end;constructor(){this.parts=[],this.substrs=[],this.start=0,this.end=0}add(e){e&&(this.parts.push(e),this.substrs.push(e.substr),this.start=Math.min(e.start,this.start),this.end=Math.max(e.end,this.end))}last(){return this.parts[this.parts.length-1]}length(){return this.parts.length}clone(e,t){let s=new Br,i=JSON.parse(JSON.stringify(this.parts)),n=i.pop();for(const e of i)s.add(e);let o=t.substr.substring(0,e-n.start),a=o.length;return s.add({start:n.start,end:n.start+a,length:a,substr:o}),s}}const Pr=(e,t)=>{if(e)return e[t]},Mr=(e,t)=>{if(e){for(var s,i=t.split(".");(s=i.shift())&&(e=e[s]););return e}},Or=(e,t,s)=>{var i,n;return e?(e+="",null==t.regex||-1===(n=e.search(t.regex))?0:(i=t.string.length/e.length,0===n&&(i+=.5),i*s)):0},zr=(e,t)=>{var s=e[t];if("function"==typeof s)return s;s&&!Array.isArray(s)&&(e[t]=[s])},$r=(e,t)=>{if(Array.isArray(e))e.forEach(t);else for(var s in e)e.hasOwnProperty(s)&&t(e[s],s)},Fr=(e,t)=>"number"==typeof e&&"number"==typeof t?e>t?1:e<t?-1:0:(e=Er(e+"").toLowerCase())>(t=Er(t+"").toLowerCase())?1:t>e?-1:0;class Hr{items;settings;constructor(e,t){this.items=e,this.settings=t||{diacritics:!0}}tokenize(e,t,s){if(!e||!e.length)return[];const i=[],n=e.split(/\s+/);var o;return s&&(o=new RegExp("^("+Object.keys(s).map(fr).join("|")+"):(.*)$")),n.forEach(e=>{let s,n=null,a=null;o&&(s=e.match(o))&&(n=s[1],e=s[2]),e.length>0&&(a=this.settings.diacritics?(e=>{void 0===_r&&(_r=Lr(wr)),e=Er(e);let t="",s=[new Br];for(let i=0;i<e.length;i++){let n=e.substring(i).match(xr);const o=e.substring(i,i+1),a=n?n[0]:null;let r=[],l=new Set;for(const e of s){const t=e.last();if(!t||1==t.length||t.end<=i)if(a){const t=a.length;e.add({start:i,end:i+t,length:t,substr:a}),l.add("1")}else e.add({start:i,end:i+1,length:1,substr:o}),l.add("2");else if(a){let s=e.clone(i,t);const n=a.length;s.add({start:i,end:i+n,length:n,substr:a}),r.push(s)}else l.add("3")}if(r.length>0){r=r.sort((e,t)=>e.length()-t.length());for(let e of r)qr(e,s)||s.push(e)}else if(i>0&&1==l.size&&!l.has("3")){t+=Dr(s,!1);let e=new Br;const i=s[0];i&&e.add(i.last()),s=[e]}}return t+=Dr(s,!0),t})(e)||null:fr(e),a&&t&&(a="\\b"+a)),i.push({string:e,regex:a?new RegExp(a,"iu"):null,field:n})}),i}getScoreFunction(e,t){var s=this.prepareSearch(e,t);return this._getScoreFunction(s)}_getScoreFunction(e){const t=e.tokens,s=t.length;if(!s)return function(){return 0};const i=e.options.fields,n=e.weights,o=i.length,a=e.getAttrFn;if(!o)return function(){return 1};const r=1===o?function(e,t){const s=i[0].field;return Or(a(t,s),e,n[s]||1)}:function(e,t){var s=0;if(e.field){const i=a(t,e.field);!e.regex&&i?s+=1/o:s+=Or(i,e,1)}else $r(n,(i,n)=>{s+=Or(a(t,n),e,i)});return s/o};return 1===s?function(e){return r(t[0],e)}:"and"===e.options.conjunction?function(e){var i,n=0;for(let s of t){if((i=r(s,e))<=0)return 0;n+=i}return n/s}:function(e){var i=0;return $r(t,t=>{i+=r(t,e)}),i/s}}getSortFunction(e,t){var s=this.prepareSearch(e,t);return this._getSortFunction(s)}_getSortFunction(e){var t,s=[];const i=this,n=e.options,o=!e.query&&n.sort_empty?n.sort_empty:n.sort;if("function"==typeof o)return o.bind(this);const a=function(t,s){return"$score"===t?s.score:e.getAttrFn(i.items[s.id],t)};if(o)for(let t of o)(e.query||"$score"!==t.field)&&s.push(t);if(e.query){t=!0;for(let e of s)if("$score"===e.field){t=!1;break}t&&s.unshift({field:"$score",direction:"desc"})}else s=s.filter(e=>"$score"!==e.field);return s.length?function(e,t){var i,n;for(let o of s)if(n=o.field,i=("desc"===o.direction?-1:1)*Fr(a(n,e),a(n,t)))return i;return 0}:null}prepareSearch(e,t){const s={};var i=Object.assign({},t);if(zr(i,"sort"),zr(i,"sort_empty"),i.fields){zr(i,"fields");const e=[];i.fields.forEach(t=>{"string"==typeof t&&(t={field:t,weight:1}),e.push(t),s[t.field]="weight"in t?t.weight:1}),i.fields=e}return{options:i,query:e.toLowerCase().trim(),tokens:this.tokenize(e,i.respect_word_boundaries,s),total:0,items:[],weights:s,getAttrFn:i.nesting?Mr:Pr}}search(e,t){var s,i,n=this;i=this.prepareSearch(e,t),t=i.options,e=i.query;const o=t.score||n._getScoreFunction(i);e.length?$r(n.items,(e,n)=>{s=o(e),(!1===t.filter||s>0)&&i.items.push({score:s,id:n})}):$r(n.items,(e,t)=>{i.items.push({score:1,id:t})});const a=n._getSortFunction(i);return a&&i.items.sort(a),i.total=i.items.length,"number"==typeof t.limit&&(i.items=i.items.slice(0,t.limit)),i}}const Qr=e=>null==e?null:Nr(e),Nr=e=>"boolean"==typeof e?e?"1":"0":e+"",Rr=e=>(e+"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Wr=(e,t)=>{var s;return function(i,n){var o=this;s&&(o.loading=Math.max(o.loading-1,0),clearTimeout(s)),s=setTimeout(function(){s=null,o.loadedSearches[i]=!0,e.call(o,i,n)},t)}},jr=(e,t,s)=>{var i,n=e.trigger,o={};for(i of(e.trigger=function(){var s=arguments[0];if(-1===t.indexOf(s))return n.apply(e,arguments);o[s]=arguments},s.apply(e,[]),e.trigger=n,t))i in o&&n.apply(e,o[i])},Vr=(e,t=!1)=>{e&&(e.preventDefault(),t&&e.stopPropagation())},Ur=(e,t,s,i)=>{e.addEventListener(t,s,i)},Xr=(e,t)=>!!t&&!!t[e]&&1==(t.altKey?1:0)+(t.ctrlKey?1:0)+(t.shiftKey?1:0)+(t.metaKey?1:0),Jr=(e,t)=>e.getAttribute("id")||(e.setAttribute("id",t),t),Gr=e=>e.replace(/[\\"']/g,"\\$&"),Yr=(e,t)=>{t&&e.append(t)},Kr=(e,t)=>{if(Array.isArray(e))e.forEach(t);else for(var s in e)e.hasOwnProperty(s)&&t(e[s],s)},Zr=e=>{if(e.jquery)return e[0];if(e instanceof HTMLElement)return e;if(el(e)){var t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}return document.querySelector(e)},el=e=>"string"==typeof e&&e.indexOf("<")>-1,tl=(e,t)=>{var s=document.createEvent("HTMLEvents");s.initEvent(t,!0,!1),e.dispatchEvent(s)},sl=(e,t)=>{Object.assign(e.style,t)},il=(e,...t)=>{var s=ol(t);(e=al(e)).map(e=>{s.map(t=>{e.classList.add(t)})})},nl=(e,...t)=>{var s=ol(t);(e=al(e)).map(e=>{s.map(t=>{e.classList.remove(t)})})},ol=e=>{var t=[];return Kr(e,e=>{"string"==typeof e&&(e=e.trim().split(/[\t\n\f\r\s]/)),Array.isArray(e)&&(t=t.concat(e))}),t.filter(Boolean)},al=e=>(Array.isArray(e)||(e=[e]),e),rl=(e,t,s)=>{if(!s||s.contains(e))for(;e&&e.matches;){if(e.matches(t))return e;e=e.parentNode}},ll=(e,t=0)=>t>0?e[e.length-1]:e[0],cl=(e,t)=>{if(!e)return-1;t=t||e.nodeName;for(var s=0;e=e.previousElementSibling;)e.matches(t)&&s++;return s},dl=(e,t)=>{Kr(t,(t,s)=>{null==t?e.removeAttribute(s):e.setAttribute(s,""+t)})},ul=(e,t)=>{e.parentNode&&e.parentNode.replaceChild(t,e)},hl="undefined"!=typeof navigator&&/Mac/.test(navigator.userAgent)?"metaKey":"ctrlKey",pl={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:null,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,shouldOpen:null,maxOptions:50,maxItems:null,hideSelected:null,duplicates:!1,addPrecedence:!1,selectOnTab:!1,preload:null,allowEmptyOption:!1,refreshThrottle:300,loadThrottle:300,loadingClass:"loading",dataAttr:null,optgroupField:"optgroup",valueField:"value",labelField:"text",disabledField:"disabled",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:!1,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"ts-wrapper",controlClass:"ts-control",dropdownClass:"ts-dropdown",dropdownContentClass:"ts-dropdown-content",itemClass:"item",optionClass:"option",dropdownParent:null,controlInput:'<input type="text" autocomplete="off" size="1" />',copyClassesToDropdown:!1,placeholder:null,hidePlaceholder:null,shouldLoad:function(e){return e.length>0},render:{}};function ml(e,t){var s=Object.assign({},pl,t),i=s.dataAttr,n=s.labelField,o=s.valueField,a=s.disabledField,r=s.optgroupField,l=s.optgroupLabelField,c=s.optgroupValueField,d=e.tagName.toLowerCase(),u=e.getAttribute("placeholder")||e.getAttribute("data-placeholder");if(!u&&!s.allowEmptyOption){let t=e.querySelector('option[value=""]');t&&(u=t.textContent)}var h={placeholder:u,options:[],optgroups:[],items:[],maxItems:null};return"select"===d?(()=>{var t,d=h.options,u={},p=1;let m=0;var g=e=>{var t=Object.assign({},e.dataset),s=i&&t[i];return"string"==typeof s&&s.length&&(t=Object.assign(t,JSON.parse(s))),t},f=(e,t)=>{var i=Qr(e.value);if(null!=i&&(i||s.allowEmptyOption)){if(u.hasOwnProperty(i)){if(t){var l=u[i][r];l?Array.isArray(l)?l.push(t):u[i][r]=[l,t]:u[i][r]=t}}else{var c=g(e);c[n]=c[n]||e.textContent,c[o]=c[o]||i,c[a]=c[a]||e.disabled,c[r]=c[r]||t,c.$option=e,c.$order=c.$order||++m,u[i]=c,d.push(c)}e.selected&&h.items.push(i)}};h.maxItems=e.hasAttribute("multiple")?null:1,Kr(e.children,e=>{var s,i,n;"optgroup"===(t=e.tagName.toLowerCase())?((n=g(s=e))[l]=n[l]||s.getAttribute("label")||"",n[c]=n[c]||p++,n[a]=n[a]||s.disabled,n.$order=n.$order||++m,h.optgroups.push(n),i=n[c],Kr(s.children,e=>{f(e,i)})):"option"===t&&f(e)})})():(()=>{const t=e.getAttribute(i);if(t)h.options=JSON.parse(t),Kr(h.options,e=>{h.items.push(e[o])});else{var a=e.value.trim()||"";if(!s.allowEmptyOption&&!a.length)return;const t=a.split(s.delimiter);Kr(t,e=>{const t={};t[n]=e,t[o]=e,h.options.push(t)}),h.items=t}})(),Object.assign({},pl,h,t)}var gl=0;class fl extends(function(e){return e.plugins={},class extends e{constructor(){super(...arguments),this.plugins={names:[],settings:{},requested:{},loaded:{}}}static define(t,s){e.plugins[t]={name:t,fn:s}}initializePlugins(e){var t,s;const i=this,n=[];if(Array.isArray(e))e.forEach(e=>{"string"==typeof e?n.push(e):(i.plugins.settings[e.name]=e.options,n.push(e.name))});else if(e)for(t in e)e.hasOwnProperty(t)&&(i.plugins.settings[t]=e[t],n.push(t));for(;s=n.shift();)i.require(s)}loadPlugin(t){var s=this,i=s.plugins,n=e.plugins[t];if(!e.plugins.hasOwnProperty(t))throw new Error('Unable to find "'+t+'" plugin');i.requested[t]=!0,i.loaded[t]=n.fn.apply(s,[s.plugins.settings[t]||{}]),i.names.push(t)}require(e){var t=this,s=t.plugins;if(!t.plugins.loaded.hasOwnProperty(e)){if(s.requested[e])throw new Error('Plugin has circular dependency ("'+e+'")');t.loadPlugin(e)}return s.loaded[e]}}}(ur)){constructor(e,t){var s;super(),this.order=0,this.isOpen=!1,this.isDisabled=!1,this.isReadOnly=!1,this.isInvalid=!1,this.isValid=!0,this.isLocked=!1,this.isFocused=!1,this.isInputHidden=!1,this.isSetup=!1,this.ignoreFocus=!1,this.ignoreHover=!1,this.hasOptions=!1,this.lastValue="",this.caretPos=0,this.loading=0,this.loadedSearches={},this.activeOption=null,this.activeItems=[],this.optgroups={},this.options={},this.userOptions={},this.items=[],this.refreshTimeout=null,gl++;var i=Zr(e);if(i.tomselect)throw new Error("Tom Select already initialized on this element");i.tomselect=this,s=(window.getComputedStyle&&window.getComputedStyle(i,null)).getPropertyValue("direction");const n=ml(i,t);this.settings=n,this.input=i,this.tabIndex=i.tabIndex||0,this.is_select_tag="select"===i.tagName.toLowerCase(),this.rtl=/rtl/i.test(s),this.inputId=Jr(i,"tomselect-"+gl),this.isRequired=i.required,this.sifter=new Hr(this.options,{diacritics:n.diacritics}),n.mode=n.mode||(1===n.maxItems?"single":"multi"),"boolean"!=typeof n.hideSelected&&(n.hideSelected="multi"===n.mode),"boolean"!=typeof n.hidePlaceholder&&(n.hidePlaceholder="multi"!==n.mode);var o=n.createFilter;"function"!=typeof o&&("string"==typeof o&&(o=new RegExp(o)),o instanceof RegExp?n.createFilter=e=>o.test(e):n.createFilter=e=>this.settings.duplicates||!this.options[e]),this.initializePlugins(n.plugins),this.setupCallbacks(),this.setupTemplates();const a=Zr("<div>"),r=Zr("<div>"),l=this._render("dropdown"),c=Zr('<div role="listbox" tabindex="-1">'),d=this.input.getAttribute("class")||"",u=n.mode;var h;il(a,n.wrapperClass,d,u),il(r,n.controlClass),Yr(a,r),il(l,n.dropdownClass,u),n.copyClassesToDropdown&&il(l,d),il(c,n.dropdownContentClass),Yr(l,c),Zr(n.dropdownParent||a).appendChild(l),el(n.controlInput)?(h=Zr(n.controlInput),Kr(["autocorrect","autocapitalize","autocomplete","spellcheck"],e=>{i.getAttribute(e)&&dl(h,{[e]:i.getAttribute(e)})}),h.tabIndex=-1,r.appendChild(h),this.focus_node=h):n.controlInput?(h=Zr(n.controlInput),this.focus_node=h):(h=Zr("<input/>"),this.focus_node=r),this.wrapper=a,this.dropdown=l,this.dropdown_content=c,this.control=r,this.control_input=h,this.setup()}setup(){const e=this,t=e.settings,s=e.control_input,i=e.dropdown,n=e.dropdown_content,o=e.wrapper,a=e.control,r=e.input,l=e.focus_node,c={passive:!0},d=e.inputId+"-ts-dropdown";dl(n,{id:d}),dl(l,{role:"combobox","aria-haspopup":"listbox","aria-expanded":"false","aria-controls":d});const u=Jr(l,e.inputId+"-ts-control"),h="label[for='"+(e=>e.replace(/['"\\]/g,"\\$&"))(e.inputId)+"']",p=document.querySelector(h),m=e.focus.bind(e);if(p){Ur(p,"click",m),dl(p,{for:u});const t=Jr(p,e.inputId+"-ts-label");dl(l,{"aria-labelledby":t}),dl(n,{"aria-labelledby":t})}if(o.style.width=r.style.width,e.plugins.names.length){const t="plugin-"+e.plugins.names.join(" plugin-");il([o,i],t)}(null===t.maxItems||t.maxItems>1)&&e.is_select_tag&&dl(r,{multiple:"multiple"}),t.placeholder&&dl(s,{placeholder:t.placeholder}),!t.splitOn&&t.delimiter&&(t.splitOn=new RegExp("\\s*"+fr(t.delimiter)+"+\\s*")),t.load&&t.loadThrottle&&(t.load=Wr(t.load,t.loadThrottle)),Ur(i,"mousemove",()=>{e.ignoreHover=!1}),Ur(i,"mouseenter",t=>{var s=rl(t.target,"[data-selectable]",i);s&&e.onOptionHover(t,s)},{capture:!0}),Ur(i,"click",t=>{const s=rl(t.target,"[data-selectable]");s&&(e.onOptionSelect(t,s),Vr(t,!0))}),Ur(a,"click",t=>{var i=rl(t.target,"[data-ts-item]",a);i&&e.onItemSelect(t,i)?Vr(t,!0):""==s.value&&(e.onClick(),Vr(t,!0))}),Ur(l,"keydown",t=>e.onKeyDown(t)),Ur(s,"keypress",t=>e.onKeyPress(t)),Ur(s,"input",t=>e.onInput(t)),Ur(l,"blur",t=>e.onBlur(t)),Ur(l,"focus",t=>e.onFocus(t)),Ur(s,"paste",t=>e.onPaste(t));const g=t=>{const n=t.composedPath()[0];if(!o.contains(n)&&!i.contains(n))return e.isFocused&&e.blur(),void e.inputState();n==s&&e.isOpen?t.stopPropagation():Vr(t,!0)},f=()=>{e.isOpen&&e.positionDropdown()};Ur(document,"mousedown",g),Ur(window,"scroll",f,c),Ur(window,"resize",f,c),this._destroy=()=>{document.removeEventListener("mousedown",g),window.removeEventListener("scroll",f),window.removeEventListener("resize",f),p&&p.removeEventListener("click",m)},this.revertSettings={innerHTML:r.innerHTML,tabIndex:r.tabIndex},r.tabIndex=-1,r.insertAdjacentElement("afterend",e.wrapper),e.sync(!1),t.items=[],delete t.optgroups,delete t.options,Ur(r,"invalid",()=>{e.isValid&&(e.isValid=!1,e.isInvalid=!0,e.refreshState())}),e.updateOriginalInput(),e.refreshItems(),e.close(!1),e.inputState(),e.isSetup=!0,r.disabled?e.disable():r.readOnly?e.setReadOnly(!0):e.enable(),e.on("change",this.onChange),il(r,"tomselected","ts-hidden-accessible"),e.trigger("initialize"),!0===t.preload&&e.preload()}setupOptions(e=[],t=[]){this.addOptions(e),Kr(t,e=>{this.registerOptionGroup(e)})}setupTemplates(){var e=this,t=e.settings.labelField,s=e.settings.optgroupLabelField,i={optgroup:e=>{let t=document.createElement("div");return t.className="optgroup",t.appendChild(e.options),t},optgroup_header:(e,t)=>'<div class="optgroup-header">'+t(e[s])+"</div>",option:(e,s)=>"<div>"+s(e[t])+"</div>",item:(e,s)=>"<div>"+s(e[t])+"</div>",option_create:(e,t)=>'<div class="create">Add <strong>'+t(e.input)+"</strong>…</div>",no_results:()=>'<div class="no-results">No results found</div>',loading:()=>'<div class="spinner"></div>',not_loading:()=>{},dropdown:()=>"<div></div>"};e.settings.render=Object.assign({},i,e.settings.render)}setupCallbacks(){var e,t,s={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",item_select:"onItemSelect",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"};for(e in s)(t=this.settings[s[e]])&&this.on(e,t)}sync(e=!0){const t=this,s=e?ml(t.input,{delimiter:t.settings.delimiter}):t.settings;t.setupOptions(s.options,s.optgroups),t.setValue(s.items||[],!0),t.lastQuery=null}onClick(){var e=this;if(e.activeItems.length>0)return e.clearActiveItems(),void e.focus();e.isFocused&&e.isOpen?e.blur():e.focus()}onMouseDown(){}onChange(){tl(this.input,"input"),tl(this.input,"change")}onPaste(e){var t=this;t.isInputHidden||t.isLocked?Vr(e):t.settings.splitOn&&setTimeout(()=>{var e=t.inputValue();if(e.match(t.settings.splitOn)){var s=e.trim().split(t.settings.splitOn);Kr(s,e=>{Qr(e)&&(this.options[e]?t.addItem(e):t.createItem(e))})}},0)}onKeyPress(e){var t=this;if(!t.isLocked){var s=String.fromCharCode(e.keyCode||e.which);return t.settings.create&&"multi"===t.settings.mode&&s===t.settings.delimiter?(t.createItem(),void Vr(e)):void 0}Vr(e)}onKeyDown(e){var t=this;if(t.ignoreHover=!0,t.isLocked)9!==e.keyCode&&Vr(e);else{switch(e.keyCode){case 65:if(Xr(hl,e)&&""==t.control_input.value)return Vr(e),void t.selectAll();break;case 27:return t.isOpen&&(Vr(e,!0),t.close()),void t.clearActiveItems();case 40:if(!t.isOpen&&t.hasOptions)t.open();else if(t.activeOption){let e=t.getAdjacent(t.activeOption,1);e&&t.setActiveOption(e)}return void Vr(e);case 38:if(t.activeOption){let e=t.getAdjacent(t.activeOption,-1);e&&t.setActiveOption(e)}return void Vr(e);case 13:return void(t.canSelect(t.activeOption)?(t.onOptionSelect(e,t.activeOption),Vr(e)):(t.settings.create&&t.createItem()||document.activeElement==t.control_input&&t.isOpen)&&Vr(e));case 37:return void t.advanceSelection(-1,e);case 39:return void t.advanceSelection(1,e);case 9:return void(t.settings.selectOnTab&&(t.canSelect(t.activeOption)&&(t.onOptionSelect(e,t.activeOption),Vr(e)),t.settings.create&&t.createItem()&&Vr(e)));case 8:case 46:return void t.deleteSelection(e)}t.isInputHidden&&!Xr(hl,e)&&Vr(e)}}onInput(e){if(this.isLocked)return;const t=this.inputValue();var s,i;this.lastValue!==t&&(this.lastValue=t,""!=t?(this.refreshTimeout&&window.clearTimeout(this.refreshTimeout),this.refreshTimeout=(s=()=>{this.refreshTimeout=null,this._onInput()},(i=this.settings.refreshThrottle)>0?window.setTimeout(s,i):(s.call(null),null))):this._onInput())}_onInput(){const e=this.lastValue;this.settings.shouldLoad.call(this,e)&&this.load(e),this.refreshOptions(),this.trigger("type",e)}onOptionHover(e,t){this.ignoreHover||this.setActiveOption(t,!1)}onFocus(e){var t=this,s=t.isFocused;if(t.isDisabled||t.isReadOnly)return t.blur(),void Vr(e);t.ignoreFocus||(t.isFocused=!0,"focus"===t.settings.preload&&t.preload(),s||t.trigger("focus"),t.activeItems.length||(t.inputState(),t.refreshOptions(!!t.settings.openOnFocus)),t.refreshState())}onBlur(e){if(!1!==document.hasFocus()){var t=this;if(t.isFocused){t.isFocused=!1,t.ignoreFocus=!1;var s=()=>{t.close(),t.setActiveItem(),t.setCaret(t.items.length),t.trigger("blur")};t.settings.create&&t.settings.createOnBlur?t.createItem(null,s):s()}}}onOptionSelect(e,t){var s,i=this;t.parentElement&&t.parentElement.matches("[data-disabled]")||(t.classList.contains("create")?i.createItem(null,()=>{i.settings.closeAfterSelect&&i.close()}):void 0!==(s=t.dataset.value)&&(i.lastQuery=null,i.addItem(s),i.settings.closeAfterSelect&&i.close(),!i.settings.hideSelected&&e.type&&/click/.test(e.type)&&i.setActiveOption(t)))}canSelect(e){return!!(this.isOpen&&e&&this.dropdown_content.contains(e))}onItemSelect(e,t){var s=this;return!s.isLocked&&"multi"===s.settings.mode&&(Vr(e),s.setActiveItem(t,e),!0)}canLoad(e){return!!this.settings.load&&!this.loadedSearches.hasOwnProperty(e)}load(e){const t=this;if(!t.canLoad(e))return;il(t.wrapper,t.settings.loadingClass),t.loading++;const s=t.loadCallback.bind(t);t.settings.load.call(t,e,s)}loadCallback(e,t){const s=this;s.loading=Math.max(s.loading-1,0),s.lastQuery=null,s.clearActiveOption(),s.setupOptions(e,t),s.refreshOptions(s.isFocused&&!s.isInputHidden),s.loading||nl(s.wrapper,s.settings.loadingClass),s.trigger("load",e,t)}preload(){var e=this.wrapper.classList;e.contains("preloaded")||(e.add("preloaded"),this.load(""))}setTextboxValue(e=""){var t=this.control_input;t.value!==e&&(t.value=e,tl(t,"update"),this.lastValue=e)}getValue(){return this.is_select_tag&&this.input.hasAttribute("multiple")?this.items:this.items.join(this.settings.delimiter)}setValue(e,t){jr(this,t?[]:["change"],()=>{this.clear(t),this.addItems(e,t)})}setMaxItems(e){0===e&&(e=null),this.settings.maxItems=e,this.refreshState()}setActiveItem(e,t){var s,i,n,o,a,r,l=this;if("single"!==l.settings.mode){if(!e)return l.clearActiveItems(),void(l.isFocused&&l.inputState());if("click"===(s=t&&t.type.toLowerCase())&&Xr("shiftKey",t)&&l.activeItems.length){for(r=l.getLastActive(),(n=Array.prototype.indexOf.call(l.control.children,r))>(o=Array.prototype.indexOf.call(l.control.children,e))&&(a=n,n=o,o=a),i=n;i<=o;i++)e=l.control.children[i],-1===l.activeItems.indexOf(e)&&l.setActiveItemClass(e);Vr(t)}else"click"===s&&Xr(hl,t)||"keydown"===s&&Xr("shiftKey",t)?e.classList.contains("active")?l.removeActiveItem(e):l.setActiveItemClass(e):(l.clearActiveItems(),l.setActiveItemClass(e));l.inputState(),l.isFocused||l.focus()}}setActiveItemClass(e){const t=this,s=t.control.querySelector(".last-active");s&&nl(s,"last-active"),il(e,"active last-active"),t.trigger("item_select",e),-1==t.activeItems.indexOf(e)&&t.activeItems.push(e)}removeActiveItem(e){var t=this.activeItems.indexOf(e);this.activeItems.splice(t,1),nl(e,"active")}clearActiveItems(){nl(this.activeItems,"active"),this.activeItems=[]}setActiveOption(e,t=!0){e!==this.activeOption&&(this.clearActiveOption(),e&&(this.activeOption=e,dl(this.focus_node,{"aria-activedescendant":e.getAttribute("id")}),dl(e,{"aria-selected":"true"}),il(e,"active"),t&&this.scrollToOption(e)))}scrollToOption(e,t){if(!e)return;const s=this.dropdown_content,i=s.clientHeight,n=s.scrollTop||0,o=e.offsetHeight,a=e.getBoundingClientRect().top-s.getBoundingClientRect().top+n;a+o>i+n?this.scroll(a-i+o,t):a<n&&this.scroll(a,t)}scroll(e,t){const s=this.dropdown_content;t&&(s.style.scrollBehavior=t),s.scrollTop=e,s.style.scrollBehavior=""}clearActiveOption(){this.activeOption&&(nl(this.activeOption,"active"),dl(this.activeOption,{"aria-selected":null})),this.activeOption=null,dl(this.focus_node,{"aria-activedescendant":null})}selectAll(){const e=this;if("single"===e.settings.mode)return;const t=e.controlChildren();t.length&&(e.inputState(),e.close(),e.activeItems=t,Kr(t,t=>{e.setActiveItemClass(t)}))}inputState(){var e=this;e.control.contains(e.control_input)&&(dl(e.control_input,{placeholder:e.settings.placeholder}),e.activeItems.length>0||!e.isFocused&&e.settings.hidePlaceholder&&e.items.length>0?(e.setTextboxValue(),e.isInputHidden=!0):(e.settings.hidePlaceholder&&e.items.length>0&&dl(e.control_input,{placeholder:""}),e.isInputHidden=!1),e.wrapper.classList.toggle("input-hidden",e.isInputHidden))}inputValue(){return this.control_input.value.trim()}focus(){var e=this;e.isDisabled||e.isReadOnly||(e.ignoreFocus=!0,e.control_input.offsetWidth?e.control_input.focus():e.focus_node.focus(),setTimeout(()=>{e.ignoreFocus=!1,e.onFocus()},0))}blur(){this.focus_node.blur(),this.onBlur()}getScoreFunction(e){return this.sifter.getScoreFunction(e,this.getSearchOptions())}getSearchOptions(){var e=this.settings,t=e.sortField;return"string"==typeof e.sortField&&(t=[{field:e.sortField}]),{fields:e.searchField,conjunction:e.searchConjunction,sort:t,nesting:e.nesting}}search(e){var t,s,i=this,n=this.getSearchOptions();if(i.settings.score&&"function"!=typeof(s=i.settings.score.call(i,e)))throw new Error('Tom Select "score" setting must be a function that returns a function');return e!==i.lastQuery?(i.lastQuery=e,t=i.sifter.search(e,Object.assign(n,{score:s})),i.currentResults=t):t=Object.assign({},i.currentResults),i.settings.hideSelected&&(t.items=t.items.filter(e=>{let t=Qr(e.id);return!(t&&-1!==i.items.indexOf(t))})),t}refreshOptions(e=!0){var t,s,i,n,o,a,r,l,c,d;const u={},h=[];var p=this,m=p.inputValue();const g=m===p.lastQuery||""==m&&null==p.lastQuery;var f=p.search(m),b=null,v=p.settings.shouldOpen||!1,y=p.dropdown_content;g&&(b=p.activeOption)&&(c=b.closest("[data-group]")),n=f.items.length,"number"==typeof p.settings.maxOptions&&(n=Math.min(n,p.settings.maxOptions)),n>0&&(v=!0);const w=(e,t)=>{let s=u[e];if(void 0!==s){let e=h[s];if(void 0!==e)return[s,e.fragment]}let i=document.createDocumentFragment();return s=h.length,h.push({fragment:i,order:t,optgroup:e}),[s,i]};for(t=0;t<n;t++){let e=f.items[t];if(!e)continue;let n=e.id,r=p.options[n];if(void 0===r)continue;let l=Nr(n),d=p.getOption(l,!0);for(p.settings.hideSelected||d.classList.toggle("selected",p.items.includes(l)),o=r[p.settings.optgroupField]||"",s=0,i=(a=Array.isArray(o)?o:[o])&&a.length;s<i;s++){o=a[s];let e=r.$order,t=p.optgroups[o];void 0===t?o="":e=t.$order;const[i,l]=w(o,e);s>0&&(d=d.cloneNode(!0),dl(d,{id:r.$id+"-clone-"+s,"aria-selected":null}),d.classList.add("ts-cloned"),nl(d,"active"),p.activeOption&&p.activeOption.dataset.value==n&&c&&c.dataset.group===o.toString()&&(b=d)),l.appendChild(d),""!=o&&(u[o]=i)}}var _;p.settings.lockOptgroupOrder&&h.sort((e,t)=>e.order-t.order),r=document.createDocumentFragment(),Kr(h,e=>{let t=e.fragment,s=e.optgroup;if(!t||!t.children.length)return;let i=p.optgroups[s];if(void 0!==i){let e=document.createDocumentFragment(),s=p.render("optgroup_header",i);Yr(e,s),Yr(e,t);let n=p.render("optgroup",{group:i,options:e});Yr(r,n)}else Yr(r,t)}),y.innerHTML="",Yr(y,r),p.settings.highlight&&(_=y.querySelectorAll("span.highlight"),Array.prototype.forEach.call(_,function(e){var t=e.parentNode;t.replaceChild(e.firstChild,e),t.normalize()}),f.query.length&&f.tokens.length&&Kr(f.tokens,e=>{((e,t)=>{if(null===t)return;if("string"==typeof t){if(!t.length)return;t=new RegExp(t,"i")}const s=e=>3===e.nodeType?(e=>{var s=e.data.match(t);if(s&&e.data.length>0){var i=document.createElement("span");i.className="highlight";var n=e.splitText(s.index);n.splitText(s[0].length);var o=n.cloneNode(!0);return i.appendChild(o),ul(n,i),1}return 0})(e):((e=>{1!==e.nodeType||!e.childNodes||/(script|style)/i.test(e.tagName)||"highlight"===e.className&&"SPAN"===e.tagName||Array.from(e.childNodes).forEach(e=>{s(e)})})(e),0);s(e)})(y,e.regex)}));var x=e=>{let t=p.render(e,{input:m});return t&&(v=!0,y.insertBefore(t,y.firstChild)),t};if(p.loading?x("loading"):p.settings.shouldLoad.call(p,m)?0===f.items.length&&x("no_results"):x("not_loading"),(l=p.canCreate(m))&&(d=x("option_create")),p.hasOptions=f.items.length>0||l,v){if(f.items.length>0){if(b||"single"!==p.settings.mode||null==p.items[0]||(b=p.getOption(p.items[0])),!y.contains(b)){let e=0;d&&!p.settings.addPrecedence&&(e=1),b=p.selectable()[e]}}else d&&(b=d);e&&!p.isOpen&&(p.open(),p.scrollToOption(b,"auto")),p.setActiveOption(b)}else p.clearActiveOption(),e&&p.isOpen&&p.close(!1)}selectable(){return this.dropdown_content.querySelectorAll("[data-selectable]")}addOption(e,t=!1){const s=this;if(Array.isArray(e))return s.addOptions(e,t),!1;const i=Qr(e[s.settings.valueField]);return null!==i&&!s.options.hasOwnProperty(i)&&(e.$order=e.$order||++s.order,e.$id=s.inputId+"-opt-"+e.$order,s.options[i]=e,s.lastQuery=null,t&&(s.userOptions[i]=t,s.trigger("option_add",i,e)),i)}addOptions(e,t=!1){Kr(e,e=>{this.addOption(e,t)})}registerOption(e){return this.addOption(e)}registerOptionGroup(e){var t=Qr(e[this.settings.optgroupValueField]);return null!==t&&(e.$order=e.$order||++this.order,this.optgroups[t]=e,t)}addOptionGroup(e,t){var s;t[this.settings.optgroupValueField]=e,(s=this.registerOptionGroup(t))&&this.trigger("optgroup_add",s,t)}removeOptionGroup(e){this.optgroups.hasOwnProperty(e)&&(delete this.optgroups[e],this.clearCache(),this.trigger("optgroup_remove",e))}clearOptionGroups(){this.optgroups={},this.clearCache(),this.trigger("optgroup_clear")}updateOption(e,t){const s=this;var i,n;const o=Qr(e),a=Qr(t[s.settings.valueField]);if(null===o)return;const r=s.options[o];if(null==r)return;if("string"!=typeof a)throw new Error("Value must be set in option data");const l=s.getOption(o),c=s.getItem(o);if(t.$order=t.$order||r.$order,delete s.options[o],s.uncacheValue(a),s.options[a]=t,l){if(s.dropdown_content.contains(l)){const e=s._render("option",t);ul(l,e),s.activeOption===l&&s.setActiveOption(e)}l.remove()}c&&(-1!==(n=s.items.indexOf(o))&&s.items.splice(n,1,a),i=s._render("item",t),c.classList.contains("active")&&il(i,"active"),ul(c,i)),s.lastQuery=null}removeOption(e,t){const s=this;e=Nr(e),s.uncacheValue(e),delete s.userOptions[e],delete s.options[e],s.lastQuery=null,s.trigger("option_remove",e),s.removeItem(e,t)}clearOptions(e){const t=(e||this.clearFilter).bind(this);this.loadedSearches={},this.userOptions={},this.clearCache();const s={};Kr(this.options,(e,i)=>{t(e,i)&&(s[i]=e)}),this.options=this.sifter.items=s,this.lastQuery=null,this.trigger("option_clear")}clearFilter(e,t){return this.items.indexOf(t)>=0}getOption(e,t=!1){const s=Qr(e);if(null===s)return null;const i=this.options[s];if(null!=i){if(i.$div)return i.$div;if(t)return this._render("option",i)}return null}getAdjacent(e,t,s="option"){var i;if(!e)return null;i="item"==s?this.controlChildren():this.dropdown_content.querySelectorAll("[data-selectable]");for(let s=0;s<i.length;s++)if(i[s]==e)return t>0?i[s+1]:i[s-1];return null}getItem(e){if("object"==typeof e)return e;var t=Qr(e);return null!==t?this.control.querySelector(`[data-value="${Gr(t)}"]`):null}addItems(e,t){var s=this,i=Array.isArray(e)?e:[e];const n=(i=i.filter(e=>-1===s.items.indexOf(e)))[i.length-1];i.forEach(e=>{s.isPending=e!==n,s.addItem(e,t)})}addItem(e,t){jr(this,t?[]:["change","dropdown_close"],()=>{var s,i;const n=this,o=n.settings.mode,a=Qr(e);if((!a||-1===n.items.indexOf(a)||("single"===o&&n.close(),"single"!==o&&n.settings.duplicates))&&null!==a&&n.options.hasOwnProperty(a)&&("single"===o&&n.clear(t),"multi"!==o||!n.isFull())){if(s=n._render("item",n.options[a]),n.control.contains(s)&&(s=s.cloneNode(!0)),i=n.isFull(),n.items.splice(n.caretPos,0,a),n.insertAtCaret(s),n.isSetup){if(!n.isPending&&n.settings.hideSelected){let e=n.getOption(a),t=n.getAdjacent(e,1);t&&n.setActiveOption(t)}n.isPending||n.settings.closeAfterSelect||n.refreshOptions(n.isFocused&&"single"!==o),0!=n.settings.closeAfterSelect&&n.isFull()?n.close():n.isPending||n.positionDropdown(),n.trigger("item_add",a,s),n.isPending||n.updateOriginalInput({silent:t})}(!n.isPending||!i&&n.isFull())&&(n.inputState(),n.refreshState())}})}removeItem(e=null,t){const s=this;if(!(e=s.getItem(e)))return;var i,n;const o=e.dataset.value;i=cl(e),e.remove(),e.classList.contains("active")&&(n=s.activeItems.indexOf(e),s.activeItems.splice(n,1),nl(e,"active")),s.items.splice(i,1),s.lastQuery=null,!s.settings.persist&&s.userOptions.hasOwnProperty(o)&&s.removeOption(o,t),i<s.caretPos&&s.setCaret(s.caretPos-1),s.updateOriginalInput({silent:t}),s.refreshState(),s.positionDropdown(),s.trigger("item_remove",o,e)}createItem(e=null,t=()=>{}){3===arguments.length&&(t=arguments[2]),"function"!=typeof t&&(t=()=>{});var s,i=this,n=i.caretPos;if(e=e||i.inputValue(),!i.canCreate(e))return t(),!1;i.lock();var o=!1,a=e=>{if(i.unlock(),!e||"object"!=typeof e)return t();var s=Qr(e[i.settings.valueField]);if("string"!=typeof s)return t();i.setTextboxValue(),i.addOption(e,!0),i.setCaret(n),i.addItem(s),t(e),o=!0};return s="function"==typeof i.settings.create?i.settings.create.call(this,e,a):{[i.settings.labelField]:e,[i.settings.valueField]:e},o||a(s),!0}refreshItems(){var e=this;e.lastQuery=null,e.isSetup&&e.addItems(e.items),e.updateOriginalInput(),e.refreshState()}refreshState(){const e=this;e.refreshValidityState();const t=e.isFull(),s=e.isLocked;e.wrapper.classList.toggle("rtl",e.rtl);const i=e.wrapper.classList;var n;i.toggle("focus",e.isFocused),i.toggle("disabled",e.isDisabled),i.toggle("readonly",e.isReadOnly),i.toggle("required",e.isRequired),i.toggle("invalid",!e.isValid),i.toggle("locked",s),i.toggle("full",t),i.toggle("input-active",e.isFocused&&!e.isInputHidden),i.toggle("dropdown-active",e.isOpen),i.toggle("has-options",(n=e.options,0===Object.keys(n).length)),i.toggle("has-items",e.items.length>0)}refreshValidityState(){var e=this;e.input.validity&&(e.isValid=e.input.validity.valid,e.isInvalid=!e.isValid)}isFull(){return null!==this.settings.maxItems&&this.items.length>=this.settings.maxItems}updateOriginalInput(e={}){const t=this;var s,i;const n=t.input.querySelector('option[value=""]');if(t.is_select_tag){const o=[],a=t.input.querySelectorAll("option:checked").length;function r(e,s,i){return e||(e=Zr('<option value="'+Rr(s)+'">'+Rr(i)+"</option>")),e!=n&&t.input.append(e),o.push(e),(e!=n||a>0)&&(e.selected=!0),e}t.input.querySelectorAll("option:checked").forEach(e=>{e.selected=!1}),0==t.items.length&&"single"==t.settings.mode?r(n,"",""):t.items.forEach(e=>{s=t.options[e],i=s[t.settings.labelField]||"",o.includes(s.$option)?r(t.input.querySelector(`option[value="${Gr(e)}"]:not(:checked)`),e,i):s.$option=r(s.$option,e,i)})}else t.input.value=t.getValue();t.isSetup&&(e.silent||t.trigger("change",t.getValue()))}open(){var e=this;e.isLocked||e.isOpen||"multi"===e.settings.mode&&e.isFull()||(e.isOpen=!0,dl(e.focus_node,{"aria-expanded":"true"}),e.refreshState(),sl(e.dropdown,{visibility:"hidden",display:"block"}),e.positionDropdown(),sl(e.dropdown,{visibility:"visible",display:"block"}),e.focus(),e.trigger("dropdown_open",e.dropdown))}close(e=!0){var t=this,s=t.isOpen;e&&(t.setTextboxValue(),"single"===t.settings.mode&&t.items.length&&t.inputState()),t.isOpen=!1,dl(t.focus_node,{"aria-expanded":"false"}),sl(t.dropdown,{display:"none"}),t.settings.hideSelected&&t.clearActiveOption(),t.refreshState(),s&&t.trigger("dropdown_close",t.dropdown)}positionDropdown(){if("body"===this.settings.dropdownParent){var e=this.control,t=e.getBoundingClientRect(),s=e.offsetHeight+t.top+window.scrollY,i=t.left+window.scrollX;sl(this.dropdown,{width:t.width+"px",top:s+"px",left:i+"px"})}}clear(e){var t=this;if(t.items.length){var s=t.controlChildren();Kr(s,e=>{t.removeItem(e,!0)}),t.inputState(),e||t.updateOriginalInput(),t.trigger("clear")}}insertAtCaret(e){const t=this,s=t.caretPos,i=t.control;i.insertBefore(e,i.children[s]||null),t.setCaret(s+1)}deleteSelection(e){var t,s,i,n,o,a=this;t=e&&8===e.keyCode?-1:1,s={start:(o=a.control_input).selectionStart||0,length:(o.selectionEnd||0)-(o.selectionStart||0)};const r=[];if(a.activeItems.length)n=ll(a.activeItems,t),i=cl(n),t>0&&i++,Kr(a.activeItems,e=>r.push(e));else if((a.isFocused||"single"===a.settings.mode)&&a.items.length){const e=a.controlChildren();let i;t<0&&0===s.start&&0===s.length?i=e[a.caretPos-1]:t>0&&s.start===a.inputValue().length&&(i=e[a.caretPos]),void 0!==i&&r.push(i)}if(!a.shouldDelete(r,e))return!1;for(Vr(e,!0),void 0!==i&&a.setCaret(i);r.length;)a.removeItem(r.pop());return a.inputState(),a.positionDropdown(),a.refreshOptions(!1),!0}shouldDelete(e,t){const s=e.map(e=>e.dataset.value);return!(!s.length||"function"==typeof this.settings.onDelete&&!1===this.settings.onDelete(s,t))}advanceSelection(e,t){var s,i,n=this;n.rtl&&(e*=-1),n.inputValue().length||(Xr(hl,t)||Xr("shiftKey",t)?(i=(s=n.getLastActive(e))?s.classList.contains("active")?n.getAdjacent(s,e,"item"):s:e>0?n.control_input.nextElementSibling:n.control_input.previousElementSibling)&&(i.classList.contains("active")&&n.removeActiveItem(s),n.setActiveItemClass(i)):n.moveCaret(e))}moveCaret(e){}getLastActive(e){let t=this.control.querySelector(".last-active");if(t)return t;var s=this.control.querySelectorAll(".active");return s?ll(s,e):void 0}setCaret(e){this.caretPos=this.items.length}controlChildren(){return Array.from(this.control.querySelectorAll("[data-ts-item]"))}lock(){this.setLocked(!0)}unlock(){this.setLocked(!1)}setLocked(e=this.isReadOnly||this.isDisabled){this.isLocked=e,this.refreshState()}disable(){this.setDisabled(!0),this.close()}enable(){this.setDisabled(!1)}setDisabled(e){this.focus_node.tabIndex=e?-1:this.tabIndex,this.isDisabled=e,this.input.disabled=e,this.control_input.disabled=e,this.setLocked()}setReadOnly(e){this.isReadOnly=e,this.input.readOnly=e,this.control_input.readOnly=e,this.setLocked()}destroy(){var e=this,t=e.revertSettings;e.trigger("destroy"),e.off(),e.wrapper.remove(),e.dropdown.remove(),e.input.innerHTML=t.innerHTML,e.input.tabIndex=t.tabIndex,nl(e.input,"tomselected","ts-hidden-accessible"),e._destroy(),delete e.input.tomselect}render(e,t){var s,i;const n=this;if("function"!=typeof this.settings.render[e])return null;if(!(i=n.settings.render[e].call(this,t,Rr)))return null;if(i=Zr(i),"option"===e||"option_create"===e?t[n.settings.disabledField]?dl(i,{"aria-disabled":"true"}):dl(i,{"data-selectable":""}):"optgroup"===e&&(s=t.group[n.settings.optgroupValueField],dl(i,{"data-group":s}),t.group[n.settings.disabledField]&&dl(i,{"data-disabled":""})),"option"===e||"item"===e){const s=Nr(t[n.settings.valueField]);dl(i,{"data-value":s}),"item"===e?(il(i,n.settings.itemClass),dl(i,{"data-ts-item":""})):(il(i,n.settings.optionClass),dl(i,{role:"option",id:t.$id}),t.$div=i,n.options[s]=t)}return i}_render(e,t){const s=this.render(e,t);if(null==s)throw"HTMLElement expected";return s}clearCache(){Kr(this.options,e=>{e.$div&&(e.$div.remove(),delete e.$div)})}uncacheValue(e){const t=this.getOption(e);t&&t.remove()}canCreate(e){return this.settings.create&&e.length>0&&this.settings.createFilter.call(this,e)}hook(e,t,s){var i=this,n=i[t];i[t]=function(){var t,o;return"after"===e&&(t=n.apply(i,arguments)),o=s.apply(i,arguments),"instead"===e?o:("before"===e&&(t=n.apply(i,arguments)),t)}}}const bl=(e,t=!1)=>{e&&(e.preventDefault(),t&&e.stopPropagation())},vl=(e,t,s,i)=>{e.addEventListener(t,s,i)},yl=e=>{if(e.jquery)return e[0];if(e instanceof HTMLElement)return e;if(wl(e)){var t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}return document.querySelector(e)},wl=e=>"string"==typeof e&&e.indexOf("<")>-1,_l=(e,t,s,i)=>{e.addEventListener(t,s,i)},xl=(e,t=!1)=>{e&&(e.preventDefault(),t&&e.stopPropagation())},Sl=(e,t,s,i)=>{e.addEventListener(t,s,i)},Cl=e=>{if(e.jquery)return e[0];if(e instanceof HTMLElement)return e;if(kl(e)){var t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}return document.querySelector(e)},kl=e=>"string"==typeof e&&e.indexOf("<")>-1;fl.define("change_listener",function(){((e,t,s)=>{this.input.addEventListener("change",s,void 0)})(0,0,()=>{this.sync()})}),fl.define("checkbox_options",function(e){var t=this,s=t.onOptionSelect;t.settings.hideSelected=!1;const i=Object.assign({className:"tomselect-checkbox",checkedClassNames:void 0,uncheckedClassNames:void 0},e);var n=function(e,t){t?(e.checked=!0,i.uncheckedClassNames&&e.classList.remove(...i.uncheckedClassNames),i.checkedClassNames&&e.classList.add(...i.checkedClassNames)):(e.checked=!1,i.checkedClassNames&&e.classList.remove(...i.checkedClassNames),i.uncheckedClassNames&&e.classList.add(...i.uncheckedClassNames))},o=function(e){setTimeout(()=>{var t=e.querySelector("input."+i.className);t instanceof HTMLInputElement&&n(t,e.classList.contains("selected"))},1)};t.hook("after","setupTemplates",()=>{var e=t.settings.render.option;t.settings.render.option=(s,o)=>{var a=(e=>{if(e.jquery)return e[0];if(e instanceof HTMLElement)return e;if("string"==typeof(s=e)&&s.indexOf("<")>-1){var t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}var s;return document.querySelector(e)})(e.call(t,s,o)),r=document.createElement("input");i.className&&r.classList.add(i.className),r.addEventListener("click",function(e){bl(e)}),r.type="checkbox";const l=null==(c=s[t.settings.valueField])?null:(e=>"boolean"==typeof e?e?"1":"0":e+"")(c);var c;return n(r,!!(l&&t.items.indexOf(l)>-1)),a.prepend(r),a}}),t.on("item_remove",e=>{var s=t.getOption(e);s&&(s.classList.remove("selected"),o(s))}),t.on("item_add",e=>{var s=t.getOption(e);s&&o(s)}),t.hook("instead","onOptionSelect",(e,i)=>{if(i.classList.contains("selected"))return i.classList.remove("selected"),t.removeItem(i.dataset.value),t.refreshOptions(),void bl(e,!0);s.call(t,e,i),o(i)})}),fl.define("clear_button",function(e){const t=this,s=Object.assign({className:"clear-button",title:"Clear All",html:e=>`<div class="${e.className}" title="${e.title}">⨯</div>`},e);t.on("initialize",()=>{var e=(e=>{if(e.jquery)return e[0];if(e instanceof HTMLElement)return e;if("string"==typeof(s=e)&&s.indexOf("<")>-1){var t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}var s;return document.querySelector(e)})(s.html(s));e.addEventListener("click",e=>{t.isLocked||(t.clear(),"single"===t.settings.mode&&t.settings.allowEmptyOption&&t.addItem(""),e.preventDefault(),e.stopPropagation())}),t.control.appendChild(e)})}),fl.define("drag_drop",function(){var e=this;if("multi"!==e.settings.mode)return;var t=e.lock,s=e.unlock;let i,n=!0;e.hook("after","setupTemplates",()=>{var t=e.settings.render.item;e.settings.render.item=(s,o)=>{const a=(e=>{if(e.jquery)return e[0];if(e instanceof HTMLElement)return e;if("string"==typeof(s=e)&&s.indexOf("<")>-1){var t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}var s;return document.querySelector(e)})(t.call(e,s,o));var r;r=a,((e,t)=>{if(Array.isArray(e))e.forEach(t);else for(var s in e)e.hasOwnProperty(s)&&t(e[s],s)})({draggable:"true"},(e,t)=>{null==e?r.removeAttribute(t):r.setAttribute(t,""+e)});const l=e=>{e.preventDefault(),a.classList.add("ts-drag-over"),c(a,i)},c=(e,t)=>{var s,i,n;void 0!==t&&(((e,t)=>{do{var s;if(e==(t=null==(s=t)?void 0:s.previousElementSibling))return!0}while(t&&t.previousElementSibling);return!1})(t,a)?(i=t,null==(n=(s=e).parentNode)||n.insertBefore(i,s.nextSibling)):((e,t)=>{var s;null==(s=e.parentNode)||s.insertBefore(t,e)})(e,t))};return vl(a,"mousedown",e=>{n||((e,t=!1)=>{e&&(e.preventDefault(),t&&e.stopPropagation())})(e),e.stopPropagation()}),vl(a,"dragstart",e=>{i=a,setTimeout(()=>{a.classList.add("ts-dragging")},0)}),vl(a,"dragenter",l),vl(a,"dragover",l),vl(a,"dragleave",()=>{a.classList.remove("ts-drag-over")}),vl(a,"dragend",()=>{var t;document.querySelectorAll(".ts-drag-over").forEach(e=>e.classList.remove("ts-drag-over")),null==(t=i)||t.classList.remove("ts-dragging"),i=void 0;var s=[];e.control.querySelectorAll("[data-value]").forEach(e=>{if(e.dataset.value){let t=e.dataset.value;t&&s.push(t)}}),e.setValue(s)}),a}}),e.hook("instead","lock",()=>(n=!1,t.call(e))),e.hook("instead","unlock",()=>(n=!0,s.call(e)))}),fl.define("dropdown_header",function(e){const t=this,s=Object.assign({title:"Untitled",headerClass:"dropdown-header",titleRowClass:"dropdown-header-title",labelClass:"dropdown-header-label",closeClass:"dropdown-header-close",html:e=>'<div class="'+e.headerClass+'"><div class="'+e.titleRowClass+'"><span class="'+e.labelClass+'">'+e.title+'</span><a class="'+e.closeClass+'">×</a></div></div>'},e);t.on("initialize",()=>{var e=(e=>{if(e.jquery)return e[0];if(e instanceof HTMLElement)return e;if("string"==typeof(s=e)&&s.indexOf("<")>-1){var t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}var s;return document.querySelector(e)})(s.html(s)),i=e.querySelector("."+s.closeClass);i&&i.addEventListener("click",e=>{((e,t=!1)=>{e&&(e.preventDefault(),t&&e.stopPropagation())})(e,!0),t.close()}),t.dropdown.insertBefore(e,t.dropdown.firstChild)})}),fl.define("caret_position",function(){var e=this;e.hook("instead","setCaret",t=>{"single"!==e.settings.mode&&e.control.contains(e.control_input)?(t=Math.max(0,Math.min(e.items.length,t)))==e.caretPos||e.isPending||e.controlChildren().forEach((s,i)=>{i<t?e.control_input.insertAdjacentElement("beforebegin",s):e.control.appendChild(s)}):t=e.items.length,e.caretPos=t}),e.hook("instead","moveCaret",t=>{if(!e.isFocused)return;const s=e.getLastActive(t);if(s){const r=((e,t)=>{if(!e)return-1;t=t||e.nodeName;for(var s=0;e=e.previousElementSibling;)e.matches(t)&&s++;return s})(s);e.setCaret(t>0?r+1:r),e.setActiveItem(),n=s,i=[],((e,t)=>{if(Array.isArray(e))e.forEach(t);else for(var s in e)e.hasOwnProperty(s)&&t(e[s])})(["last-active"],e=>{"string"==typeof e&&(e=e.trim().split(/[\t\n\f\r\s]/)),Array.isArray(e)&&(i=i.concat(e))}),a=i.filter(Boolean),(o=n,Array.isArray(o)||(o=[o]),n=o).map(e=>{a.map(t=>{e.classList.remove(t)})})}else e.setCaret(e.caretPos+t);var i,n,o,a})}),fl.define("dropdown_input",function(){const e=this;e.settings.shouldOpen=!0,e.hook("before","setup",()=>{e.focus_node=e.control,((e,...t)=>{var s,i=(e=>{var t=[];return((e,t)=>{if(Array.isArray(e))e.forEach(t);else for(var s in e)e.hasOwnProperty(s)&&t(e[s])})(e,e=>{"string"==typeof e&&(e=e.trim().split(/[\t\n\f\r\s]/)),Array.isArray(e)&&(t=t.concat(e))}),t.filter(Boolean)})(t);(s=e,Array.isArray(s)||(s=[s]),e=s).map(e=>{i.map(t=>{e.classList.add(t)})})})(e.control_input,"dropdown-input");const t=yl('<div class="dropdown-input-wrap">');t.append(e.control_input),e.dropdown.insertBefore(t,e.dropdown.firstChild);const s=yl('<input class="items-placeholder" tabindex="-1" />');s.placeholder=e.settings.placeholder||"",e.control.append(s)}),e.on("initialize",()=>{e.control_input.addEventListener("keydown",t=>{switch(t.keyCode){case 27:return e.isOpen&&(((e,t=!1)=>{e&&(e.preventDefault(),t&&e.stopPropagation())})(t,!0),e.close()),void e.clearActiveItems();case 9:e.focus_node.tabIndex=-1}return e.onKeyDown.call(e,t)}),e.on("blur",()=>{e.focus_node.tabIndex=e.isDisabled?-1:e.tabIndex}),e.on("dropdown_open",()=>{e.control_input.focus()});const t=e.onBlur;e.hook("instead","onBlur",s=>{if(!s||s.relatedTarget!=e.control_input)return t.call(e)}),e.control_input.addEventListener("blur",()=>e.onBlur(),void 0),e.hook("before","close",()=>{e.isOpen&&e.focus_node.focus({preventScroll:!0})})})}),fl.define("input_autogrow",function(){var e=this;e.on("initialize",()=>{var t=document.createElement("span"),s=e.control_input;t.style.cssText="position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; ",e.wrapper.appendChild(t);for(const e of["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"])t.style[e]=s.style[e];var i=()=>{t.textContent=s.value,s.style.width=t.clientWidth+"px"};i(),e.on("update item_add item_remove",i),_l(s,"input",i),_l(s,"keyup",i),_l(s,"blur",i),_l(s,"update",i)})}),fl.define("no_backspace_delete",function(){var e=this,t=e.deleteSelection;this.hook("instead","deleteSelection",s=>!!e.activeItems.length&&t.call(e,s))}),fl.define("no_active_items",function(){this.hook("instead","setActiveItem",()=>{}),this.hook("instead","selectAll",()=>{})}),fl.define("optgroup_columns",function(){var e=this,t=e.onKeyDown;e.hook("instead","onKeyDown",s=>{var i,n,o,a;if(!e.isOpen||37!==s.keyCode&&39!==s.keyCode)return t.call(e,s);e.ignoreHover=!0,a=(e=>{for(;e&&e.matches;){if(e.matches("[data-group]"))return e;e=e.parentNode}})(e.activeOption),i=((e,t)=>{if(!e)return-1;t=t||e.nodeName;for(var s=0;e=e.previousElementSibling;)e.matches(t)&&s++;return s})(e.activeOption,"[data-selectable]"),a&&(a=37===s.keyCode?a.previousSibling:a.nextSibling)&&(n=(o=a.querySelectorAll("[data-selectable]"))[Math.min(o.length-1,i)])&&e.setActiveOption(n)})}),fl.define("remove_button",function(e){const t=Object.assign({label:"×",title:"Remove",className:"remove",append:!0},e);var s=this;if(t.append){var i='<a href="javascript:void(0)" class="'+t.className+'" tabindex="-1" title="'+(t.title+"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")+'">'+t.label+"</a>";s.hook("after","setupTemplates",()=>{var e=s.settings.render.item;s.settings.render.item=(t,n)=>{var o=Cl(e.call(s,t,n)),a=Cl(i);return o.appendChild(a),Sl(a,"mousedown",e=>{xl(e,!0)}),Sl(a,"click",e=>{s.isLocked||(xl(e,!0),s.isLocked||s.shouldDelete([o],e)&&(s.removeItem(o),s.refreshOptions(!1),s.inputState()))}),o}})}}),fl.define("restore_on_backspace",function(e){const t=this,s=Object.assign({text:e=>e[t.settings.labelField]},e);t.on("item_remove",function(e){if(t.isFocused&&""===t.control_input.value.trim()){var i=t.options[e];i&&t.setTextboxValue(s.text.call(t,i))}})}),fl.define("virtual_scroll",function(){const e=this,t=e.canLoad,s=e.clearActiveOption,i=e.loadCallback;var n,o,a={},r=!1,l=[];if(e.settings.shouldLoadMore||(e.settings.shouldLoadMore=()=>{if(n.clientHeight/(n.scrollHeight-n.scrollTop)>.9)return!0;if(e.activeOption){var t=e.selectable();if(Array.from(t).indexOf(e.activeOption)>=t.length-2)return!0}return!1}),!e.settings.firstUrl)throw"virtual_scroll plugin requires a firstUrl() method";e.settings.sortField=[{field:"$order"},{field:"$score"}];const c=t=>!("number"==typeof e.settings.maxOptions&&n.children.length>=e.settings.maxOptions||!(t in a)||!a[t]),d=(t,s)=>e.items.indexOf(s)>=0||l.indexOf(s)>=0;e.setNextUrl=(e,t)=>{a[e]=t},e.getUrl=t=>{if(t in a){const e=a[t];return a[t]=!1,e}return e.clearPagination(),e.settings.firstUrl.call(e,t)},e.clearPagination=()=>{a={}},e.hook("instead","clearActiveOption",()=>{if(!r)return s.call(e)}),e.hook("instead","canLoad",s=>s in a?c(s):t.call(e,s)),e.hook("instead","loadCallback",(t,s)=>{if(r){if(o){const s=t[0];void 0!==s&&(o.dataset.value=s[e.settings.valueField])}}else e.clearOptions(d);i.call(e,t,s),r=!1}),e.hook("after","refreshOptions",()=>{const t=e.lastValue;var s;c(t)?(s=e.render("loading_more",{query:t}))&&(s.setAttribute("data-selectable",""),o=s):t in a&&!n.querySelector(".no-results")&&(s=e.render("no_more_results",{query:t})),s&&(((e,...t)=>{var s,i=(e=>{var t=[];return((e,t)=>{if(Array.isArray(e))e.forEach(t);else for(var s in e)e.hasOwnProperty(s)&&t(e[s])})(e,e=>{"string"==typeof e&&(e=e.trim().split(/[\t\n\f\r\s]/)),Array.isArray(e)&&(t=t.concat(e))}),t.filter(Boolean)})(t);(s=e,Array.isArray(s)||(s=[s]),e=s).map(e=>{i.map(t=>{e.classList.add(t)})})})(s,e.settings.optionClass),n.append(s))}),e.on("initialize",()=>{l=Object.keys(e.options),n=e.dropdown_content,e.settings.render=Object.assign({},{loading_more:()=>'<div class="loading-more-results">Loading more results ... </div>',no_more_results:()=>'<div class="no-more-results">No more results</div>'},e.settings.render),n.addEventListener("scroll",()=>{e.settings.shouldLoadMore.call(e)&&c(e.lastValue)&&(r||(r=!0,e.load.call(e,e.lastValue)))})})});const Al=fl,El={};let Tl;"undefined"!=typeof lpDataAdmin&&(Tl=lpDataAdmin.lp_rest_url,El.admin={apiAdminNotice:Tl+"lp/v1/admin/tools/admin-notices",apiAddons:Tl+"lp/v1/addon/all",apiAddonAction:Tl+"lp/v1/addon/action-n",apiAddonsPurchase:Tl+"lp/v1/addon/info-addons-purchase",apiSearchCourses:Tl+"lp/v1/admin/tools/search-course",apiSearchUsers:Tl+"lp/v1/admin/tools/search-user",apiAssignUserCourse:Tl+"lp/v1/admin/tools/assign-user-course",apiUnAssignUserCourse:Tl+"lp/v1/admin/tools/unassign-user-course"}),"undefined"!=typeof lpData&&(Tl=lpData.lp_rest_url,El.frontend={apiWidgets:Tl+"lp/v1/widgets/api",apiCourses:Tl+"lp/v1/courses/archive-course",apiAJAX:Tl+"lp/v1/load_content_via_ajax/",apiProfileCoverImage:Tl+"lp/v1/profile/cover-image"}),Tl&&(El.apiCourses=Tl+"lp/v1/courses/",El.apiEditCoursesArchiveBlock=Tl+"lp/v1/courses/edit-archive-block",El.apiCoursesSuggest=Tl+"lp/v1/courses/courses-suggest");const Ll=El,Il={buildTomSelect(e,t,s,i,n){if(!e)return;const o={plugins:{remove_button:{title:"Remove this item"},dropdown_input:{}},onInitialize(){},onItemAdd(t){if(s){const o=Array.from(e.selectedOptions).map(e=>e.value);o.push(t),i.id_not_in=o.join(","),s("",i,n)}}};return s&&(o.load=(t,o)=>{const a=Array.from(e.selectedOptions).map(e=>e.value);i.id_not_in=a.join(","),s(t,i,Il.callBackTomSelectSearchAPI(o,n))}),(t={...o,...t}).options,new Al(e,t)},callBackTomSelectSearchAPI:(e,t)=>({success:s=>{const i=t.success(s);e(i)}}),fetchCourses(t="",s={},i){const n=Ll.admin.apiSearchCourses;s.search=t;const o={headers:{"Content-Type":"application/json","X-WP-Nonce":lpDataAdmin.nonce},method:"POST",body:JSON.stringify(s)};e.lpFetchAPI(n,o,i)},fetchUsers(t="",s={},i){const n=Ll.admin.apiSearchUsers;s.search=t;const o={headers:{"Content-Type":"application/json","X-WP-Nonce":lpDataAdmin.nonce},method:"POST",body:JSON.stringify(s)};e.lpFetchAPI(n,o,i)}},Dl=(e,t={})=>e?null!=e.tomSelectInstance?null:void(e.tomSelectInstance=Il.buildTomSelect(e,t)):null,ql=()=>{const t=document.querySelectorAll("select.lp-tom-select:not(.loaded)");t.length&&t.forEach(t=>{t.closest(".widget-liquid-left")||((t,s={},i={})=>{var n,o;if(!t)return;if(t.classList.contains("loaded"))return;t.classList.add("loaded");const a=t.dataset?.saved?JSON.parse(t.dataset.saved):0,r=t?.dataset?.struct?JSON.parse(t.dataset.struct):"";if(!r)return void Dl(t);const l=(e,t)=>{const s=t.parentElement;return s.tagName.toLowerCase()===e?s:"html"!==s.tagName.toLowerCase()&&l(e,s)},c=l("form",t);if(c){const e=c.querySelector('input[name="'+t.getAttribute("name")+'"]');e&&e.remove()}const d=null!==(n=r.dataSendApi)&&void 0!==n?n:"",u=null!==(o=r.urlApi)&&void 0!==o?o:"",h={...r.setting,...s};if(!u)return void Dl(t,h);const p=(t="",s,i)=>{const n=u,o={current_ids:a,...d,...s};o.search=t;const r={headers:{"Content-Type":"application/json","X-WP-Nonce":lpData.nonce},method:"POST",body:JSON.stringify(o)};e.lpFetchAPI(n,r,i)},m={success:e=>{((e,t,s,i,n={},o)=>{if(!(e&&t&&s&&i&&o))return;const a=e=>{if(!s.keyGetValue?.text||!s.keyGetValue.key_render)return;let t=s.keyGetValue.text;for(const[i,n]of Object.entries(s.keyGetValue.key_render))t=t.replace(new RegExp(`{{${n}}}`,"g"),e[n]);return t},r=t.dataset?.saved?JSON.parse(t.dataset.saved):0;let l=[];e.data[s.dataType].length>0&&(l=e.data[s.dataType].map(e=>({value:e[s.keyGetValue.value],text:a(e)})));const c={items:r,render:{item:(e,t)=>`<li data-id="${e.value}">\n\t\t\t\t\t\t<div class="item">${e.text}</div>\n\t\t\t\t\t</li>`},onChange:e=>{e.length<1&&(t.value="")},...n,options:l};null!=t.tomSelectInstance?t.tomSelectInstance.addOptions(l):t.tomSelectInstance=Il.buildTomSelect(t,c,i,{},o)})(e,t,r,p,h,m)}};let g=[];"object"==typeof a&&(g=Object.entries(a).map(([e,t])=>({key:e,value:t}))),d?.id_not_in&&(g=[...g,...d.id_not_in]),i.id_not_in=g.join(","),p("",i,m)})(t)})};document.addEventListener("submit",e=>{const t=e.target.closest(".cb-search-form");if(!t)return;const s=t.querySelector(".cb-search-btn");s&&(s.classList.add("loading"),s.disabled=!0)}),(()=>{try{new l,new k,document.querySelector(".lp-btn-generate-course-with-ai, .lp-btn-warning-enable-ai")&&new L({autoInsertButton:!1,isCourseBuilder:!0,redirectDelayMs:1200}),document.querySelector(".cb-course-edit-ai-btn.lp-btn-generate-with-ai")&&new $({autoInsertButtons:!1,isCourseBuilder:!0}),new F,new H,new Q,new W,new j,new V,new X,new or,new ar,new cr({isCourseBuilder:!0}),C(),(()=>{const e=document.getElementById("lp-course-builder-sidebar"),t=document.querySelector(".lp-cb-sidebar__toggle"),s=document.getElementById("lp-course-builder"),i="lp_cb_sidebar_collapsed";e&&t&&("true"===localStorage.getItem(i)&&(e.classList.add("is-collapsed"),s&&s.classList.add("has-collapsed-sidebar")),t.addEventListener("click",()=>{const t=!e.classList.contains("is-collapsed");e.classList.toggle("is-collapsed"),s&&s.classList.toggle("has-collapsed-sidebar"),localStorage.setItem(i,t?"true":"false")}))})(),(()=>{const e=document.getElementById("lp-course-builder-sidebar");e&&"true"!==e.dataset.subMenusInitialized&&(e.dataset.subMenusInitialized="true",e.addEventListener("click",t=>{const s=t.target.closest(".lp-cb-sidebar__sub-menu-toggle");if(!s||!e.contains(s))return;const i=s.closest(".lp-cb-sidebar__item.has-sub-menu");if(!i)return;t.preventDefault();const n=i.classList.toggle("is-expanded");s.setAttribute("aria-expanded",n?"true":"false")}))})(),(()=>{const t=".cb-header-action-expanded",s=".course-action-expanded",i="is-open",o=(e=null)=>{document.querySelectorAll(`${t}.${i}`).forEach(t=>{if(e&&t===e)return;t.classList.remove(i);const n=t.querySelector(s);n&&n.setAttribute("aria-expanded","false")})};document.addEventListener("click",a=>{const r=a.target,l=r.closest(s);if(l){a.preventDefault(),a.stopPropagation();const e=l.closest(t);if(!e)return;const s=!e.classList.contains(i);return o(e),e.classList.toggle(i,s),void l.setAttribute("aria-expanded",s?"true":"false")}r.closest(t)||o();const c=document.querySelectorAll(".lp-cb-item-action-expand");if(r.closest(".lp-cb-item-action-expand-toggle")){const t=r.closest(".lp-cb-item-action-wrap").querySelector(".lp-cb-item-action-expand");t.classList.toggle(e.lpClassName.hidden),c.forEach(s=>{s!==t&&s.classList.add(e.lpClassName.hidden)})}if(r.closest(".lp-cb-item-action-expand-toggle")||c.forEach(t=>{t.classList.add(e.lpClassName.hidden)}),r.closest(".lp-cb-item-action")){const t=r.closest(".lp-cb-item-action"),s=t.closest(".lp-cb-item-action-wrap").querySelector(".lp-cb-item-action-expand-toggle"),i=JSON.parse(t.dataset.send);e.lpSetLoadingEl(s,1),s.querySelector("svg");const o={success:e=>{const{message:s,status:o,data:a}=e;n.W(s,o),"success"===o&&(a.redirect_url?window.location.href=a.redirect_url:a.html?t.closest("li.course").outerHTML=a.html:"delete"===i.action_type&&t.closest("li.course").remove())},error:e=>{n.W(e,"error")},completed:()=>{e.lpSetLoadingEl(s,0)}};window.lpAJAXG.fetchAJAX(i,o)}}),document.addEventListener("keydown",e=>{"Escape"===e.key&&o()})})()}catch(e){console.error("Error initializing builder components:",e)}})(),document.addEventListener("click",e=>{try{ql()}catch(e){console.warn("Error initializing TomSelect:",e)}}),document.addEventListener("DOMContentLoaded",()=>{try{ql()}catch(e){console.warn("Error initializing TomSelect on DOMContentLoaded:",e)}try{!function(){const e=new WeakSet;document.addEventListener("click",t=>{const s=t.target.closest("ul.lp-meta-box__course-tab__tabs a");if(!s)return;const i=s.getAttribute("href");i&&i.includes("material")&&setTimeout(()=>{try{const t=document.querySelector(i+" #lp-material-container");t&&!e.has(t)&&(e.add(t),new U(t))}catch(e){console.error("Error initializing BuilderMaterial:",e)}},100)})}()}catch(e){console.error("Error initializing BuilderMaterial:",e)}}),e?.lpOnElementReady&&e.lpOnElementReady("select.lp-tom-select",()=>{try{ql()}catch(e){console.warn("Error initializing TomSelect:",e)}}),window.lpFindTomSelect=ql})()})(); |