(()=>{"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 a in o)e.o(o,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:o[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,o=window.wp.blockEditor,a=window.wp.serverSideRender;var r=e.n(a);const n=window.wp.components,l=window.wp.element,c=window.wp.apiFetch;var u=e.n(c);const s=window.ReactJSXRuntime;function i({value:e,onChange:t,label:o}){const[a,r]=(0,l.useState)([]),[c,i]=(0,l.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=>{r(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>r([])).finally(()=>i(!1))}return(0,l.useEffect)(()=>{d("")},[]),(0,l.useEffect)(()=>{e&&!a.find(t=>t.value===e)&&u()({path:`/ggmc/v1/products/${e}`}).then(e=>{r(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:a,onChange:t,onFilterValueChange:e=>d(e),__nextHasNoMarginBottom:!0})}const d=JSON.parse('{"UU":"ggmc/product-price"}');(0,t.registerBlockType)(d.UU,{edit:({attributes:e,setAttributes:t})=>(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(o.InspectorControls,{children:(0,s.jsxs)(n.PanelBody,{title:"Content",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)(i,{value:e.productId,onChange:e=>t({productId:e})}),(0,s.jsx)(n.SelectControl,{label:"Variable Product Price Format",value:e.variablePriceFormat,options:[{label:"From $X (lowest price)",value:"from"},{label:"$X - $Y (full range)",value:"range"}],onChange:e=>t({variablePriceFormat:e})}),"from"===e.variablePriceFormat&&(0,s.jsx)(n.TextControl,{label:"From Label Text",value:e.fromLabelText,onChange:e=>t({fromLabelText:e})}),"range"===e.variablePriceFormat&&(0,s.jsx)(n.TextControl,{label:"Range Separator",value:e.rangeSeparator,onChange:e=>t({rangeSeparator:e})})]})}),(0,s.jsx)(r(),{block:d.UU,attributes:e})]}),save:()=>null})})();