(()=>{"use strict";var e={n:t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var l in o)e.o(o,l)&&!e.o(t,l)&&Object.defineProperty(t,l,{enumerable:!0,get:o[l]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,o=window.wp.blockEditor,l=window.wp.serverSideRender;var a=e.n(l);const n=window.wp.components,s=window.wp.element,c=window.wp.apiFetch;var r=e.n(c);const i=window.ReactJSXRuntime;function u({value:e,onChange:t,label:o}){const[l,a]=(0,s.useState)([]),[c,u]=(0,s.useState)(!1);function d(e){u(!0);const t=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";r()({path:t}).then(e=>{a(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>a([])).finally(()=>u(!1))}return(0,s.useEffect)(()=>{d("")},[]),(0,s.useEffect)(()=>{e&&!l.find(t=>t.value===e)&&r()({path:`/ggmc/v1/products/${e}`}).then(e=>{a(t=>t.find(t=>t.value===e.id)?t:[{value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name},...t])}).catch(()=>{})},[e]),(0,i.jsx)(n.ComboboxControl,{label:o||"Product",value:e,options:l,onChange:t,onFilterValueChange:e=>d(e),__nextHasNoMarginBottom:!0})}const d=JSON.parse('{"UU":"ggmc/variation-selector"}');(0,t.registerBlockType)(d.UU,{edit:({attributes:e,setAttributes:t})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(o.InspectorControls,{children:[(0,i.jsxs)(n.PanelBody,{title:"Content",children:[(0,i.jsx)(u,{value:e.productId,onChange:e=>t({productId:e})}),(0,i.jsx)(n.ToggleControl,{label:"Show Attribute Labels",checked:"yes"===e.showAttributeLabel,onChange:e=>t({showAttributeLabel:e?"yes":""})}),(0,i.jsx)(n.ToggleControl,{label:"Show Selected Value",checked:"yes"===e.showSelectedValue,onChange:e=>t({showSelectedValue:e?"yes":""})}),(0,i.jsx)(n.ToggleControl,{label:"Hide Out of Stock",checked:"yes"===e.hideOutOfStock,onChange:e=>t({hideOutOfStock:e?"yes":""})}),(0,i.jsx)(n.ToggleControl,{label:"Show Price Change",checked:"yes"===e.showPriceChange,onChange:e=>t({showPriceChange:e?"yes":""})}),(0,i.jsx)(n.TextControl,{label:"Clear Selection Text",value:e.clearSelectionText,onChange:e=>t({clearSelectionText:e})})]}),(0,i.jsxs)(n.PanelBody,{title:"Display Settings",initialOpen:!1,children:[(0,i.jsx)(n.SelectControl,{label:"Default Display Type",value:e.defaultDisplayType,options:[{label:"Auto (from attribute type)",value:"auto"},{label:"Dropdown",value:"select"},{label:"Buttons",value:"buttons"},{label:"Swatches (color/image)",value:"swatches"}],onChange:e=>t({defaultDisplayType:e})}),(0,i.jsx)(n.SelectControl,{label:"Button Layout",value:e.buttonLayout,options:[{label:"Inline",value:"inline"},{label:"Grid",value:"grid"}],onChange:e=>t({buttonLayout:e})})]})]}),(0,i.jsx)(a(),{block:d.UU,attributes:e})]}),save:()=>null})})();