(()=>{"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 n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,o=window.wp.blockEditor,n=window.wp.serverSideRender;var r=e.n(n);const a=window.wp.components,l=window.wp.element,s=window.wp.apiFetch;var c=e.n(s);const u=window.ReactJSXRuntime;function d({value:e,onChange:t,label:o}){const[n,r]=(0,l.useState)([]),[s,d]=(0,l.useState)(!1);function i(e){d(!0);const t=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";c()({path:t}).then(e=>{r(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>r([])).finally(()=>d(!1))}return(0,l.useEffect)(()=>{i("")},[]),(0,l.useEffect)(()=>{e&&!n.find(t=>t.value===e)&&c()({path:`/ggmc/v1/products/${e}`}).then(e=>{r(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,u.jsx)(a.ComboboxControl,{label:o||"Product",value:e,options:n,onChange:t,onFilterValueChange:e=>i(e),__nextHasNoMarginBottom:!0})}const i=JSON.parse('{"UU":"ggmc/product-description"}');(0,t.registerBlockType)(i.UU,{edit:({attributes:e,setAttributes:t})=>(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(o.InspectorControls,{children:(0,u.jsxs)(a.PanelBody,{title:"Description Settings",children:[(0,u.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,u.jsx)(d,{value:e.productId,onChange:e=>t({productId:e})}),(0,u.jsx)(a.SelectControl,{label:"Description Type",value:e.descriptionType,options:[{label:"Full Description",value:"full"},{label:"Short Description",value:"short"},{label:"Auto Excerpt",value:"excerpt"}],onChange:e=>t({descriptionType:e})}),"excerpt"===e.descriptionType&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(a.RangeControl,{label:"Excerpt Length (words)",value:e.excerptLength,onChange:e=>t({excerptLength:e}),min:5,max:100}),(0,u.jsx)(a.ToggleControl,{label:"Show Read More",checked:"yes"===e.showReadMore,onChange:e=>t({showReadMore:e?"yes":"no"})}),"yes"===e.showReadMore&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(a.TextControl,{label:"Read More Text",value:e.readMoreText,onChange:e=>t({readMoreText:e})}),(0,u.jsx)(a.TextControl,{label:"Read Less Text",value:e.readLessText,onChange:e=>t({readLessText:e})})]})]})]})}),(0,u.jsx)(r(),{block:i.UU,attributes:e})]}),save:()=>null})})();