import{j as e,b as l}from"./chunks/BlockEditorTranslator.js?ver=1.4.1";import{r as x}from"./chunks/Icons.js?ver=1.4.1";const{InspectorControls:_}=wp.blockEditor,{PanelBody:j,ToggleControl:d,__experimentalToggleGroupControl:k,__experimentalToggleGroupControlOption:b}=wp.components,C=k,g=b,v=({attributes:o,setAttributes:r,clientId:n})=>e.jsx(e.Fragment,{children:e.jsx(_,{children:e.jsxs(j,{title:l("Settings","fluent-cart"),initialOpen:!0,children:[e.jsxs(C,{isBlock:!0,label:l("Display style","fluent-cart"),value:o.display_style,onChange:t=>r({display_style:t}),children:[e.jsx(g,{value:"list",label:l("List","fluent-cart")}),e.jsx(g,{value:"dropdown",label:l("Dropdown","fluent-cart")})]}),e.jsx(d,{label:l("Show product count","fluent-cart"),help:l("Display the number of products in each category.","fluent-cart"),checked:o.show_product_count,onChange:t=>r({show_product_count:t})}),e.jsx(d,{label:l("Show hierarchy","fluent-cart"),help:l("Display child categories nested under their parents.","fluent-cart"),checked:o.show_hierarchy,onChange:t=>r({show_hierarchy:t})}),e.jsx(d,{label:l("Show empty categories","fluent-cart"),help:l("Display categories even if they have no products.","fluent-cart"),checked:o.show_empty,onChange:t=>r({show_empty:t})})]})})}),{useBlockProps:N}=wp.blockEditor,{registerBlockType:D}=wp.blocks,{useMemo:E}=wp.element,i=window.fluent_cart_product_categories_list_data;function S(o){const r={},n=[];return o.forEach(t=>{r[t.term_id]={...t,children:[]}}),o.forEach(t=>{t.parent&&r[t.parent]?r[t.parent].children.push(r[t.term_id]):n.push(r[t.term_id])}),n}function f({category:o,showCount:r,showHierarchy:n,depth:t=0}){return e.jsxs("li",{className:`fct-category-item fct-category-item--depth-${t}`,children:[e.jsxs("span",{className:"fct-category-link-wrap",children:[e.jsx("a",{href:"#",className:"fct-category-link",onClick:c=>c.preventDefault(),children:o.name}),r&&e.jsxs("span",{className:"fct-category-count",children:["(",o.count,")"]})]}),n&&o.children&&o.children.length>0&&e.jsx("ul",{className:"fct-categories-children",children:o.children.map(c=>e.jsx(f,{category:c,showCount:r,showHierarchy:n,depth:t+1},c.term_id))})]})}D(i.slug+"/"+i.name,{apiVersion:3,title:i.title,description:i.description,icon:{src:x},category:"fluent-cart",attributes:{show_product_count:{type:"boolean",default:!0},show_hierarchy:{type:"boolean",default:!0},show_empty:{type:"boolean",default:!1},display_style:{type:"string",default:"list"}},supports:{html:!1,alignWide:!1,typography:{fontSize:!0,lineHeight:!0},color:{text:!0,link:!0,background:!1},shadow:!1},edit:({attributes:o,setAttributes:r,clientId:n})=>{const{show_product_count:t,show_hierarchy:c,show_empty:h,display_style:m}=o,y=N(),u=i.categories||[],a=E(()=>{let s=u;return h||(s=s.filter(p=>p.count>0)),c?S(s):s.map(p=>({...p,children:[]}))},[u,h,c]),w=a.length===0;return e.jsxs("div",{...y,children:[e.jsx(v,{attributes:o,setAttributes:r,clientId:n}),e.jsx("div",{className:"fct-product-categories-list",children:w?e.jsx("p",{className:"fct-product-categories-list--empty",children:l("No categories found.","fluent-cart")}):m==="dropdown"?e.jsxs("div",{className:"fct-categories-dropdown-wrap",children:[e.jsxs("select",{className:"fct-categories-dropdown",disabled:!0,children:[e.jsx("option",{value:"",children:l("Select a category","fluent-cart")}),a.map(s=>e.jsxs("option",{value:s.slug,children:[s.name," ",t?`(${s.count})`:""]},s.term_id))]}),e.jsx("button",{type:"button",className:"fct-categories-go-btn",disabled:!0,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"9 18 15 12 9 6"})})})]}):e.jsx("ul",{className:"fct-categories-list",children:a.map(s=>e.jsx(f,{category:s,showCount:t,showHierarchy:c},s.term_id))})})]})},save:function(o){return null}});
