(()=>{"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 l in t)e.o(t,l)&&!e.o(o,l)&&Object.defineProperty(o,l,{enumerable:!0,get:t[l]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o)};const o=window.wp.blocks,t=window.wp.blockEditor,l=window.wp.serverSideRender;var n=e.n(l);const a=window.wp.components,s=window.wp.element,u=window.wp.apiFetch;var r=e.n(u);const i=window.ReactJSXRuntime;function c({value:e,onChange:o,label:t}){const[l,n]=(0,s.useState)([]),[u,c]=(0,s.useState)(!1);function d(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,s.useEffect)(()=>{d("")},[]),(0,s.useEffect)(()=>{e&&!l.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,i.jsx)(a.ComboboxControl,{label:t||"Product",value:e,options:l,onChange:o,onFilterValueChange:e=>d(e),__nextHasNoMarginBottom:!0})}const d=JSON.parse('{"UU":"ggmc/custom-attributes"}');(0,o.registerBlockType)(d.UU,{edit:({attributes:e,setAttributes:o})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.InspectorControls,{children:(0,i.jsxs)(a.PanelBody,{title:"Content",children:[(0,i.jsx)(c,{value:e.productId,onChange:e=>o({productId:e})}),(0,i.jsx)(a.TextControl,{label:"Title",value:e.title,onChange:e=>o({title:e})}),(0,i.jsx)(a.SelectControl,{label:"Layout",value:e.layout,options:[{label:"Table",value:"table"},{label:"List",value:"list"},{label:"Grid",value:"grid"},{label:"Inline",value:"inline"}],onChange:e=>o({layout:e})}),"grid"===e.layout&&(0,i.jsx)(a.SelectControl,{label:"Columns",value:e.columns,options:[{label:"1",value:"1"},{label:"2",value:"2"},{label:"3",value:"3"},{label:"4",value:"4"}],onChange:e=>o({columns:e})}),(0,i.jsx)(a.ToggleControl,{label:"Show Units",checked:"yes"===e.show_units,onChange:e=>o({show_units:e?"yes":""})}),(0,i.jsx)(a.ToggleControl,{label:"Show Empty Attributes",checked:"yes"===e.show_empty,onChange:e=>o({show_empty:e?"yes":""})}),(0,i.jsx)(a.ToggleControl,{label:"Show Icons",checked:"yes"===e.show_icons,onChange:e=>o({show_icons:e?"yes":""})}),(0,i.jsx)(a.ToggleControl,{label:"Group by Attribute Group",checked:"yes"===e.group_by_group,onChange:e=>o({group_by_group:e?"yes":""})}),(0,i.jsx)(a.ToggleControl,{label:"Hide if No Attributes",checked:"yes"===e.hide_if_empty,onChange:e=>o({hide_if_empty:e?"yes":""})})]})}),(0,i.jsx)(n(),{block:d.UU,attributes:e})]}),save:()=>null})})();