(()=>{"use strict";var e={n:l=>{var a=l&&l.__esModule?()=>l.default:()=>l;return e.d(a,{a}),a},d:(l,a)=>{for(var o in a)e.o(a,o)&&!e.o(l,o)&&Object.defineProperty(l,o,{enumerable:!0,get:a[o]})},o:(e,l)=>Object.prototype.hasOwnProperty.call(e,l)};const l=window.wp.blocks,a=window.wp.blockEditor,o=window.wp.serverSideRender;var n=e.n(o);const t=window.wp.components,r=window.wp.element,u=window.wp.apiFetch;var s=e.n(u);const i=window.ReactJSXRuntime;function c({value:e,onChange:l,label:a}){const[o,n]=(0,r.useState)([]),[u,c]=(0,r.useState)(!1);function d(e){c(!0);const l=e?`/ggmc/v1/products/search?q=${encodeURIComponent(e)}`:"/ggmc/v1/products/search";s()({path:l}).then(e=>{n(e.map(e=>({value:e.id,label:e.sku?`${e.name} (${e.sku})`:e.name})))}).catch(()=>n([])).finally(()=>c(!1))}return(0,r.useEffect)(()=>{d("")},[]),(0,r.useEffect)(()=>{e&&!o.find(l=>l.value===e)&&s()({path:`/ggmc/v1/products/${e}`}).then(e=>{n(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,i.jsx)(t.ComboboxControl,{label:a||"Product",value:e,options:o,onChange:l,onFilterValueChange:e=>d(e),__nextHasNoMarginBottom:!0})}const d=JSON.parse('{"UU":"ggmc/product-image-grid"}');(0,l.registerBlockType)(d.UU,{edit:({attributes:e,setAttributes:l})=>(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(a.InspectorControls,{children:[(0,i.jsxs)(t.PanelBody,{title:"Content",children:[(0,i.jsx)(t.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,i.jsx)(c,{value:e.productId,onChange:e=>l({productId:e})}),(0,i.jsx)(t.SelectControl,{label:"Image Size",value:e.imageSize,options:[{label:"Thumbnail (150px)",value:"thumbnail"},{label:"Medium (300px)",value:"medium"},{label:"Large (600px)",value:"large"},{label:"Full (Original)",value:"full"}],onChange:e=>l({imageSize:e})})]}),(0,i.jsxs)(t.PanelBody,{title:"Layout",initialOpen:!1,children:[(0,i.jsx)(t.SelectControl,{label:"Layout",value:e.layoutPreset,options:[{label:"Standard Grid",value:"standard-grid"},{label:"Featured + Grid",value:"featured-grid"},{label:"Masonry",value:"masonry"},{label:"Alternating Rows",value:"alternating"}],onChange:e=>l({layoutPreset:e})}),"masonry"!==e.layoutPreset&&(0,i.jsx)(t.SelectControl,{label:"Columns",value:e.gridColumns,options:[{label:"2",value:"2"},{label:"3",value:"3"},{label:"4",value:"4"},{label:"5",value:"5"},{label:"6",value:"6"}],onChange:e=>l({gridColumns:e})}),"masonry"===e.layoutPreset&&(0,i.jsx)(t.SelectControl,{label:"Columns",value:e.masonryColumns,options:[{label:"2",value:"2"},{label:"3",value:"3"},{label:"4",value:"4"},{label:"5",value:"5"},{label:"6",value:"6"}],onChange:e=>l({masonryColumns:e})}),"featured-grid"===e.layoutPreset&&(0,i.jsx)(t.SelectControl,{label:"Featured Image Size",value:e.featuredSpan,options:[{label:"2 Columns x 2 Rows",value:"2x2"},{label:"2 Columns x 1 Row",value:"2x1"},{label:"1 Column x 2 Rows",value:"1x2"}],onChange:e=>l({featuredSpan:e})}),"alternating"===e.layoutPreset&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.TextControl,{label:"Primary Row Count",help:"Number of images in odd rows",type:"number",value:e.alternatingPrimary,onChange:e=>l({alternatingPrimary:parseInt(e,10)||3})}),(0,i.jsx)(t.TextControl,{label:"Secondary Row Count",help:"Number of images in even rows",type:"number",value:e.alternatingSecondary,onChange:e=>l({alternatingSecondary:parseInt(e,10)||2})})]}),"masonry"!==e.layoutPreset&&(0,i.jsx)(t.SelectControl,{label:"Image Aspect Ratio",value:e.imageAspectRatio,options:[{label:"Original",value:"original"},{label:"1:1 Square",value:"1-1"},{label:"4:3",value:"4-3"},{label:"3:2",value:"3-2"},{label:"16:9",value:"16-9"}],onChange:e=>l({imageAspectRatio:e})})]}),(0,i.jsx)(t.PanelBody,{title:"Lightbox",initialOpen:!1,children:(0,i.jsx)(t.ToggleControl,{label:"Enable Lightbox",checked:"yes"===e.showLightbox,onChange:e=>l({showLightbox:e?"yes":""})})}),(0,i.jsx)(t.PanelBody,{title:"Performance",initialOpen:!1,children:(0,i.jsx)(t.ToggleControl,{label:"Lazy Loading",checked:"yes"===e.enableLazyLoading,onChange:e=>l({enableLazyLoading:e?"yes":""})})})]}),(0,i.jsx)(n(),{block:d.UU,attributes:e})]}),save:()=>null})})();