(()=>{"use strict";var e={n:l=>{var n=l&&l.__esModule?()=>l.default:()=>l;return e.d(n,{a:n}),n},d:(l,n)=>{for(var a in n)e.o(n,a)&&!e.o(l,a)&&Object.defineProperty(l,a,{enumerable:!0,get:n[a]})},o:(e,l)=>Object.prototype.hasOwnProperty.call(e,l)};const l=window.wp.blocks,n=window.wp.blockEditor,a=window.wp.serverSideRender;var t=e.n(a);const o=window.wp.components,u=window.wp.element,r=window.wp.apiFetch;var c=e.n(r);const s=window.ReactJSXRuntime;function i({value:e,onChange:l,label:n}){const[a,t]=(0,u.useState)([]),[r,i]=(0,u.useState)(!1);function d(e){i(!0);const l=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";c()({path:l}).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,u.useEffect)(()=>{d("")},[]),(0,u.useEffect)(()=>{e&&!a.find(l=>l.value===e)&&c()({path:`/ggmc/v1/products/${e}`}).then(e=>{t(l=>l.find(l=>l.value===e.id)?l:[{value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name},...l])}).catch(()=>{})},[e]),(0,s.jsx)(o.ComboboxControl,{label:n||"Product",value:e,options:a,onChange:l,onFilterValueChange:e=>d(e),__nextHasNoMarginBottom:!0})}const d=JSON.parse('{"UU":"ggmc/product-name"}');(0,l.registerBlockType)(d.UU,{edit:({attributes:e,setAttributes:l})=>(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.InspectorControls,{children:(0,s.jsxs)(o.PanelBody,{title:"Content",children:[(0,s.jsx)(o.SelectControl,{label:"Product Source",value:e.productSource,options:[{label:"Current Product (Auto-detect)",value:"current"},{label:"Select Product",value:"custom"}],onChange:e=>l({productSource:e})}),"custom"===e.productSource&&(0,s.jsx)(i,{value:e.productId,onChange:e=>l({productId:e})}),(0,s.jsx)(o.SelectControl,{label:"HTML Tag",value:e.htmlTag,options:[{label:"H1",value:"h1"},{label:"H2",value:"h2"},{label:"H3",value:"h3"},{label:"H4",value:"h4"},{label:"H5",value:"h5"},{label:"H6",value:"h6"},{label:"div",value:"div"},{label:"span",value:"span"},{label:"p",value:"p"}],onChange:e=>l({htmlTag:e})}),(0,s.jsx)(o.ToggleControl,{label:"Enable Link",checked:"yes"===e.enableLink,onChange:e=>l({enableLink:e?"yes":""})}),"yes"===e.enableLink&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(o.TextControl,{label:"Link URL",value:e.link.url,onChange:n=>l({link:{...e.link,url:n}})}),(0,s.jsx)(o.ToggleControl,{label:"Open in New Tab",checked:e.link.is_external,onChange:n=>l({link:{...e.link,is_external:n}})}),(0,s.jsx)(o.ToggleControl,{label:"Nofollow",checked:e.link.nofollow,onChange:n=>l({link:{...e.link,nofollow:n}})})]}),(0,s.jsx)(o.SelectControl,{label:"Alignment",value:e.alignment,options:[{label:"Default",value:""},{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"},{label:"Justify",value:"justify"}],onChange:e=>l({alignment:e})})]})}),(0,s.jsx)(t(),{block:d.UU,attributes:e})]}),save:()=>null})})();