(()=>{"use strict";var e={n:o=>{var a=o&&o.__esModule?()=>o.default:()=>o;return e.d(a,{a}),a},d:(o,a)=>{for(var l in a)e.o(a,l)&&!e.o(o,l)&&Object.defineProperty(o,l,{enumerable:!0,get:a[l]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o)};const o=window.wp.blocks,a=window.wp.blockEditor,l=window.wp.serverSideRender;var t=e.n(l);const n=window.wp.components,s=window.wp.element,r=window.wp.apiFetch;var c=e.n(r);const d=window.ReactJSXRuntime;function i({value:e,onChange:o,label:a}){const[l,t]=(0,s.useState)([]),[r,i]=(0,s.useState)(!1);function u(e){i(!0);const o=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";c()({path:o}).then(e=>{t(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>t([])).finally(()=>i(!1))}return(0,s.useEffect)(()=>{u("")},[]),(0,s.useEffect)(()=>{e&&!l.find(o=>o.value===e)&&c()({path:`/ggmc/v1/products/${e}`}).then(e=>{t(o=>o.find(o=>o.value===e.id)?o:[{value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name},...o])}).catch(()=>{})},[e]),(0,d.jsx)(n.ComboboxControl,{label:a||"Product",value:e,options:l,onChange:o,onFilterValueChange:e=>u(e),__nextHasNoMarginBottom:!0})}const u=JSON.parse('{"UU":"ggmc/product-barcode"}');(0,o.registerBlockType)(u.UU,{edit:({attributes:e,setAttributes:o})=>(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(a.InspectorControls,{children:(0,d.jsxs)(n.PanelBody,{title:"Content",children:[(0,d.jsx)(i,{value:e.productId,onChange:e=>o({productId:e})}),(0,d.jsx)(n.SelectControl,{label:"Display",value:e.barcode_display,options:[{label:"Primary Barcode Only",value:"primary"},{label:"All Barcodes",value:"all"}],onChange:e=>o({barcode_display:e})}),(0,d.jsx)(n.ToggleControl,{label:"Show Barcode Type",checked:"yes"===e.show_barcode_type,onChange:e=>o({show_barcode_type:e?"yes":""})}),(0,d.jsx)(n.ToggleControl,{label:"Show Barcode Image",checked:"yes"===e.show_barcode_image,onChange:e=>o({show_barcode_image:e?"yes":""})}),(0,d.jsx)(n.SelectControl,{label:"Layout",value:e.layout,options:[{label:"Inline",value:"inline"},{label:"Stacked",value:"stacked"},{label:"Table",value:"table"}],onChange:e=>o({layout:e})}),(0,d.jsx)(n.TextControl,{label:"Label Text",value:e.label_text,onChange:e=>o({label_text:e})}),(0,d.jsx)(n.ToggleControl,{label:"Hide if No Barcode",checked:"yes"===e.hide_if_empty,onChange:e=>o({hide_if_empty:e?"yes":""})})]})}),(0,d.jsx)(t(),{block:u.UU,attributes:e})]}),save:()=>null})})();