(()=>{"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 n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,o=window.wp.blockEditor,n=window.wp.serverSideRender;var l=e.n(n);const a=window.wp.components,r=window.wp.element,c=window.wp.apiFetch;var s=e.n(c);const u=window.ReactJSXRuntime;function d({value:e,onChange:t,label:o}){const[n,l]=(0,r.useState)([]),[c,d]=(0,r.useState)(!1);function i(e){d(!0);const t=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";s()({path:t}).then(e=>{l(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>l([])).finally(()=>d(!1))}return(0,r.useEffect)(()=>{i("")},[]),(0,r.useEffect)(()=>{e&&!n.find(t=>t.value===e)&&s()({path:`/ggmc/v1/products/${e}`}).then(e=>{l(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,u.jsx)(a.ComboboxControl,{label:o||"Product",value:e,options:n,onChange:t,onFilterValueChange:e=>i(e),__nextHasNoMarginBottom:!0})}const i=JSON.parse('{"UU":"ggmc/product-stock"}');(0,t.registerBlockType)(i.UU,{edit:({attributes:e,setAttributes:t})=>(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(o.InspectorControls,{children:(0,u.jsxs)(a.PanelBody,{title:"Content",children:[(0,u.jsx)(a.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,u.jsx)(d,{value:e.productId,onChange:e=>t({productId:e})}),(0,u.jsx)(a.SelectControl,{label:"Display Format",value:e.displayFormat,options:[{label:"Number Only (25)",value:"number_only"},{label:"Text + Number (In Stock: 25)",value:"text_number"},{label:"Status Only (In Stock)",value:"status_only"}],onChange:e=>t({displayFormat:e})}),"number_only"!==e.displayFormat&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(a.TextControl,{label:"In Stock Text",value:e.inStockText,onChange:e=>t({inStockText:e})}),(0,u.jsx)(a.TextControl,{label:"Low Stock Text",value:e.lowStockText,onChange:e=>t({lowStockText:e})})]}),(0,u.jsx)(a.TextControl,{label:"Out of Stock Text",value:e.outOfStockText,onChange:e=>t({outOfStockText:e})}),(0,u.jsx)(a.TextControl,{label:"Low Stock Threshold",type:"number",value:e.lowStockThreshold,onChange:e=>t({lowStockThreshold:parseInt(e,10)||1})}),(0,u.jsx)(a.ToggleControl,{label:"Show Status Icon",checked:"yes"===e.showIcon,onChange:e=>t({showIcon:e?"yes":""})})]})}),(0,u.jsx)(l(),{block:i.UU,attributes:e})]}),save:()=>null})})();