(()=>{"use strict";var e={n:t=>{var l=t&&t.__esModule?()=>t.default:()=>t;return e.d(l,{a:l}),l},d:(t,l)=>{for(var a in l)e.o(l,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:l[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,l=window.wp.blockEditor,a=window.wp.serverSideRender;var o=e.n(a);const n=window.wp.components,s=window.wp.element,r=window.wp.apiFetch;var u=e.n(r);const c=window.ReactJSXRuntime;function i({value:e,onChange:t,label:l}){const[a,o]=(0,s.useState)([]),[r,i]=(0,s.useState)(!1);function d(e){i(!0);const t=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";u()({path:t}).then(e=>{o(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>o([])).finally(()=>i(!1))}return(0,s.useEffect)(()=>{d("")},[]),(0,s.useEffect)(()=>{e&&!a.find(t=>t.value===e)&&u()({path:`/ggmc/v1/products/${e}`}).then(e=>{o(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,c.jsx)(n.ComboboxControl,{label:l||"Product",value:e,options:a,onChange:t,onFilterValueChange:e=>d(e),__nextHasNoMarginBottom:!0})}const d=JSON.parse('{"UU":"ggmc/product-categories"}');(0,t.registerBlockType)(d.UU,{edit:({attributes:e,setAttributes:t})=>(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(l.InspectorControls,{children:(0,c.jsxs)(n.PanelBody,{title:"Content",children:[(0,c.jsx)(n.SelectControl,{label:"Product Source",value:e.productSource,options:[{label:"Current Product (Auto-detect)",value:"current"},{label:"Select Product",value:"custom"}],onChange:e=>t({productSource:e})}),"custom"===e.productSource&&(0,c.jsx)(i,{value:e.productId,onChange:e=>t({productId:e})}),(0,c.jsx)(n.SelectControl,{label:"Display Layout",value:e.displayLayout,options:[{label:"Inline (Horizontal)",value:"inline"},{label:"List (Vertical)",value:"list"},{label:"Badges/Pills",value:"badges"}],onChange:e=>t({displayLayout:e})}),(0,c.jsx)(n.ToggleControl,{label:"Show Label",checked:"yes"===e.showLabel,onChange:e=>t({showLabel:e?"yes":""})}),"yes"===e.showLabel&&(0,c.jsx)(n.TextControl,{label:"Label Text",value:e.labelText,onChange:e=>t({labelText:e})}),"inline"===e.displayLayout&&(0,c.jsx)(n.TextControl,{label:"Separator",value:e.separator,onChange:e=>t({separator:e})}),"inline"!==e.displayLayout&&(0,c.jsx)(n.ToggleControl,{label:"Show Category Image",checked:"yes"===e.showImage,onChange:e=>t({showImage:e?"yes":""})}),(0,c.jsx)(n.SelectControl,{label:"Alignment",value:e.alignment,options:[{label:"Default",value:""},{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],onChange:e=>t({alignment:e})})]})}),(0,c.jsx)(o(),{block:d.UU,attributes:e})]}),save:()=>null})})();