(()=>{"use strict";var e,r={471(e,r,t){const n=window.wp.blocks,o=JSON.parse('{"UU":"madeit/forms"}'),l=window.wp.element,a=window.wp.components,i=window.wp.blockEditor,s=window.wp.apiFetch;var m=t.n(s);const c=window.wp.serverSideRender;var d=t.n(c);(0,n.registerBlockType)(o.UU,{edit:function({attributes:e,setAttributes:r}){const{formId:t}=e,[n,o]=(0,l.useState)([]),[s,c]=(0,l.useState)(!0),[u,p]=(0,l.useState)(null),[f,w]=(0,l.useState)(!1),v=(0,i.useBlockProps)({}),b=[];return(0,l.useEffect)(()=>{let e=!0;return m()({path:"/madeit/v1/forms"}).then(r=>{e&&(o(Array.isArray(r)?r:[]),p(null))}).catch(r=>{e&&(o([]),p(r))}).finally(()=>{e&&c(!1)}),()=>{e=!1}},[]),s?(0,l.createElement)(a.Spinner,null):t?(t&&b.push((0,l.createElement)(l.Fragment,null,(0,l.createElement)(a.ToolbarButton,{key:"edit",icon:"edit",label:"Bewerk formulier",text:"Formulier bewerken",onClick:()=>w(!0)}),(0,l.createElement)(a.ToolbarButton,{key:"new",icon:"plus",label:"Ander formulier selecteren",text:"Ander formulier selecteren",onClick:()=>r({formId:null})}))),(0,l.createElement)("div",v,(0,l.createElement)(i.BlockControls,null,b),(0,l.createElement)("div",{className:"madeit-form-preview-wrapper"},!f&&(0,l.createElement)(d(),{block:"madeit/forms",attributes:{formId:t}}),f&&(0,l.createElement)(a.Modal,{className:"formsModalMadeit",title:"Formulier bewerken",onRequestClose:()=>w(!1)},(0,l.createElement)("iframe",{src:`/wp-admin/post.php?post=${t}&action=edit`,style:{width:"100%"}}))))):(0,l.createElement)("div",v,(0,l.createElement)(a.Placeholder,{label:"Made I.T. Form"},u&&(0,l.createElement)("p",{style:{marginTop:0}},"Kon formulieren niet ophalen. Controleer of je bent ingelogd en of de plugin API bereikbaar is."),(0,l.createElement)(a.SelectControl,{label:"Selecteer formulier",value:t,options:[{label:"Kies een formulier",value:0},...n.map(e=>({label:e.name,value:e.id}))],onChange:e=>r({formId:parseInt(e,10)})}),(0,l.createElement)(a.Button,{variant:"primary",onClick:()=>{m()({path:"/madeit/v1/forms",method:"POST"}).then(e=>{if(!e||!e.id)throw new Error;r({formId:e.id}),w(!0)}).catch(()=>{alert("Er is een fout opgetreden bij het aanmaken van het formulier.")})}},"Nieuw formulier"),f&&(0,l.createElement)(a.Modal,{className:"formsModalMadeit",title:"Formulier bewerken",onRequestClose:()=>w(!1)},(0,l.createElement)("iframe",{src:`/wp-admin/post.php?post=${t}&action=edit`,style:{width:"100%"}}))))},save:function(){return null}})}},t={};function n(e){var o=t[e];if(void 0!==o)return o.exports;var l=t[e]={exports:{}};return r[e](l,l.exports,n),l.exports}n.m=r,e=[],n.O=(r,t,o,l)=>{if(!t){var a=1/0;for(c=0;c<e.length;c++){for(var[t,o,l]=e[c],i=!0,s=0;s<t.length;s++)(!1&l||a>=l)&&Object.keys(n.O).every(e=>n.O[e](t[s]))?t.splice(s--,1):(i=!1,l<a&&(a=l));if(i){e.splice(c--,1);var m=o();void 0!==m&&(r=m)}}return r}l=l||0;for(var c=e.length;c>0&&e[c-1][2]>l;c--)e[c]=e[c-1];e[c]=[t,o,l]},n.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return n.d(r,{a:r}),r},n.d=(e,r)=>{for(var t in r)n.o(r,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},n.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={57:0,350:0};n.O.j=r=>0===e[r];var r=(r,t)=>{var o,l,[a,i,s]=t,m=0;if(a.some(r=>0!==e[r])){for(o in i)n.o(i,o)&&(n.m[o]=i[o]);if(s)var c=s(n)}for(r&&r(t);m<a.length;m++)l=a[m],n.o(e,l)&&e[l]&&e[l][0](),e[l]=0;return n.O(c)},t=globalThis.webpackChunkmadeit_forms=globalThis.webpackChunkmadeit_forms||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))})();var o=n.O(void 0,[350],()=>n(471));o=n.O(o)})();