!function(e){const t={init(){const t=e("#dokan_product_qa_save_answer"),a=e("#dokan_product_qa_edit_answer"),o=e("#dokan_product_qa_cancel_save_answer"),n=e("#dokan_product_qa_delete_answer"),s=e(".dokan-product-qa-delete-question");t&&t.on("click",this.saveAnswer),a&&a.on("click",this.openEdit),o&&o.on("click",this.cancelEdit),n&&n.on("click",this.deleteAnswer),s&&s.on("click",this.deleteQuestion),e(window).on("load",this.setTinyMCEHtmlEditorActive)},saveAnswer(a){a.preventDefault(),t.setTinyMCEHtmlEditorActive();const o=e(a.target),n=o.data("question"),s=o.data("security"),i={question_id:n,answer:tinyMCE.activeEditor.getContent(),_nonce:s,action:"dokan_product_qa_answer_question"},r=o.parent().parent();r.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),e.post(dokan.ajaxurl,i,(e=>{!0===e.success?dokan_sweetalert(e.data,{position:"bottom-end",toast:!0,icon:"success",showConfirmButton:!1,timer:2e3,timerProgressBar:!0,didOpen:e=>{setTimeout((()=>{r.unblock(),window.location.reload()}),2e3)}}):(dokan_sweetalert("",{icon:"error",html:e.data}),r.unblock())}))},openEdit(a){a.preventDefault();const o=e(".dokan-product-qa-answer-display"),n=e("#dokan-product-qa-answer-text-area");o.slideUp("fast",(()=>{n.slideDown("fast"),t.setTinyMCEHtmlEditorActive()}))},cancelEdit(t){t.preventDefault();const a=e(".dokan-product-qa-answer-display");e("#dokan-product-qa-answer-text-area").slideUp("fast",(()=>{a.slideDown("fast")}))},async deleteAnswer(t){t.preventDefault();const a=e(t.target),o=a.data("question"),n=a.data("security"),s=a.data("message"),i={question_id:o,_nonce:n,action:"dokan_product_qa_delete_question_answer"},r=a.parent().parent().parent().parent();r.block({message:null,overlayCSS:{background:"#fff",opacity:.6}});const c=await dokan_sweetalert(s,{action:"confirm",icon:"warning"});"undefined"!==c&&c.isConfirmed&&(r.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),e.post(dokan.ajaxurl,i,(e=>{!0===e.success?dokan_sweetalert(e.data,{position:"bottom-end",toast:!0,icon:"success",showConfirmButton:!1,timer:2e3,timerProgressBar:!0,didOpen:e=>{setTimeout((()=>{r.unblock(),window.location.reload()}),2e3)}}):(dokan_sweetalert("",{icon:"error",html:e.data}),r.unblock())}))),r.unblock()},async deleteQuestion(t){t.preventDefault();const a=e(t.target),o=a.data("question"),n=a.data("security"),s=a.data("message"),i=a.data("redirect"),r={question_id:o,_nonce:n,action:"dokan_product_qa_delete_question"},c=a.parent().parent();c.block({message:null,overlayCSS:{background:"#fff",opacity:.6}});const d=await dokan_sweetalert(s,{action:"confirm",icon:"warning"});"undefined"!==d&&d.isConfirmed&&(c.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),e.post(dokan.ajaxurl,r,(e=>{!0===e.success?dokan_sweetalert(e.data,{position:"bottom-end",toast:!0,icon:"success",showConfirmButton:!1,timer:2e3,timerProgressBar:!0,didOpen:e=>{setTimeout((()=>{c.unblock(),window.location.replace(i)}),2e3)}}):(dokan_sweetalert("",{icon:"error",html:e.data}),c.unblock())}))),c.unblock()},setTinyMCEHtmlEditorActive(){e("#dokan-product-qa-answer-tmce").trigger("click")}};t.init()}(jQuery);