File: /home/h340499/public_html/wp-content/plugins/learnpress/assets/js/admin/edit-question.min.js
import*as lpUtils from"lpAssetsJsPath/utils.js";import*as lpToastify from"lpAssetsJsPath/lpToastify";import SweetAlert from"sweetalert2";import Sortable from"sortablejs";const idUrlHandle="edit-question";let fibSelection,timeoutAutoUpdateAnswer,timeoutAutoUpdateFib,timeoutAutoUpdateQuestion;export class EditQuestion{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(){if(EditQuestion._loadedEvents)return;EditQuestion._loadedEvents=!0;document.querySelectorAll(`${EditQuestion.selectors.elQuestionEditMain}`).forEach(e=>{this.sortAbleQuestionAnswer(e)}),lpUtils.eventHandlers("click",[{selector:EditQuestion.selectors.elBtnQuestionCreateType,callBack:this.createQuestionType.name,class:this},{selector:EditQuestion.selectors.elBtnAddAnswer,callBack:this.addQuestionAnswer.name,class:this},{selector:EditQuestion.selectors.elBtnDeleteAnswer,callBack:this.deleteQuestionAnswer.name,class:this},{selector:EditQuestion.selectors.elBtnFibInsertBlank,callBack:this.fibInsertBlank.name,class:this},{selector:EditQuestion.selectors.elBtnFibDeleteAllBlanks,callBack:this.fibDeleteAllBlanks.name,class:this},{selector:EditQuestion.selectors.elBtnFibSaveContent,callBack:this.fibSaveContent.name,class:this},{selector:EditQuestion.selectors.elBtnFibClearAllContent,callBack:this.fibClearContent.name,class:this},{selector:EditQuestion.selectors.elBtnFibOptionDelete,callBack:this.fibDeleteBlank.name,class:this},{selector:EditQuestion.selectors.elFibOptionMatchCaseInput,callBack:this.fibShowHideMatchCaseOption.name,class:this},{selector:EditQuestion.selectors.elFibOptionComparisonInput,callBack:e=>{const{e:t,target:s}=e;s.closest(`${EditQuestion.selectors.elQuestionEditMain}`).querySelector(`${EditQuestion.selectors.elBtnFibSaveContent}`).click()}}]),document.addEventListener("click",e=>{const t=e.target;lpUtils.toggleCollapse(e,t,EditQuestion.selectors.elTriggerToggle)}),lpUtils.eventHandlers("keyup",[{selector:EditQuestion.selectors.elQuestionAnswerTitleNewInput,callBack:this.checkCanAddAnswer.name,class:this},{selector:EditQuestion.selectors.elFibOptionTitleInput,callBack:this.fibOptionTitleInputChange.name,class:this},{selector:EditQuestion.selectors.elAutoSaveQuestion,callBack:this.autoUpdateQuestion.name,class:this}]),lpUtils.eventHandlers("keydown",[{selector:EditQuestion.selectors.elQuestionAnswerTitleNewInput,callBack:this.addQuestionAnswer.name,class:this,checkIsEventEnter:!0}]),lpUtils.eventHandlers("change",[{selector:EditQuestion.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){window.tinymce.execCommand("mceRemoveEditor",!0,e),window.tinymce.execCommand("mceAddEditor",!0,e)}eventEditorTinymce(){window.tinymce.on("AddEditor",e=>{const t=e.editor.id,s=window.tinymce.get(t);if(!s)return;if("content"===t)return;const n=document.querySelector(`#wp-${t}-wrap`);n&&(n.classList.add("tmce-active"),n.classList.remove("html-active"));const i=document.getElementById(t);i.closest(`${EditQuestion.selectors.elQuestionEditMain}`).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=>{i.value=s.getContent(),this.autoUpdateQuestion({e:e,target:i})}),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.${EditQuestion.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(),n=s.dom.select(`.${EditQuestion.selectors.elQuestionFibInput}[data-id="${t}"]`);n[0]&&n[0].focus(),s.dom.bind(n[0],"input",e=>{})}),s.on("selectionchange",e=>{if(fibSelection=s.selection,fibSelection.getNode().classList.contains(`${EditQuestion.selectors.elQuestionFibInput}`)){const e=fibSelection.getNode().dataset.id,n=fibSelection.getNode().textContent.trim();if(0===n.length){const t=s.id.replace(`${EditQuestion.selectors.elQuestionFibInput}-`,""),n=document.querySelector(`${EditQuestion.selectors.elQuestionEditMain}[data-question-id="${t}"]`).querySelector(`${EditQuestion.selectors.elFibBlankOptions}`).querySelector(`${EditQuestion.selectors.elFibBlankOptionItem}[data-id="${e}"]`);n&&lpUtils.lpShowHideEl(n,0)}else{const s=document.getElementById(t).closest(`${EditQuestion.selectors.elAnswersConfig}`).querySelector(`${EditQuestion.selectors.elFibBlankOptionItem}[data-id="${e}"]`);if(s){const e=s.querySelector(`${EditQuestion.selectors.elFibOptionTitleInput}`);e&&(e.value=n)}}}}),s.on("Undo",e=>{s.getContent();const t=s.selection.getNode();if(t.classList.contains(`${EditQuestion.selectors.elQuestionFibInput}`)){const e=t.dataset.id,s=document.querySelector(`${EditQuestion.selectors.elFibBlankOptionItem}[data-id="${e}"]`);s&&lpUtils.lpShowHideEl(s,1)}}),s.on("Redo",e=>{})})}autoUpdateQuestion(e){let{e:t,target:s,key:n,value:i}=e;const o=s.closest(`${EditQuestion.selectors.elAutoSaveQuestion}`);if(!o)return;const l=o.closest(`${EditQuestion.selectors.elQuestionEditMain}`).dataset.questionId;clearTimeout(timeoutAutoUpdateQuestion),timeoutAutoUpdateQuestion=setTimeout(()=>{const e={success:e=>{const{message:t,status:s}=e;if("success"!==s)throw`Error: ${t}`;lpToastify.show(t,s)},error:e=>{lpToastify.show(e,"error")},completed:()=>{}},t={action:"update_question",question_id:l,args:{id_url:idUrlHandle}};if(void 0===n){if(n=o.dataset.keyAutoSave,!n){if(!o.classList.contains("lp-editor-tinymce"))return;const e=o.id;if(n=e.replace(/lp-/g,"").replace(`-${l}`,"").replace(/-/g,"_"),!n)return}i=o.value}t[n]=i,window.lpAJAXG.fetchAJAX(t,e)},700)}createQuestionType(e){const{e:t,target:s}=e,n=s.closest(`${EditQuestion.selectors.elBtnQuestionCreateType}`);if(!n)return;const i=n.closest(`${EditQuestion.selectors.elQuestionEditMain}`);if(!i)return;const o=i.dataset.questionId,l=i.querySelector(`${EditQuestion.selectors.elQuestionTypeNew}`);if(!l)return;const r=l.value.trim();if(!r){const e=l.dataset.messEmptyType;return void lpToastify.show(e,"error")}const a={success:e=>{const{message:t,status:s,data:n}=e;if("success"!==s)throw`Error: ${t}`;{const{html_option_answers:e}=n;i.querySelector(`${EditQuestion.selectors.elAnswersConfig}`).outerHTML=e,this.initTinyMCE(),this.sortAbleQuestionAnswer(i),lpToastify.show(t,s)}},error:e=>{lpToastify.show(e,"error")},completed:()=>{}},c={action:"update_question",question_id:o,question_type:r,args:{id_url:idUrlHandle}};window.lpAJAXG.fetchAJAX(c,a)}addQuestionAnswer(e){const{e:t,target:s}=e,n=s.closest(`${EditQuestion.selectors.elQuestionAnswerItemAddNew}`);if(!n)return;t.preventDefault();const i=n.querySelector(`${EditQuestion.selectors.elQuestionAnswerTitleNewInput}`);if(!i.value.trim()){const e=i.dataset.messEmptyTitle;return void lpToastify.show(e,"error")}const o=s.closest(`${EditQuestion.selectors.elQuestionEditMain}`),l=o.querySelector(`${EditQuestion.selectors.elQuestionAnswerItem}.clone`),r=l.cloneNode(!0),a=r.querySelector(`${EditQuestion.selectors.elQuestionAnswerTitleInput}`);r.classList.remove("clone"),lpUtils.lpShowHideEl(r,1),lpUtils.lpSetLoadingEl(r,1),l.insertAdjacentElement("beforebegin",r);const c=i.value.trim();a.value=c,i.value="";const u={success:e=>{const{message:t,status:s,data:n}=e;if("success"!==s)throw`Error: ${t}`;{const{question_answer:e}=n;r.dataset.answerId=e.question_answer_id,lpUtils.lpSetLoadingEl(r,0);const t=this.getDataAnswersConfig(o);t.push(e),this.setDataAnswersConfig(o,t)}lpToastify.show(t,s)},error:e=>{r.remove(),lpToastify.show(e,"error")},completed:()=>{this.checkCanAddAnswer(null,i)}},d={action:"add_question_answer",question_id:o.dataset.questionId,answer_title:c,args:{id_url:idUrlHandle}};window.lpAJAXG.fetchAJAX(d,u)}checkCanAddAnswer(e){const{e:t,target:s}=e,n=s.closest(EditQuestion.selectors.elQuestionAnswerTitleNewInput);if(!n)return;const i=n.closest(`${EditQuestion.selectors.elQuestionAnswerItemAddNew}`);if(!i)return;const o=i.querySelector(`${EditQuestion.selectors.elBtnAddAnswer}`);if(!o)return;n.value.trim()?o.classList.add("active"):o.classList.remove("active")}autoUpdateAnswer(e){const{e:t,target:s}=e,n=s.closest(`${EditQuestion.selectors.elAutoSaveAnswer}`);if(!n)return;const i=n.closest(`${EditQuestion.selectors.elQuestionAnswerItem}`);clearTimeout(timeoutAutoUpdateAnswer),timeoutAutoUpdateAnswer=setTimeout(()=>{const e=n.closest(`${EditQuestion.selectors.elQuestionEditMain}`),t=e.dataset.questionId,s=this.getDataAnswersConfig(e),o=e.querySelector(`${EditQuestion.selectors.elAnswersConfig}`),l=structuredClone(s),r=o.querySelectorAll(`${EditQuestion.selectors.elQuestionAnswerItem}:not(.clone)`),a={};r.forEach((e,t)=>{a[e.dataset.answerId]=t+1}),s.map((t,s)=>{const n=e.querySelector(`${EditQuestion.selectors.elQuestionAnswerItem}[data-answer-id="${t.question_answer_id}"]`),i=n.querySelector(`${EditQuestion.selectors.elInputAnswerSetTrue}`),o=n.querySelector(`${EditQuestion.selectors.elQuestionAnswerTitleInput}`);return o&&(t.title=o.value.trim()),i&&(i.checked?t.is_true="yes":t.is_true=""),a[t.question_answer_id]&&(t.order=a[t.question_answer_id]),t}),lpUtils.lpSetLoadingEl(i,1);const c={success:e=>{const{message:t,status:s}=e;if("success"!==s)throw`Error: ${t}`;lpToastify.show(t,s)},error:t=>{l.forEach(t=>{const s=e.querySelector(`${EditQuestion.selectors.elQuestionAnswerItem}[data-answer-id="${t.question_answer_id}"]`).querySelector(`${EditQuestion.selectors.elInputAnswerSetTrue}`);return"yes"===t.is_true&&(s.checked=!0),t}),lpToastify.show(t,"error")},completed:()=>{lpUtils.lpSetLoadingEl(i,0)}},u={action:"update_question_answers_config",question_id:t,answers:s,args:{id_url:idUrlHandle}};window.lpAJAXG.fetchAJAX(u,c)},700)}sortAbleQuestionAnswer(e){let t,s=0;e.querySelectorAll(`${EditQuestion.selectors.elAnswersConfig}`).forEach(e=>{new Sortable(e,{handle:".drag",animation:150,onEnd:e=>{const n=e.item;s&&(clearTimeout(t),t=setTimeout(()=>{const e=n.querySelector(`${EditQuestion.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,n=s.closest(`${EditQuestion.selectors.elBtnDeleteAnswer}`);if(!n)return;const i=n.closest(`${EditQuestion.selectors.elQuestionAnswerItem}`);if(!i)return;const o=n.closest(`${EditQuestion.selectors.elQuestionEditMain}`),l=o.dataset.questionId,r=i.dataset.answerId;l&&r&&SweetAlert.fire({title:n.dataset.title||"Are you sure?",text:n.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){lpUtils.lpSetLoadingEl(i,1);const e={success:e=>{const{message:t,status:s}=e;if(lpToastify.show(t,s),"success"===s){const e=parseInt(i.dataset.answerId);i.remove();const t=this.getDataAnswersConfig(o);if(t){const s=t.filter(t=>parseInt(t.question_answer_id)!==e);this.setDataAnswersConfig(o,s)}}},error:e=>{lpToastify.show(e,"error")},completed:()=>{lpUtils.lpSetLoadingEl(i,0)}},t={action:"delete_question_answer",question_id:l,question_answer_id:r,args:{id_url:idUrlHandle}};window.lpAJAXG.fetchAJAX(t,e)}})}getDataAnswersConfig(e){const t=e.querySelector(`${EditQuestion.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(`${EditQuestion.selectors.elAnswersConfig}`);s&&(t&&"object"==typeof t||(t={}),s.dataset.answers=JSON.stringify(t))}fibInsertBlank=e=>{const{e:t,target:s}=e,n=s.closest(EditQuestion.selectors.elBtnFibInsertBlank);if(!n)return;const i=n.dataset.defaultText,o=n.closest(EditQuestion.selectors.elQuestionEditMain),l=o.dataset.questionId,r=n.dataset.messInserted,a=n.dataset.messRequireSelectText,c=`${EditQuestion.selectors.elQuestionFibInput}-${l}`,u=this.randomString();let d;if(!fibSelection)return void lpToastify.show(a,"error");{const e=fibSelection.getNode();if(!e)return void lpToastify.show("Event insert blank has error, please try again","error");if(!e.closest(`body[data-id="${c}"]`))return void lpToastify.show(a,"error");if(e.classList.contains(`${EditQuestion.selectors.elQuestionFibInput}`))return void lpToastify.show(r,"error");d=fibSelection.getContent(),0===d.length&&(d=i);const t=`<span class="${EditQuestion.selectors.elQuestionFibInput}" data-id="${u}">${d}</span>`;fibSelection.setContent(t)}const p=this.getDataAnswersConfig(o);p.meta_data=p.meta_data||{},0===Object.keys(p.meta_data).length&&(p.meta_data={}),p.meta_data[u]={id:u,match_case:0,comparison:"equal",fill:d,index:1,open:!1},this.setDataAnswersConfig(o,p);const w=o.querySelector(`${EditQuestion.selectors.elFibBlankOptions}`),Q=o.querySelector(`${EditQuestion.selectors.elFibBlankOptionItemClone}`),m=Q.cloneNode(!0),E=w.querySelectorAll(`${EditQuestion.selectors.elFibBlankOptionItem}:not(.clone)`).length,f=m.querySelector(`${EditQuestion.selectors.elFibBlankOptionIndex}`),b=m.querySelector(`${EditQuestion.selectors.elFibOptionTitleInput}`),h=m.querySelector(`${EditQuestion.selectors.elFibOptionMatchCaseInput}`),g=m.querySelectorAll(`${EditQuestion.selectors.elFibOptionComparisonInput}`);m.dataset.id=u,b.name=`${EditQuestion.selectors.elFibOptionTitleInput}-${u}`,b.value=this.decodeHtml(d),f.textContent=E+1+".",h.name=`${EditQuestion.selectors.elFibOptionMatchCaseInput}-${u}`.replace(/\./g,""),g.forEach(e=>{e.name=`${EditQuestion.selectors.elFibOptionComparisonInput}-${u}`.replace(/\./g,""),"equal"===e.value&&(e.checked=!0)}),Q.insertAdjacentElement("beforebegin",m),m.classList.remove("clone"),lpUtils.lpShowHideEl(m,1);const A=o.querySelector(`${EditQuestion.selectors.elBtnFibSaveContent}`);lpUtils.lpSetLoadingEl(n,1),this.fibSaveContent({e:null,target:A,callBackCompleted:()=>{lpUtils.lpSetLoadingEl(n,0)}})};fibDeleteAllBlanks(e){const{e:t,target:s}=e,n=s.closest(`${EditQuestion.selectors.elBtnFibDeleteAllBlanks}`);if(!n)return;const i=n.closest(`${EditQuestion.selectors.elQuestionEditMain}`);if(!i)return;const o=i.dataset.questionId,l=this.getDataAnswersConfig(i);SweetAlert.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(`${EditQuestion.selectors.elQuestionFibInput}-${o}`);e.dom.select(`.${EditQuestion.selectors.elQuestionFibInput}`).forEach(t=>{e.dom.remove(t,!0)}),l.meta_data={},this.setDataAnswersConfig(i,l);i.querySelector(`${EditQuestion.selectors.elFibBlankOptions}`).querySelectorAll(`${EditQuestion.selectors.elFibBlankOptionItem}:not(.clone)`).forEach(e=>{e.remove()});const t=i.querySelector(`${EditQuestion.selectors.elBtnFibSaveContent}`);lpUtils.lpSetLoadingEl(n,1),this.fibSaveContent({e:null,target:t,callBackCompleted:()=>{lpUtils.lpSetLoadingEl(n,0)}})}})}fibClearContent(e){const{e:t,target:s}=e,n=s.closest(`${EditQuestion.selectors.elBtnFibClearAllContent}`);if(!n)return;const i=n.closest(`${EditQuestion.selectors.elQuestionEditMain}`);if(!i)return;const o=i.dataset.questionId,l=this.getDataAnswersConfig(i);SweetAlert.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-${o}`).setContent(""),l.meta_data={},this.setDataAnswersConfig(i,l);i.querySelector(`${EditQuestion.selectors.elFibBlankOptions}`).querySelectorAll(`${EditQuestion.selectors.elFibBlankOptionItem}:not(.clone)`).forEach(e=>{e.remove()});const e=i.querySelector(`${EditQuestion.selectors.elBtnFibSaveContent}`);lpUtils.lpSetLoadingEl(n,1),this.fibSaveContent({e:null,target:e,callBackCompleted:()=>{lpUtils.lpSetLoadingEl(n,0)}})}})}fibDeleteBlank(e){const{e:t,target:s}=e,n=s.closest(`${EditQuestion.selectors.elBtnFibOptionDelete}`);if(!n)return;const i=n.closest(`${EditQuestion.selectors.elQuestionEditMain}`);if(!i)return;const o=i.dataset.questionId,l=(i.querySelector(`${EditQuestion.selectors.elAnswersConfig}`),this.getDataAnswersConfig(i)),r=n.closest(`${EditQuestion.selectors.elFibBlankOptionItem}`),a=r.dataset.id;SweetAlert.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(`${EditQuestion.selectors.elQuestionFibInput}-${o}`),t=e.dom.select(`.${EditQuestion.selectors.elQuestionFibInput}[data-id="${a}"]`);t[0]&&e.dom.remove(t[0],!0),r.remove(),l.meta_data=l.meta_data||{},l.meta_data[a]&&delete l.meta_data[a],this.setDataAnswersConfig(i,l);const s=i.querySelector(`${EditQuestion.selectors.elBtnFibSaveContent}`);lpUtils.lpSetLoadingEl(r,1),this.fibSaveContent({e:null,target:s,callBackCompleted:()=>{lpUtils.lpSetLoadingEl(r,0)}})}})}fibOptionTitleInputChange(e){const{e:t,target:s}=e,n=s.closest(`${EditQuestion.selectors.elFibOptionTitleInput}`);if(!n)return;const i=n.closest(`${EditQuestion.selectors.elFibBlankOptionItem}`);if(!i)return;const o=n.closest(`${EditQuestion.selectors.elQuestionEditMain}`);if(!o)return;const l=n.value.trim(),r=i.dataset.id,a=o.dataset.questionId,c=window.tinymce.get(`lp-question-fib-input-${a}`).dom.select(`.lp-question-fib-input[data-id="${r}"]`);c[0]&&(c[0].textContent=l),clearTimeout(timeoutAutoUpdateFib),timeoutAutoUpdateFib=setTimeout(()=>{const e=o.querySelector(`${EditQuestion.selectors.elBtnFibSaveContent}`);this.fibSaveContent({e:null,target:e})},700)}fibSaveContent(e){const{e:t,target:s,callBackCompleted:n=null}=e,i=s.closest(`${EditQuestion.selectors.elBtnFibSaveContent}`);if(!i)return;const o=i.closest(`${EditQuestion.selectors.elQuestionEditMain}`),l=o.dataset.questionId,r=this.getDataAnswersConfig(o);if(!r)return;const a=window.tinymce.get(`${EditQuestion.selectors.elQuestionFibInput}-${l}`);r.title=a.getContent();const c=o.querySelectorAll(`${EditQuestion.selectors.elFibBlankOptionItem}:not(.clone)`);c&&c.forEach(e=>{const t=e.dataset.id,s=e.querySelector(`${EditQuestion.selectors.elFibOptionMatchCaseInput}`),n=e.querySelector(`${EditQuestion.selectors.elFibOptionComparisonInput}:checked`);r.meta_data[t].match_case=s.checked?1:0,r.meta_data[t].comparison=n.value}),n||lpUtils.lpSetLoadingEl(i,1);const u={success:e=>{const{message:t,status:s}=e;if("success"!==s)throw`Error: ${t}`;this.setDataAnswersConfig(o,r),lpToastify.show(t,s)},error:e=>{lpToastify.show(e,"error")},completed:()=>{n&&"function"==typeof n?n():lpUtils.lpSetLoadingEl(i,0)}},d={action:"update_question_answers_config",question_id:l,answers:r,args:{id_url:idUrlHandle}};window.lpAJAXG.fetchAJAX(d,u)}fibShowHideMatchCaseOption(e){const{e:t,target:s}=e,n=s.closest(`${EditQuestion.selectors.elFibOptionMatchCaseInput}`);if(!n)return;const i=n.closest(`${EditQuestion.selectors.elQuestionFibOptionDetail}`),o=i.querySelector(`${EditQuestion.selectors.elFibOptionMatchCaseWrap}`);if(!i||!o)return;n.checked?lpUtils.lpShowHideEl(o,1):lpUtils.lpShowHideEl(o,0);n.closest(`${EditQuestion.selectors.elQuestionEditMain}`).querySelector(`${EditQuestion.selectors.elBtnFibSaveContent}`).click()}randomString(e=10){const t="abcdefghijklmnopqrstuvwxyz0123456789";let s="";for(let n=0;n<e;n++)s+=t.charAt(Math.floor(36*Math.random()));return s}decodeHtml(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}}const editQuestion=new EditQuestion;lpUtils.lpOnElementReady(EditQuestion.selectors.elEditQuestionWrap,e=>{const t=EditQuestion.selectors.elQuestionEditMain.replace(".","");e.classList.contains(t)&&editQuestion.init()});