(()=>{"use strict";var e={n:t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var l in o)e.o(o,l)&&!e.o(t,l)&&Object.defineProperty(t,l,{enumerable:!0,get:o[l]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,o=window.wp.blockEditor,l=window.wp.serverSideRender;var n=e.n(l);const a=window.wp.components,u=window.wp.element,c=window.wp.apiFetch;var r=e.n(c);const s=window.ReactJSXRuntime;function i({value:e,onChange:t,label:o}){const[l,n]=(0,u.useState)([]),[c,i]=(0,u.useState)(!1);function d(e){i(!0);const t=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";r()({path:t}).then(e=>{n(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>n([])).finally(()=>i(!1))}return(0,u.useEffect)(()=>{d("")},[]),(0,u.useEffect)(()=>{e&&!l.find(t=>t.value===e)&&r()({path:`/ggmc/v1/products/${e}`}).then(e=>{n(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,s.jsx)(a.ComboboxControl,{label:o||"Product",value:e,options:l,onChange:t,onFilterValueChange:e=>d(e),__nextHasNoMarginBottom:!0})}const d=JSON.parse('{"UU":"ggmc/product-details-link"}');(0,t.registerBlockType)(d.UU,{edit:({attributes:e,setAttributes:t})=>(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(o.InspectorControls,{children:(0,s.jsxs)(a.PanelBody,{title:"Content",children:[(0,s.jsx)(a.SelectControl,{label:"Product Source",value:e.productSource,options:[{label:"Current Product (Auto-detect)",value:"current"},{label:"Select Product",value:"custom"}],onChange:e=>t({productSource:e})}),"custom"===e.productSource&&(0,s.jsx)(i,{value:e.productId,onChange:e=>t({productId:e})}),(0,s.jsx)(a.TextControl,{label:"Link Text",value:e.linkText,onChange:e=>t({linkText:e})}),(0,s.jsx)(a.SelectControl,{label:"Link Style",value:e.linkStyle,options:[{label:"Text Link",value:"text"},{label:"Button",value:"button"},{label:"Outline Button",value:"outline"}],onChange:e=>t({linkStyle:e})}),(0,s.jsx)(a.ToggleControl,{label:"Close Popup on Click",checked:"yes"===e.closePopup,onChange:e=>t({closePopup:e?"yes":""})}),(0,s.jsx)(a.SelectControl,{label:"Alignment",value:e.align,options:[{label:"Left",value:"left"},{label:"Center",value:"center"},{label:"Right",value:"right"}],onChange:e=>t({align:e})})]})}),(0,s.jsx)(n(),{block:d.UU,attributes:e})]}),save:()=>null})})();