(function(){
(function(){var N;if(!window.wp||!window.wp.blocks)return;const{registerBlockType:w}=window.wp.blocks,{__:t}=window.wp.i18n||(l=>l),a=window.wp.components||{},s=window.wp.element||{},p=window.wp.apiFetch,u=window.wp.blockEditor||window.wp.editor||{},b=u.useBlockProps,h=u.InspectorControls,k=a.SelectControl,n=a.Notice,v=a.Spinner,g=a.PanelBody,y=a.Disabled,F=window.wp.serverSideRender,L=s.Fragment||"div",e=s.createElement||((N=window.React)==null?void 0:N.createElement),i=s.useState,E=s.useEffect;if(!w||!p||!k||!n||!v||!e||!i||!E||!b)return;const S="formatrica/form";w(S,{title:t("Formatrica","formatrica"),description:t("Embed a form created with Formatrica.","formatrica"),icon:"feedback",category:"widgets",keywords:[t("form","formatrica"),t("contact","formatrica"),t("easy","formatrica")],supports:{align:["wide","full"]},attributes:{formId:{type:"number",default:0}},edit({attributes:l,setAttributes:R}){const{formId:m}=l,[C,B]=i([]),[_,f]=i(!0),[P,I]=i(null);E(()=>{f(!0),I(null),p({path:"/formatrica/v1/forms"}).then(o=>{o&&Array.isArray(o.forms)?B(o.forms.map(A=>({value:Number(A.id),label:A.title||t("Untitled form","formatrica")}))):B([]),f(!1)}).catch(o=>{console.warn("Failed to fetch forms:",o),I(o.message||t("Failed to load forms","formatrica")),f(!1)})},[]);const M=[{value:0,label:t("Select a form…","formatrica")},...C],O=b({className:"formatrica-block-editor"}),c=e(k,{label:t("Form","formatrica"),value:m||0,options:M,onChange:o=>R({formId:Number(o)})}),D=h&&g,T=F&&y;let r;_?r=e("div",{className:"formatrica-block-empty"},e(v),e("p",null,t("Loading forms…","formatrica"))):P?r=e(n,{status:"error",isDismissible:!1},P):C.length?m?T?r=e("div",{className:"formatrica-block-preview"},D?null:c,e(y,null,e(F,{block:S,attributes:{formId:m},httpMethod:"GET"}))):r=e("div",{className:"formatrica-block-empty"},c):r=e("div",{className:"formatrica-block-empty"},c):r=e(n,{status:"info",isDismissible:!1},t("Create a form with Formatrica to embed it here.","formatrica"));const d=[];return D&&d.push(e(h,{key:"inspector"},e(g,{title:t("Form settings","formatrica"),initialOpen:!0},c))),d.push(e("div",O,r)),e(L,null,...d)},save(){return null}})})();

})();