(()=>{"use strict";var e={n:o=>{var t=o&&o.__esModule?()=>o.default:()=>o;return e.d(t,{a:t}),t},d:(o,t)=>{for(var s in t)e.o(t,s)&&!e.o(o,s)&&Object.defineProperty(o,s,{enumerable:!0,get:t[s]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o)};const o=window.wp.blocks,t=window.wp.blockEditor,s=window.wp.serverSideRender;var n=e.n(s);const l=window.wp.components,a=window.wp.element,i=window.wp.apiFetch;var r=e.n(i);const u=window.ReactJSXRuntime;function c({value:e,onChange:o,label:t}){const[s,n]=(0,a.useState)([]),[i,c]=(0,a.useState)(!1);function h(e){c(!0);const o=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";r()({path:o}).then(e=>{n(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>n([])).finally(()=>c(!1))}return(0,a.useEffect)(()=>{h("")},[]),(0,a.useEffect)(()=>{e&&!s.find(o=>o.value===e)&&r()({path:`/ggmc/v1/products/${e}`}).then(e=>{n(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,u.jsx)(l.ComboboxControl,{label:t||"Product",value:e,options:s,onChange:o,onFilterValueChange:e=>h(e),__nextHasNoMarginBottom:!0})}const h=JSON.parse('{"UU":"ggmc/product-attributes"}');(0,o.registerBlockType)(h.UU,{edit:({attributes:e,setAttributes:o})=>(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(t.InspectorControls,{children:(0,u.jsxs)(l.PanelBody,{title:"Content",children:[(0,u.jsx)(l.SelectControl,{label:"Product Source",value:e.productSource,options:[{label:"Current Product (Auto-detect)",value:"current"},{label:"Select Product",value:"custom"}],onChange:e=>o({productSource:e})}),"custom"===e.productSource&&(0,u.jsx)(c,{value:e.productId,onChange:e=>o({productId:e})}),(0,u.jsx)(l.SelectControl,{label:"Layout",value:e.layout,options:[{label:"Table",value:"table"},{label:"Vertical List",value:"list"},{label:"Inline",value:"inline"},{label:"Grid (2 columns)",value:"grid"}],onChange:e=>o({layout:e})}),(0,u.jsx)(l.ToggleControl,{label:"Show Weight",checked:"yes"===e.showWeight,onChange:e=>o({showWeight:e?"yes":""})}),(0,u.jsx)(l.ToggleControl,{label:"Show Dimensions",checked:"yes"===e.showDimensions,onChange:e=>o({showDimensions:e?"yes":""})}),"yes"===e.showDimensions&&(0,u.jsx)(l.SelectControl,{label:"Dimensions Format",value:e.dimensionsFormat,options:[{label:"Combined (L x W x H)",value:"combined"},{label:"Separate rows/items",value:"separate"}],onChange:e=>o({dimensionsFormat:e})}),(0,u.jsx)(l.ToggleControl,{label:"Show Labels",checked:"yes"===e.showLabels,onChange:e=>o({showLabels:e?"yes":""})}),"yes"===e.showLabels&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(l.TextControl,{label:"Weight Label",value:e.weightLabel,onChange:e=>o({weightLabel:e})}),"combined"===e.dimensionsFormat&&(0,u.jsx)(l.TextControl,{label:"Dimensions Label",value:e.dimensionsLabel,onChange:e=>o({dimensionsLabel:e})})]}),(0,u.jsx)(l.ToggleControl,{label:"Show Units",checked:"yes"===e.showUnits,onChange:e=>o({showUnits:e?"yes":""})}),(0,u.jsx)(l.ToggleControl,{label:"Hide if Empty",checked:"yes"===e.hideEmpty,onChange:e=>o({hideEmpty:e?"yes":""})}),(0,u.jsx)(l.ToggleControl,{label:"Show Custom Attributes",checked:"yes"===e.showCustomAttributes,onChange:e=>o({showCustomAttributes:e?"yes":""})}),"yes"===e.showCustomAttributes&&(0,u.jsx)(l.SelectControl,{label:"Custom Attributes Position",value:e.customAttributesPosition,options:[{label:"Before Weight/Dimensions",value:"before"},{label:"After Weight/Dimensions",value:"after"}],onChange:e=>o({customAttributesPosition:e})})]})}),(0,u.jsx)(n(),{block:h.UU,attributes:e})]}),save:()=>null})})();