(()=>{"use strict";var e={n:o=>{var n=o&&o.__esModule?()=>o.default:()=>o;return e.d(n,{a:n}),n},d:(o,n)=>{for(var t in n)e.o(n,t)&&!e.o(o,t)&&Object.defineProperty(o,t,{enumerable:!0,get:n[t]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o)};const o=window.wp.blocks,n=window.wp.blockEditor,t=window.wp.serverSideRender;var a=e.n(t);const s=window.wp.components,r=window.wp.element,l=window.wp.apiFetch;var c=e.n(l);const i=window.ReactJSXRuntime;function u({value:e,onChange:o,label:n}){const[t,a]=(0,r.useState)([]),[l,u]=(0,r.useState)(!1);function d(e){u(!0);const o=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";c()({path:o}).then(e=>{a(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>a([])).finally(()=>u(!1))}return(0,r.useEffect)(()=>{d("")},[]),(0,r.useEffect)(()=>{e&&!t.find(o=>o.value===e)&&c()({path:`/ggmc/v1/products/${e}`}).then(e=>{a(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)(s.ComboboxControl,{label:n||"Product",value:e,options:t,onChange:o,onFilterValueChange:e=>d(e),__nextHasNoMarginBottom:!0})}const d=JSON.parse('{"UU":"ggmc/compare-icon"}');(0,o.registerBlockType)(d.UU,{edit:({attributes:e,setAttributes:o})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.InspectorControls,{children:(0,i.jsxs)(s.PanelBody,{title:"Content",children:[(0,i.jsx)(u,{value:e.productId,onChange:e=>o({productId:e})}),(0,i.jsx)(s.ToggleControl,{label:"Show Count",checked:"yes"===e.showCount,onChange:e=>o({showCount:e?"yes":""})}),(0,i.jsx)(s.ToggleControl,{label:"Link to Comparison Page",checked:"yes"===e.linkToCompare,onChange:e=>o({linkToCompare:e?"yes":""})}),"yes"===e.linkToCompare&&(0,i.jsx)(s.TextControl,{label:"Comparison Page URL",value:e.comparePageUrl,onChange:e=>o({comparePageUrl:e}),help:"Leave empty to use the default comparison page."})]})}),(0,i.jsx)(a(),{block:d.UU,attributes:e})]}),save:()=>null})})();