(()=>{"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,r=window.wp.element,i=window.wp.apiFetch;var u=e.n(i);const s=window.ReactJSXRuntime;function c({value:e,onChange:t,label:o}){const[l,a]=(0,r.useState)([]),[i,c]=(0,r.useState)(!1);function d(e){c(!0);const t=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";u()({path:t}).then(e=>{a(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>a([])).finally(()=>c(!1))}return(0,r.useEffect)(()=>{d("")},[]),(0,r.useEffect)(()=>{e&&!l.find(t=>t.value===e)&&u()({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,s.jsx)(n.ComboboxControl,{label:o||"Product",value:e,options:l,onChange:t,onFilterValueChange:e=>d(e),__nextHasNoMarginBottom:!0})}const d=JSON.parse('{"UU":"ggmc/add-to-cart"}');(0,t.registerBlockType)(d.UU,{edit:({attributes:e,setAttributes:t})=>(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(o.InspectorControls,{children:[(0,s.jsxs)(n.PanelBody,{title:"Cart Settings",children:[(0,s.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,s.jsx)(c,{value:e.productId,onChange:e=>t({productId:e})}),(0,s.jsx)(n.TextControl,{label:"Button Text",value:e.buttonText,onChange:e=>t({buttonText:e})}),(0,s.jsx)(n.SelectControl,{label:"Layout",value:e.layout,options:[{label:"Horizontal",value:"horizontal"},{label:"Vertical",value:"vertical"}],onChange:e=>t({layout:e})})]}),(0,s.jsxs)(n.PanelBody,{title:"Variable Products",initialOpen:!1,children:[(0,s.jsx)(n.TextControl,{label:"Variable Product Button Text",value:e.variableButtonText,onChange:e=>t({variableButtonText:e})}),(0,s.jsx)(n.SelectControl,{label:"Variable Product Behavior",value:e.variableProductBehavior,options:[{label:"Link to Product Page",value:"link_to_product"},{label:"Disabled (wait for selection)",value:"disabled"},{label:"Show Variation Selector",value:"show_selector"}],onChange:e=>t({variableProductBehavior:e})})]}),(0,s.jsxs)(n.PanelBody,{title:"Quantity",initialOpen:!1,children:[(0,s.jsx)(n.ToggleControl,{label:"Show Quantity Selector",checked:"yes"===e.showQuantity,onChange:e=>t({showQuantity:e?"yes":""})}),"yes"===e.showQuantity&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.TextControl,{label:"Quantity Label",value:e.quantityLabel,onChange:e=>t({quantityLabel:e})}),(0,s.jsx)(n.SelectControl,{label:"Quantity Controls Style",value:e.quantityControlsStyle,options:[{label:"Input Controls & Buttons",value:"both"},{label:"Input Controls Only",value:"input_only"}],onChange:e=>t({quantityControlsStyle:e})})]})]}),(0,s.jsxs)(n.PanelBody,{title:"Price Display",initialOpen:!1,children:[(0,s.jsx)(n.ToggleControl,{label:"Show Price",checked:"yes"===e.showPrice,onChange:e=>t({showPrice:e?"yes":"no"})}),"yes"===e.showPrice&&(0,s.jsx)(n.TextControl,{label:"Variable Price Prefix",value:e.pricePrefixText,onChange:e=>t({pricePrefixText:e})})]})]}),(0,s.jsx)(a(),{block:d.UU,attributes:e})]}),save:()=>null})})();