(()=>{"use strict";const e={n:o=>{const r=o&&o.__esModule?()=>o.default:()=>o;return e.d(r,{a:r}),r},d:(o,r)=>{if(Array.isArray(r))for(var t=0;t<r.length;){var a=r[t++],c=r[t++];e.o(o,a)?0===c&&t++:0===c?Object.defineProperty(o,a,{enumerable:!0,value:r[t++]}):Object.defineProperty(o,a,{enumerable:!0,get:c})}else for(var a in r)e.o(r,a)&&!e.o(o,a)&&Object.defineProperty(o,a,{enumerable:!0,get:r[a]})},o:(e,o)=>Object.hasOwn(e,o)},o=window.wp.blocks,r=window.wp.blockEditor,t=window.wp.components,a=window.wp.serverSideRender;var c=e.n(a);const s=window.wp.element,l=window.wp.i18n,i=window.wp.apiFetch;var n=e.n(i);const m=window.ReactJSXRuntime;(0,o.registerBlockType)("scwc/products",{apiVersion:3,title:(0,l.__)("Smart Category Products","smart-categories-for-woocommerce"),description:(0,l.__)("Displays a smart category's products as a grid.","smart-categories-for-woocommerce"),icon:"grid-view",category:"woocommerce",attributes:{categoryId:{type:"number",default:0},columns:{type:"number",default:4},limit:{type:"number",default:12},orderby:{type:"string",default:"date"}},edit({attributes:e,setAttributes:o}){const[a,i]=(0,s.useState)([]),d=(0,r.useBlockProps)();(0,s.useEffect)(()=>{var e;n()({path:(e="/categories",`/scwc/v1${e}`)}).then(i).catch(()=>{})},[]);const u=[{label:(0,l.__)("Date","smart-categories-for-woocommerce"),value:"date"},{label:(0,l.__)("Title","smart-categories-for-woocommerce"),value:"title"},{label:(0,l.__)("Price","smart-categories-for-woocommerce"),value:"price"},{label:(0,l.__)("Popularity","smart-categories-for-woocommerce"),value:"popularity"},{label:(0,l.__)("Rating","smart-categories-for-woocommerce"),value:"rating"}];return(0,m.jsxs)("div",{...d,children:[(0,m.jsx)(r.InspectorControls,{children:(0,m.jsxs)(t.PanelBody,{title:(0,l.__)("Settings","smart-categories-for-woocommerce"),children:[(0,m.jsx)(t.SelectControl,{label:(0,l.__)("Category","smart-categories-for-woocommerce"),value:e.categoryId,options:[{label:(0,l.__)("Select…","smart-categories-for-woocommerce"),value:0},...a.map(e=>({label:e.name,value:e.id}))],onChange:e=>o({categoryId:parseInt(e,10)||0}),__nextHasNoMarginBottom:!0}),(0,m.jsx)(t.RangeControl,{label:(0,l.__)("Columns","smart-categories-for-woocommerce"),value:e.columns,min:1,max:6,onChange:e=>o({columns:e})}),(0,m.jsx)(t.RangeControl,{label:(0,l.__)("Number of products","smart-categories-for-woocommerce"),value:e.limit,min:1,max:48,onChange:e=>o({limit:e})}),(0,m.jsx)(t.SelectControl,{label:(0,l.__)("Order by","smart-categories-for-woocommerce"),value:e.orderby,options:u,onChange:e=>o({orderby:e}),__nextHasNoMarginBottom:!0})]})}),e.categoryId?(0,m.jsx)(c(),{block:"scwc/products",attributes:e}):(0,m.jsx)("p",{children:(0,l.__)("Select a smart category to display.","smart-categories-for-woocommerce")})]})},save:()=>null})})();