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