(()=>{"use strict";var e={n:o=>{var t=o&&o.__esModule?()=>o.default:()=>o;return e.d(t,{a:t}),t},d:(o,t)=>{for(var n in t)e.o(t,n)&&!e.o(o,n)&&Object.defineProperty(o,n,{enumerable:!0,get:t[n]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o)};const o=window.wp.blocks,t=window.wp.blockEditor,n=window.wp.serverSideRender;var l=e.n(n);const s=window.wp.components,a=window.wp.element,i=window.wp.apiFetch;var c=e.n(i);const r=window.ReactJSXRuntime;function u({value:e,onChange:o,label:t}){const[n,l]=(0,a.useState)([]),[i,u]=(0,a.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=>{l(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>l([])).finally(()=>u(!1))}return(0,a.useEffect)(()=>{d("")},[]),(0,a.useEffect)(()=>{e&&!n.find(o=>o.value===e)&&c()({path:`/ggmc/v1/products/${e}`}).then(e=>{l(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,r.jsx)(s.ComboboxControl,{label:t||"Product",value:e,options:n,onChange:o,onFilterValueChange:e=>d(e),__nextHasNoMarginBottom:!0})}const d=JSON.parse('{"UU":"ggmc/kit-contents"}');(0,o.registerBlockType)(d.UU,{edit:({attributes:e,setAttributes:o})=>(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.InspectorControls,{children:(0,r.jsxs)(s.PanelBody,{title:"Content",children:[(0,r.jsx)(u,{value:e.productId,onChange:e=>o({productId:e})}),(0,r.jsx)(s.TextControl,{label:"Section Title",value:e.title,onChange:e=>o({title:e})}),(0,r.jsx)(s.ToggleControl,{label:"Show Title",checked:"yes"===e.show_title,onChange:e=>o({show_title:e?"yes":""})}),(0,r.jsx)(s.ToggleControl,{label:"Show Component Images",checked:"yes"===e.show_images,onChange:e=>o({show_images:e?"yes":""})}),(0,r.jsx)(s.ToggleControl,{label:"Show Quantities",checked:"yes"===e.show_quantities,onChange:e=>o({show_quantities:e?"yes":""})}),(0,r.jsx)(s.ToggleControl,{label:"Show Component Prices",checked:"yes"===e.show_prices,onChange:e=>o({show_prices:e?"yes":""})}),(0,r.jsx)(s.ToggleControl,{label:"Link to Component Products",checked:"yes"===e.link_to_products,onChange:e=>o({link_to_products:e?"yes":""})}),(0,r.jsx)(s.SelectControl,{label:"Layout",value:e.layout,options:[{label:"List",value:"list"},{label:"Grid",value:"grid"},{label:"Table",value:"table"}],onChange:e=>o({layout:e})}),(0,r.jsx)(s.ToggleControl,{label:"Hide for Non-Kit Products",checked:"yes"===e.hide_if_not_kit,onChange:e=>o({hide_if_not_kit:e?"yes":""})})]})}),(0,r.jsx)(l(),{block:d.UU,attributes:e})]}),save:()=>null})})();