(()=>{"use strict";var e={n:a=>{var o=a&&a.__esModule?()=>a.default:()=>a;return e.d(o,{a:o}),o},d:(a,o)=>{for(var l in o)e.o(o,l)&&!e.o(a,l)&&Object.defineProperty(a,l,{enumerable:!0,get:o[l]})},o:(e,a)=>Object.prototype.hasOwnProperty.call(e,a)};const a=window.wp.blocks,o=window.wp.serverSideRender;var l=e.n(o);const t=window.wp.blockEditor,n=window.wp.components,r=window.wp.element,c=window.wp.hooks,s=window.wp.data;function i(e,a=[],o=""){var l;for(l=0;l<e.length;l+=1)a.push({label:o+e[l].name,value:e[l].id}),e[l].children.length>0&&i(e[l].children,a,o.trim()+"— ");return a}const d=window.ReactJSXRuntime,p=JSON.parse('{"UU":"acadp/categories"}');(0,a.registerBlockType)(p.UU,{attributes:{view:{type:"string",default:acadp_blocks.categories.view},parent:{type:"number",default:acadp_blocks.categories.parent},columns:{type:"number",default:acadp_blocks.categories.columns},depth:{type:"number",default:acadp_blocks.categories.depth},orderby:{type:"string",default:acadp_blocks.categories.orderby},order:{type:"string",default:acadp_blocks.categories.order},show_count:{type:"boolean",default:acadp_blocks.categories.show_count},hide_empty:{type:"boolean",default:acadp_blocks.categories.hide_empty}},edit:function({attributes:e,setAttributes:a}){const{view:o,parent:p,columns:_,depth:b,orderby:u,order:g,show_count:h,hide_empty:w}=e,x=(0,s.useSelect)(e=>e("core").getEntityRecords("taxonomy","acadp_categories",{per_page:-1})),k=(0,r.useMemo)(()=>{let e=[{label:"— "+acadp_blocks.categories.i18n.parent_label+" —",value:0}];if(x&&x.length>0){let a=function(e){var a,o,l={},t=[];for(o=0;o<e.length;o+=1)l[e[o].id]=o,e[o].children=[];for(o=0;o<e.length;o+=1)0==(a=e[o]).parent?t.push(a):l.hasOwnProperty(a.parent)&&e[l[a.parent]].children.push(a);return t}(x),o=i(a);e=[...e,...o]}return e},[x]),m=(0,r.useRef)();return(0,r.useEffect)(()=>{m.current?(0,c.doAction)("acadp_init_categories",e):m.current=!0}),(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(t.InspectorControls,{children:(0,d.jsxs)(n.PanelBody,{title:acadp_blocks.categories.i18n.panel_settings,children:[(0,d.jsx)(n.PanelRow,{children:(0,d.jsx)(n.SelectControl,{__next40pxDefaultSize:!0,label:acadp_blocks.categories.i18n.view_label,value:o,options:[{label:acadp_blocks.categories.i18n.view_list,value:"text_list"},{label:acadp_blocks.categories.i18n.view_grid,value:"image_grid"}],onChange:e=>a({view:e})})}),(0,d.jsx)(n.PanelRow,{children:(0,d.jsx)(n.SelectControl,{__next40pxDefaultSize:!0,label:acadp_blocks.categories.i18n.parent_label,value:p,options:k,onChange:e=>a({parent:Number(e)})})}),(0,d.jsx)(n.PanelRow,{children:(0,d.jsx)(n.RangeControl,{__next40pxDefaultSize:!0,label:acadp_blocks.categories.i18n.columns_label,value:_,min:1,max:12,onChange:e=>a({columns:e})})}),(0,d.jsx)(n.PanelRow,{children:(0,d.jsx)(n.RangeControl,{__next40pxDefaultSize:!0,label:acadp_blocks.categories.i18n.depth_label,value:b,min:1,max:12,onChange:e=>a({depth:e})})}),(0,d.jsx)(n.PanelRow,{children:(0,d.jsx)(n.SelectControl,{__next40pxDefaultSize:!0,label:acadp_blocks.categories.i18n.orderby_label,value:u,options:[{label:acadp_blocks.categories.i18n.orderby_id,value:"id"},{label:acadp_blocks.categories.i18n.orderby_count,value:"count"},{label:acadp_blocks.categories.i18n.orderby_name,value:"name"},{label:acadp_blocks.categories.i18n.orderby_slug,value:"slug"}],onChange:e=>a({orderby:e})})}),(0,d.jsx)(n.PanelRow,{children:(0,d.jsx)(n.SelectControl,{__next40pxDefaultSize:!0,label:acadp_blocks.categories.i18n.order_label,value:g,options:[{label:acadp_blocks.categories.i18n.order_asc,value:"asc"},{label:acadp_blocks.categories.i18n.order_desc,value:"desc"}],onChange:e=>a({order:e})})}),(0,d.jsx)(n.PanelRow,{children:(0,d.jsx)(n.ToggleControl,{__nextHasNoMarginBottom:!0,label:acadp_blocks.categories.i18n.show_count_label,help:acadp_blocks.categories.i18n.show_count_help,checked:h,onChange:()=>a({show_count:!h})})}),(0,d.jsx)(n.PanelRow,{children:(0,d.jsx)(n.ToggleControl,{__nextHasNoMarginBottom:!0,label:acadp_blocks.categories.i18n.hide_empty_label,help:acadp_blocks.categories.i18n.hide_empty_help,checked:w,onChange:()=>a({hide_empty:!w})})})]})}),(0,d.jsx)("div",{...(0,t.useBlockProps)(),children:(0,d.jsx)(n.Disabled,{children:(0,d.jsx)(l(),{block:"acadp/categories",attributes:e})})})]})}})})();