/*! For license information please see plugin.js.LICENSE.txt */
tinymce.PluginManager.add("phpmyfaq",function(e,t){"use strict";return e.ui.registry.addButton("phpmyfaq",{text:"phpMyFAQ",onAction:()=>{var t;t=document.getElementById("pmf-csrf-token").value,e.windowManager.open({title:"phpMyFAQ TinyMCE Plugin",body:{type:"panel",items:[{type:"input",name:"search",label:"Search",id:"pmf-internal-links"},{type:"htmlpanel",html:'<div id="pmf-faq-list" class="p-1"></div>'}]},buttons:[{type:"cancel",text:"Close"},{type:"submit",text:"Save",primary:!0}],onChange:e=>{const n=e.getData(),a=location.protocol+"//"+location.host+location.pathname,o=document.getElementById("pmf-faq-list");n.search.length>0&&fetch(a+"api/faq/search",{method:"POST",headers:{Accept:"application/json, text/plain, */*","Content-Type":"application/json"},body:JSON.stringify({search:n.search,csrf:t})}).then(async e=>{if(e.ok)return e.json();throw new Error("Network response was not ok: ",{cause:{response:e}})}).then(e=>{if(e.success){o.innerHTML="";const t=e.success;t.length>0&&t.forEach(e=>{o.innerHTML+=`<label> <input type="radio" name="faqURL" value="${e.url}">${e.question}</label><br>`})}else console.error(e.error)}).catch(async e=>{const t=await e.cause.response.json();console.error(t)})},onSubmit:t=>{const n=document.querySelector("input[name=faqURL]:checked"),a=`<a class="pmf-internal-link" href="${n.value}">${n.parentNode.textContent}</a>`;e.insertContent(a),t.close()}})}}),{getMetadata:function(){return{name:"phpMyFAQ TinyMCE plugin",url:"https://www.phpmyfaq.de/documentation"}}}});
//# sourceMappingURL=plugin.js.map