(()=>{"use strict";var e={n:l=>{var a=l&&l.__esModule?()=>l.default:()=>l;return e.d(a,{a}),a},d:(l,a)=>{for(var t in a)e.o(a,t)&&!e.o(l,t)&&Object.defineProperty(l,t,{enumerable:!0,get:a[t]})},o:(e,l)=>Object.prototype.hasOwnProperty.call(e,l)};const l=window.wp.blocks,a=window.wp.blockEditor,t=window.wp.serverSideRender;var n=e.n(t);const o=window.wp.components,s=window.wp.element,i=window.wp.apiFetch;var r=e.n(i);const u=window.ReactJSXRuntime;function c({value:e,onChange:l,label:a}){const[t,n]=(0,s.useState)([]),[i,c]=(0,s.useState)(!1);function b(e){c(!0);const l=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";r()({path:l}).then(e=>{n(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>n([])).finally(()=>c(!1))}return(0,s.useEffect)(()=>{b("")},[]),(0,s.useEffect)(()=>{e&&!t.find(l=>l.value===e)&&r()({path:`/ggmc/v1/products/${e}`}).then(e=>{n(l=>l.find(l=>l.value===e.id)?l:[{value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name},...l])}).catch(()=>{})},[e]),(0,u.jsx)(o.ComboboxControl,{label:a||"Product",value:e,options:t,onChange:l,onFilterValueChange:e=>b(e),__nextHasNoMarginBottom:!0})}const b=JSON.parse('{"UU":"ggmc/review-form"}');(0,l.registerBlockType)(b.UU,{edit:({attributes:e,setAttributes:l})=>(0,u.jsxs)(u.Fragment,{children:[(0,u.jsxs)(a.InspectorControls,{children:[(0,u.jsxs)(o.PanelBody,{title:"Form Settings",children:[(0,u.jsx)(c,{value:e.productId,onChange:e=>l({productId:e})}),(0,u.jsx)(o.TextControl,{label:"Form Title",value:e.formTitle,onChange:e=>l({formTitle:e})}),(0,u.jsx)(o.SelectControl,{label:"Title HTML Tag",value:e.titleHtmlTag,options:[{label:"H1",value:"h1"},{label:"H2",value:"h2"},{label:"H3",value:"h3"},{label:"H4",value:"h4"},{label:"H5",value:"h5"},{label:"H6",value:"h6"},{label:"div",value:"div"},{label:"span",value:"span"},{label:"p",value:"p"}],onChange:e=>l({titleHtmlTag:e})}),(0,u.jsx)(o.ToggleControl,{label:"Show Review Title Field",checked:"yes"===e.showTitleField,onChange:e=>l({showTitleField:e?"yes":""})}),(0,u.jsx)(o.ToggleControl,{label:"Require Login",checked:"yes"===e.requireLogin,onChange:e=>l({requireLogin:e?"yes":""})}),"yes"===e.requireLogin&&(0,u.jsx)(o.TextareaControl,{label:"Login Required Message",value:e.loginMessage,onChange:e=>l({loginMessage:e})}),(0,u.jsx)(o.TextareaControl,{label:"Success Message",value:e.successMessage,onChange:e=>l({successMessage:e})}),(0,u.jsx)(o.TextControl,{label:"Submit Button Text",value:e.submitButtonText,onChange:e=>l({submitButtonText:e})})]}),(0,u.jsxs)(o.PanelBody,{title:"Field Labels",initialOpen:!1,children:[(0,u.jsx)(o.TextControl,{label:"Rating Label",value:e.ratingLabel,onChange:e=>l({ratingLabel:e})}),"yes"===e.showTitleField&&(0,u.jsx)(o.TextControl,{label:"Title Label",value:e.titleLabel,onChange:e=>l({titleLabel:e})}),(0,u.jsx)(o.TextControl,{label:"Review Content Label",value:e.contentLabel,onChange:e=>l({contentLabel:e})}),(0,u.jsx)(o.TextControl,{label:"Name Label",value:e.nameLabel,onChange:e=>l({nameLabel:e})}),(0,u.jsx)(o.TextControl,{label:"Email Label",value:e.emailLabel,onChange:e=>l({emailLabel:e})})]})]}),(0,u.jsx)(n(),{block:b.UU,attributes:e})]}),save:()=>null})})();