(function(){"use strict";const{__:r}=wp.i18n,{registerBlockType:f}=wp.blocks,{SelectControl:l,Icon:h,PanelBody:d}=wp.components,{InspectorControls:u}=wp.blockEditor||wp.editor,{useEffect:p,useState:m}=wp.element,g=()=>React.createElement(h,{icon:React.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 163 163"},React.createElement("defs",null),React.createElement("path",{fill:"#13233c",d:"M106 0H57A57 57 0 000 57v49a57 57 0 0057 57h49a57 57 0 0057-57V57a57 57 0 00-57-57zM51 60v3l-1 59v12c0 5-3 8-8 6-2-1-3-4-3-6v-21-55a29 29 0 011-4 5 5 0 015-4h33a4 4 0 004-2c2-3 8-2 10-1a9 9 0 015 9 9 9 0 01-7 8c-3 1-6 0-9-3a3 3 0 00-1-1H51zm73 74c-6 5-12 6-20 6H72a8 8 0 01-4-1 5 5 0 01-2-6 5 5 0 015-3h35c11-1 20-10 21-20 0-11-8-20-18-23a6 6 0 00-1 0H78h-1v14l1 2h18a4 4 0 003-1c4-4 8-3 11-1 4 2 5 7 3 12-2 4-9 6-13 2a6 6 0 00-5-1H71c-3 0-5-2-5-6V82c0-4 1-5 5-6h17a21 21 0 0021-24c-1-9-8-16-16-18a25 25 0 00-6 0H46c-4 0-7-3-7-6s3-5 7-5h42a33 33 0 0132 23c2 11 0 20-6 29l-1 2 5 2c11 4 17 12 19 23 3 12-2 24-13 32z"}))}),v=async t=>{const e=new URL(bitformsBlock.ajaxUrl);e.searchParams.append("action","bitforms_get_form_html"),e.searchParams.append("_ajax_nonce",bitformsBlock.nonce),e.searchParams.append("formID",t);try{const o=await(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({formID:t})})).json();return o.success?o.data:(console.error("Error fetching form HTML:",o.data),null)}catch(c){return console.error("Error:",c),null}};f("bitforms/form-shortcode",{title:r("Bit Form - Contact Form Builder Plugin for WordPress"),icon:g,category:"widgets",keywords:["Form","Contact Form","Bitform"],attributes:{formID:{type:"Integer",default:0},formName:{type:"string",default:""}},example:{attributes:{formName:r("Contact Form"),preview:!0}},edit:t=>{const{attributes:e,setAttributes:c,className:o}=t,[w,E]=m(""),[b,y]=m(""),s=[{value:0,label:r("Select a Form"),disabled:!0}];bitformsBlock.forms.forEach(a=>{s.push({label:`${a.id}. ${a.form_name}`,value:a.id})}),p(()=>{(async()=>{if(e.formID>0){const n=await v(e.formID);n&&(E(n.html),y(n.css),c({html:n.html,css:n.css}))}})()},[e.formID]);const i=a=>{c({formID:a})},R={padding:10,textAlign:"center"};return[React.createElement("div",{style:R,className:o},e.formID>0?React.createElement(React.Fragment,null,React.createElement("style",{dangerouslySetInnerHTML:{__html:b}}),React.createElement("div",{dangerouslySetInnerHTML:{__html:w}})):React.createElement(React.Fragment,null,React.createElement("svg",{height:"50",width:"50",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 163 163"},React.createElement("defs",null),React.createElement("path",{fill:"#13233c",d:"M106 0H57A57 57 0 000 57v49a57 57 0 0057 57h49a57 57 0 0057-57V57a57 57 0 00-57-57zM51 60v3l-1 59v12c0 5-3 8-8 6-2-1-3-4-3-6v-21-55a29 29 0 011-4 5 5 0 015-4h33a4 4 0 004-2c2-3 8-2 10-1a9 9 0 015 9 9 9 0 01-7 8c-3 1-6 0-9-3a3 3 0 00-1-1H51zm73 74c-6 5-12 6-20 6H72a8 8 0 01-4-1 5 5 0 01-2-6 5 5 0 015-3h35c11-1 20-10 21-20 0-11-8-20-18-23a6 6 0 00-1 0H78h-1v14l1 2h18a4 4 0 003-1c4-4 8-3 11-1 4 2 5 7 3 12-2 4-9 6-13 2a6 6 0 00-5-1H71c-3 0-5-2-5-6V82c0-4 1-5 5-6h17a21 21 0 0021-24c-1-9-8-16-16-18a25 25 0 00-6 0H46c-4 0-7-3-7-6s3-5 7-5h42a33 33 0 0132 23c2 11 0 20-6 29l-1 2 5 2c11 4 17 12 19 23 3 12-2 24-13 32z"})),React.createElement("h3",{style:{fontFamily:"sans-serif",margin:"0.65em 0"}},"Bit Form"),React.createElement(l,{value:e.formID,options:s,onChange:i}))),React.createElement(u,{key:r("Bitform block settings")},React.createElement(d,{title:r("Form settings")},React.createElement(l,{value:e.formID,options:s,onChange:i})))]},save:t=>`[bitform id='${parseInt(t.attributes.formID,10)}']`})})();
