1import{r as n,j as e,b as Se,a3 as De,M as ge,b3 as Ee,ae as be,I as Te,a7 as Me,T as O,a0 as Le,a2 as Ae,B as se,D as re,a1 as fe,h as X,aq as Fe,F as $e}from"../entries/pages_index.DwH1fEUc.js";import{S as Re}from"./chunk-B5przYSq.js";import{C as Ie}from"./chunk-Db78be4v.js";import{F as Pe}from"./chunk-DIkC8li9.js";import"./chunk-BugajZ7n.js";/* empty css *//* empty css *//* empty css *//* empty css *//* empty css */import"./chunk-BtJPlET1.js";import"./chunk-DNCcTp_s.js";import"./chunk-SMnF6rVS.js";import"./chunk-BOx6UWN_.js";import"./chunk-Ct4DSnPm.js";import"./chunk-DPgVrtpG.js";import"./chunk-BcxcWqIV.js";import"./chunk-Bftl_ZOY.js";import"./chunk-C1PnZ2mO.js";import"./chunk-Bi54BlzQ.js";function Oe({isOpen:t,onClose:s,categories:f,relations:c,onSelect:o}){const[r,_]=n.useState(""),[a,m]=n.useState(0),b=n.useRef(null),u=n.useRef(null);if(n.useEffect(()=>{t&&setTimeout(()=>b.current?.focus(),50)},[t]),n.useEffect(()=>{m(0)},[r]),n.useEffect(()=>{const x=f.filter(y=>y.id!==1&&(y.name.toLowerCase().includes(r.toLowerCase())||y.slug.toLowerCase().includes(r.toLowerCase()))),v=Math.min(x.length-1,19),p=y=>{t&&(y.key==="Escape"?s():y.key==="ArrowDown"?(y.preventDefault(),m(d=>Math.min(d+1,v))):y.key==="ArrowUp"?(y.preventDefault(),m(d=>Math.max(d-1,0))):y.key==="Enter"&&x[a]&&(y.preventDefault(),o(x[a]),s(),_("")))};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[t,s,r,a,f,o]),n.useEffect(()=>{u.current?.children[a]?.scrollIntoView({behavior:"smooth",block:"nearest"})},[a]),!t)return null;const C=f.filter(x=>x.id!==1&&(x.name.toLowerCase().includes(r.toLowerCase())||x.slug.toLowerCase().includes(r.toLowerCase()))),j=x=>c.filter(v=>v.childId===x).length,M=x=>c.filter(v=>v.parentId===x).length;return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:s,children:e.jsxs("div",{className:"w-[500px] max-h-[70vh] bg-admin_paper rounded-2xl shadow-2xl flex flex-col overflow-hidden border border-admin_bordered",onClick:x=>x.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-admin_bordered",children:[e.jsx("h3",{className:"text-admin_text font-semibold text-sm",children:"Search Nodes"}),e.jsx("button",{onClick:s,className:"text-admin_text_dim hover:text-admin_text transition-colors text-xl leading-none",children:"Ã"})]}),e.jsx("div",{className:"px-4 pt-3 pb-2",children:e.jsx("input",{ref:b,type:"text",placeholder:"Name or slug...",value:r,onChange:x=>_(x.target.value),className:"w-full bg-admin_canvas border border-admin_bordered rounded-lg px-3 py-2 text-admin_text text-sm focus:outline-none focus:border-admin_primary"})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-2 pb-3 space-y-0.5",ref:u,children:[C.length===0&&r===""&&e.jsx("p",{className:"text-center text-admin_text_dim text-sm py-6",children:"Start typing to search..."}),C.length===0&&r!==""&&e.jsx("p",{className:"text-center text-admin_text_dim text-sm py-6",children:"No nodes found"}),C.slice(0,20).map((x,v)=>e.jsxs("button",{onClick:()=>{o(x),s(),_("")},className:`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-left transition-colors ${v===a?"bg-admin_primary/15":"hover:bg-admin_canvas"}`,children:[e.jsx("span",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:x.color}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-admin_text text-sm truncate",children:x.name}),e.jsx("div",{className:"text-admin_text_dim text-xs",children:x.slug})]}),e.jsxs("div",{className:"flex gap-2 text-xs text-admin_text_dim flex-shrink-0",children:[e.jsxs("span",{title:"parents",children:["â",j(x.id)]}),e.jsxs("span",{title:"children",children:["â",M(x.id)]})]})]},x.id)),C.length>20&&e.jsxs("p",{className:"text-center text-admin_text_dim text-xs py-2",children:["+",C.length-20," more â refine your search"]})]})]})})}const J=t=>t.toLowerCase().replace(/[^a-z0-9\s-]/g,"").trim().replace(/\s+/g,"-").replace(/-+/g,"-").substring(0,60),ie=()=>{const t=ve;return t[Math.floor(Math.random()*t.length)]},ve=["#E91E63","#9C27B0","#673AB7","#3F51B5","#2196F3","#00BCD4","#009688","#4CAF50","#8BC34A","#FFC107","#F
1F9800","#FF5722","#795548","#607D8B"];let Be=100;const pe=()=>++Be,Ke=[{id:1,name:"Taxonomy",slug:"_root",color:"#6366f1"}],ze=[];function Ve({isOpen:t,onClose:s,onCreateNew:f,onBulkCreate:c,onSelectExisting:o,categories:r,excludeIds:_,parentName:a,currentCategoryId:m,wouldCreateCycle:b}){const[u,C]=n.useState("new"),[j,M]=n.useState(!1),[x,v]=n.useState(""),[p,y]=n.useState(ie()),[d,S]=n.useState(""),[h,T]=n.useState(""),N=n.useRef(null);if(n.useEffect(()=>{t&&setTimeout(()=>N.current?.focus(),50)},[t,u,j]),n.useEffect(()=>{const i=A=>{A.key==="Escape"&&t&&s()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[t,s]),!t)return null;const w=r.filter(i=>!_.includes(i.id)&&!b(m,i.id)&&(i.name.toLowerCase().includes(h.toLowerCase())||i.slug.toLowerCase().includes(h.toLowerCase()))),D=()=>{if(j){const i=d.split(` 2`).map(I=>I.trim()).filter(Boolean);if(!i.length)return;c(i.map(I=>({name:I,color:ie()})))&&(S(""),s())}else{if(!x.trim())return;f(x.trim(),p)&&(v(""),y(ie()),s())}},l=i=>{i.key==="Enter"&&!j&&(i.preventDefault(),D()),i.key==="Enter"&&(i.metaKey||i.ctrlKey)&&(i.preventDefault(),D())};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:s,children:e.jsxs("div",{className:"w-[480px] max-h-[80vh] bg-admin_paper rounded-2xl shadow-2xl flex flex-col overflow-hidden border border-admin_bordered",onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-admin_bordered",children:[e.jsxs("h3",{className:"text-admin_text font-semibold",children:['Add to "',a,'"']}),e.jsx("button",{onClick:s,className:"text-admin_text_dim hover:text-admin_text transition-colors text-xl leading-none",children:"Ã"})]}),e.jsx("div",{className:"flex border-b border-admin_bordered",children:["new","existing"].map(i=>e.jsx("button",{onClick:()=>C(i),className:`flex-1 py-2.5 text-sm font-medium transition-colors ${u===i?"text-admin_primary border-b-2 border-admin_primary":"text-admin_text_dim hover:text-admin_text"}`,children:i==="new"?"New Node":"Existing"},i))}),e.jsx("div",{className:"flex-1 overflow-y-auto p-5 space-y-4",children:u==="new"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-admin_text_dim cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:j,onChange:i=>M(i.target.checked),className:"rounded"}),"Bulk mode"]}),j?e.jsx("textarea",{ref:N,placeholder:"One node name per line...",value:d,onChange:i=>S(i.target.value),onKeyDown:l,rows:6,className:"w-full bg-admin_canvas border border-admin_bordered rounded-lg px-3 py-2 text-admin_text text-sm resize-none focus:outline-none focus:border-admin_primary"}):e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:N,type:"text",placeholder:"Node name...",value:x,onChange:i=>v(i.target.value),onKeyDown:l,className:"w-full bg-admin_canvas border border-admin_bordered rounded-lg px-3 py-2 text-admin_text text-sm focus:outline-none focus:border-admin_primary"}),x&&e.jsxs("p",{className:"text-xs text-admin_text_dim",children:["Slug: ",e.jsx("code",{className:"text-admin_primary",children:J(x)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-xs text-admin_text_dim",children:"Color"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:ve.map(i=>e.jsx("button",{onClick:()=>y(i),style:{backgroundColor:i},className:`w-6 h-6 rounded-full transition-transform ${p===i?"ring-2 ring-white ring-offset-1 ring-offset-admin_paper scale-110":"hover:scale-105"}`},i))})]})]}),e.jsx("button",{onClick:D,disabled:j?!d.trim():!x.trim(),className:"w-full py-2 bg-admin_primary text-white rounded-lg text-sm font-medium disabled:opacity-40 hover:opacity-90 transition-opacity",children:j?"+ Create Nodes":"+ Create Node"})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:N,type:"text",placeholder:"Search existing node...",value:h,onChange:i=>T(i.target.value),className:"w-full bg-admin_canvas border border-admin_bordered rounded-lg px-3 py-2 text-admin_text text-sm focus:outline-none focus:border-admin_primary"}),e.jsxs("div",{className:"space-y-1 max-h-64 overflow-y-auto",children:[w.length===0&&e.jsx("p",{className:"text-center text-admin_text_dim text-sm py-4",children:r.length<=1?"No nodes yet":"No nodes found"}),w.slice(0,15).map(i=>e.jsxs("button",{onClick:()=>{o(i.id),s(),T("")},className:"w-full flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-admin_canvas text-left transition-colors",children:[e.jsx("span",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:i.color}}),e.jsx("span",{className:"text-admin_text text-sm",children:i.name}),e.jsx("span",{className:"text-admin_text_dim text-xs ml-auto",children:i.slug})]},i.id))]})]})})]})})}function Ue({isOpen:t,onClose:s,categories:f,onSelect:c,excludeIds:o,selectedCount:r,selectedNames:_}){const[a,m]=n.useState(""),[b,u]=n.useState(0),C=n.useRef(null),j=n.useRef(null);if(n.useEffect(()=>{t&&setTimeout(()=>C.current?.focus(),50)},[t]),n.useEffect(()=>{u(0)},[a]),n.useEffect(()=>{const v=p=>{if(!t)return;const y=f.filter(S=>!o.includes(S.id)&&(S.name.toLowerCase().includes(a.toLowerCase())||S.slug.toLowerCase().includes(a.toLowerCase()))),d=Math.min(y.length-1,14);p.key==="Escape"?s():p.key==="ArrowDown"?(p.preventDefault(),u(S=>Math.min(S+1,d))):p.key==="ArrowUp"?(p.preventDefault(),u(S=>Math.max(S-1,0))):p.key==="Enter"&&y[b]&&(p.preventDefault(),c(y[b].id),s(),m(""))};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[t,s,a,b,f,o,c]),n.useEffect(()=>{j.current?.children[b]?.scrollIntoView({behavior:"smooth",block:"nearest"})},[b]),!t)return null;const M=f.filter(v=>!o.includes(v.id)&&(v.name.toLowerCase().includes(a.toLowerCase())||v.slug.toLowerCase().includes(a.toLowerCase()))),x=_.length<=2?_.join(", "):`${_.slice(0,2).join(", ")} +${_.length-2}`;return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:s,children:e.jsxs("div",{className:"w-[440px] max-h-[70vh] bg-admin_paper rounded-2xl shadow-2xl flex flex-col overflow-hidden border border-admin_bordered",onClick:v=>v.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-admin_bordered",children:[e.jsxs("h3",{className:"text-admin_text font-semibold text-sm",children:["Move"," ",r>1?`${r} nodes`:`"${x}"`]}),e.jsx("button",{onClick:s,className:"text-admin_text_dim hover:text-admin_text transition-colors text-xl leading-none",children:"Ã"})]}),r>1&&e.jsx("div",{className:"px-4 py-2 border-b border-admin_bordered flex flex-wrap gap-1.5",children:_.map((v,p)=>e.jsx("span",{className:"px-2 py-0.5 bg-admin_primary/20 text-admin_primary text-xs rounded-full",children:v},p))}),e.jsx("div",{className:"px-4 pt-3 pb-2",children:e.jsx("input",{ref:C,type:"text",placeholder:"Search destination...",value:a,onChange:v=>m(v.target.value),className:"w-full bg-admin_canvas border border-admin_bordered rounded-lg px-3 py-2 text-admin_text text-sm focus:outline-none focus:border-admin_primary"})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-2 pb-3 space-y-0.5",ref:j,children:[M.length===0&&e.jsx("p",{className:"text-center text-admin_text_dim text-sm py-6",children:"No nodes found"}),M.slice(0,15).map((v,p)=>e.jsxs("button",{onClick:()=>{c(v.id),s(),m("")},className:`w-full flex items-center gap-3 px-3 py-2 rounded-lg text-left transition-colors ${p===b?"bg-admin_primary/15":"hover:bg-admin_canvas"}`,children:[e.jsx("span",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:v.color}}),e.jsx("span",{className:"text-admin_text text-sm",children:v.name}),e.jsx("span",{className:"text-admin_text_dim text-xs ml-auto",children:v.slug})]},v.id))]})]})})}const R=Se("taxonomy"),_e=(t={})=>R({list_nodes:t}),He=t=>R({get_node:{slug:t}}),le=t=>R({save_node:t}),qe=(t,s)=>R({move_node:{slugs:t,parentSlug:s}}),oe=(t,s)=>R({add_parent:{slugs:t,parentSlug:s}}),We=(t,s)=>R({remove_parent:{slugs:t,parentSlug:s}}),Ge=t=>R({delete_node:{slug:t}}),Ye=()=>R({list_db_models:{}}),Xe=(t,s)=>R({get_classified_item:{dataId:t,dataType:s}}),Je=t=>R({list_model_items:t}),Qe=t=>R({list_classifications:t}),Ze=(t,s,f)=>R({assign_classification:{dataIds:t,dataType:s,taxonomySlug:f}}),et=t=>R({remove_classification:t}),tt=(t,s)=>R({get_classified_ids:{dataType:t,taxonomySlug:s}}),nt=(t,s)=>R({update_classification:{id:t,enabled:s}});function at({slug:t,onClose:s,onSaved:f}){const[c,o]=n.useState(null),[r,_]=n.useState(null),[a,m]=n.useState(!0);n.useEffect(()=>{t&&(m(!0),Promise.all([He(t),De({match:{"content.type":"TaxonomyNode"},itemsPerPage:1})]).then(([u,C])=>{o(u?.content??null);const j=C?.data?.[0];_(j?{...j.content,_id:j._id}:null)}
2).catch(console.error).finally(()=>m(!1)))},[t]);const b=async u=>{c&&(await Ee({_id:c._id,content:{...c.content,...u},localization:c.localization}),f?.(),s())};return e.jsxs(ge,{isOpen:!!t,onClose:s,title:"Node Properties",variant:"admin_drawer_right",closeOnClickOutside:!0,className:"w-[800px]",children:[a&&e.jsx("div",{className:"flex items-center justify-center h-48 text-admin_text_dim text-sm",children:"Loading..."}),!a&&(!c||!r)&&e.jsx("div",{className:"flex items-center justify-center h-48 text-admin_text_dim text-sm",children:"Failed to load node"}),!a&&c&&r&&e.jsx(Ie,{dataItem:c,contentType:r,fieldValues:c.content,onSave:b,onClickSave:()=>{},clearValuesAfterSave:!1,onClose:s})]})}function st(t,s,f,c,o){const r=n.useCallback(m=>{s(b=>[...b,{id:m.id,name:m.name}]),f([])},[s,f]),_=n.useCallback(m=>{s(t.slice(0,m+1)),f([])},[t,s,f]),a=n.useCallback(m=>{const b=(C,j=[])=>{const M=c.find(v=>v.id===C);if(!M)return j;const x=o.find(v=>v.childId===C);return x?b(x.parentId,[{id:M.id,name:M.name},...j]):[{id:M.id,name:M.name},...j]},u=b(m.id);u.length>0&&s(u)},[c,o,s]);return{navigateInto:r,navigateTo:_,jumpToCategory:a}}function rt(t){const[s,f]=n.useState([]),[c,o]=n.useState(null),r=n.useCallback((a,m)=>{if(a.detail!==2)if(a.shiftKey){if(c&&c!==m){const b=t.map(j=>j.id),u=b.indexOf(c),C=b.indexOf(m);if(u!==-1&&C!==-1){const j=Math.min(u,C),M=Math.max(u,C);f(x=>Array.from(new Set([...x,...b.slice(j,M+1)])))}else f(j=>j.includes(m)?j:[...j,m])}else f(b=>b.includes(m)?b:[...b,m]);o(m)}else a.metaKey||a.ctrlKey?(f(b=>b.includes(m)?b.filter(u=>u!==m):[...b,m]),o(m)):(f(b=>b.includes(m)&&b.length===1?[]:[m]),o(m))},[c,t]),_=n.useCallback(a=>{(a.target.classList.contains("taxonomy-grid")||a.target.classList.contains("taxonomy-empty"))&&f([])},[]);return{selectedItems:s,setSelectedItems:f,handleCardClick:r,handleBackgroundClick:_}}function it(t,s,f,c,o,r,_,a,m,b,u,C={}){const j=n.useCallback((h,T)=>{const w=f.filter(l=>l.parentId===o.id).map(l=>t.find(i=>i.id===l.childId)).filter(Boolean).find(l=>l.name.toLowerCase()===h.toLowerCase());if(w)return u(`"${w.name}" already exists here`,"warning"),!1;const D={id:pe(),name:h,slug:J(h),color:T};return s(l=>[...l,D]),c(l=>[...l,{parentId:o.id,childId:D.id}]),C.onCreate&&C.onCreate(D,o.id).catch(l=>{console.error("Failed to create node:",l),u("Failed to save node","error")}),!0},[o.id,t,f,s,c,u,C]),M=n.useCallback(h=>{const T=f.filter(l=>l.parentId===o.id).map(l=>t.find(i=>i.id===l.childId)).filter(Boolean),N=h.map(l=>l.name.toLowerCase()).filter((l,i,A)=>A.indexOf(l)!==i);if(N.length>0)return u(`Duplicate names in input: ${N.slice(0,3).join(", ")}`,"warning"),!1;const w=h.filter(({name:l})=>T.some(i=>i.name.toLowerCase()===l.toLowerCase())).map(l=>l.name);if(w.length>0)return u(`Already exists here: ${w.slice(0,3).join(", ")}`,"warning"),!1;const D=h.map(({name:l,color:i})=>({id:pe(),name:l,slug:J(l),color:i}));return s(l=>[...l,...D]),c(l=>[...l,...D.map(i=>({parentId:o.id,childId:i.id}))]),C.onBulkCreate&&C.onBulkCreate(D,o.id).catch(l=>{console.error("Failed to bulk create:",l),u("Failed to save nodes","error")}),!0},[o.id,t,f,s,c,u,C]),x=n.useCallback((h,T)=>{if(a.length!==1)return;const N=a[0];s(w=>w.map(D=>D.id===N?{...D,name:h,slug:J(h),color:T}:D)),N===o.id&&_(w=>w.map(D=>D.id===N?{...D,name:h}:D)),C.onRename&&C.onRename(N,h,T).catch(w=>{console.error("Failed to rename:",w),u("Failed to save changes","error")}),b(!0)},[a,o.id,s,_,b,u,C]),v=n.useCallback((h,T,N=f)=>{if(h===T)return!0;const w=new Set,D=[h];for(;D.length>0;){const l=D.shift();if(l===T)return!0;w.has(l)||(w.add(l),D.push(...N.filter(i=>i.childId===l).map(i=>i.parentId)))}return!1},[f]),p=n.useCallback(async h=>{if(!f.some(T=>T.parentId===o.id&&T.childId===h)){if(v(o.id,h)){u("Cannot add â would create a circular reference","error");return}if(C.onAddRelation)try{await C.onAddRelation(o.id,h)}catch(T){console.error("Failed to add relation:",T),u("Failed to save changes","error")}}},[f,o.id,v,u,C]),y=n.useCallback(h=>t.find(T=>T.id===h),[t]),d=n.useCallback(h=>{if(a.length===0)return;for(const N of a)if(v(h,N)){const w=y(N);u(`Cannot move "${w?.name}" â circular reference`,"error");return}const T=a.includes(o.id);if(c(N=>
2{let w=[...N];return a.forEach(D=>{if(h!==D){if(D===o.id&&r.length>1){const l=r[r.length-2].id;w=w.filter(i=>!(i.parentId===l&&i.childId===D))}else w=w.filter(l=>!(l.parentId===o.id&&l.childId===D));w.some(l=>l.parentId===h&&l.childId===D)||w.push({parentId:h,childId:D})}}),w}),T&&y(h)){const w=(D,l=[])=>{const i=t.find(I=>I.id===D);if(!i)return l;const A=f.find(I=>I.childId===D);return A?w(A.parentId,[{id:i.id,name:i.name},...l]):[{id:i.id,name:i.name},...l]};_([...w(h),{id:o.id,name:o.name}])}C.onMove&&C.onMove(a,h).catch(N=>{console.error("Failed to move:",N),u("Failed to save changes","error")}),m([])},[a,o,r,t,f,c,_,m,y,v,u,C]),S=n.useCallback(h=>{if(a.length===0)return;const T=a.includes(o.id);c(N=>{let w=[...N];return a.forEach(D=>{if(D===o.id&&r.length>1){const l=r[r.length-2].id;w=w.filter(i=>!(i.parentId===l&&i.childId===D))}else w=w.filter(l=>!(l.parentId===o.id&&l.childId===D))}),w}),C.onDelete&&C.onDelete(a).catch(N=>{console.error("Failed to delete:",N),u("Failed to delete nodes","error")}),T&&r.length>1?h(r.length-2):m([])},[a,o,r,c,m,u,C]);return{createNewCategory:j,bulkCreateCategories:M,renameCategory:x,addExistingAsChild:p,moveSelectedToParent:d,deleteSelected:S,getCategoryById:y,wouldCreateCycle:v}}function lt(t,s,f,c){const[o,r]=n.useState(null),_=n.useCallback((j,M)=>{t.includes(M)||s([M]),j.dataTransfer.effectAllowed="move";const x=t.includes(M)?t:[M],v=document.createElement("div");v.style.cssText=` 3 position:absolute;top:-9999px; 4 background:#1e293b;border:1px solid #6366f1;border-radius:10px; 5 padding:10px 14px;box-shadow:0 8px 24px rgba(0,0,0,.5); 6 display:flex;flex-direction:column;gap:6px;max-width:280px; 7 `;const p=document.createElement("div");p.textContent=`${x.length} node${x.length>1?"s":""}`,p.style.cssText="font-size:11px;color:#94a3b8;font-weight:600;text-transform:uppercase;",v.appendChild(p);const y=document.createElement("div");if(y.style.cssText="display:flex;flex-wrap:wrap;gap:5px;",x.slice(0,3).forEach(d=>{const S=f(d);if(!S)return;const h=document.createElement("div");h.style.cssText=` 8 display:flex;align-items:center;gap:5px;padding:3px 9px; 9 background:#334155;border-radius:5px;font-size:12px;color:#e2e8f0; 10 `;const T=document.createElement("span");T.style.cssText=`width:7px;height:7px;border-radius:50%;background:${S.color};flex-shrink:0;`;const N=document.createElement("span");N.textContent=S.name,N.style.cssText="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:130px;",h.append(T,N),y.appendChild(h)}),x.length>3){const d=document.createElement("div");d.textContent=`+${x.length-3}`,d.style.cssText="padding:3px 9px;background:#6366f1;border-radius:5px;font-size:12px;color:#fff;",y.appendChild(d)}v.appendChild(y),document.body.appendChild(v),j.dataTransfer.setDragImage(v,0,0),setTimeout(()=>document.body.removeChild(v),0)},[t,s,f]),a=n.useCallback((j,M)=>{j.preventDefault(),j.dataTransfer.dropEffect=t.includes(M)?"none":"move"},[t]),m=n.useCallback((j,M)=>{j.preventDefault(),t.includes(M)||r(M)},[t]),b=n.useCallback(j=>{j.currentTarget===j.target&&r(null)},[]),u=n.useCallback((j,M)=>{j.preventDefault(),r(null),t.length>0&&!t.includes(M)&&c(M)},[t,c]),C=n.useCallback(()=>r(null),[]);return{dragOverId:o,handleDragStart:_,handleDragOver:a,handleDragEnter:m,handleDragLeave:b,handleDrop:u,handleDragEnd:C}}function ot({selectedItems:t,categories:s,breadcrumb:f,showSearch:c,showAddNode:o,showMoveNode:r,showRename:_,modalJustClosed:a,setBreadcrumb:m,setSelectedItems:b,setShowRename:u,setShowAddNode:C,setShowSearch:j,handleOpenProperties:M,children:x}){const v=n.useRef(0);n.useEffect(()=>{const p=d=>{if(!(d.target.tagName==="INPUT"||d.target.tagName==="TEXTAREA")&&!(c||o||r||_)&&!a)switch(d.key){case"Enter":if(t.length===1){const S=s.find(h=>h.id===t[0]);S&&(m(h=>[...h,{id:S.id,name:S.name}]),b([]))}break;case"Backspace":if(f.length>1){d.preventDefault();const S=f[f.length-1].id;m(h=>h.slice(0,-1)),b([S])}break;case"F2":t.length===1&&(d.preventDefault(),u(!0));break;case" ":t.length===1&&!t.includes(1)&&(d.preventDefault(),M?.());break;case"Escape":b([]);break;case"a":d.preventDefault(),C(!0);break;case"s":d.preventDefault(),j(!0);break;case"ArrowRight":case"ArrowLeft":case"ArrowDown":case"ArrowUp":d.preventDefault(),y(d.key,d.shiftKey);break}},y=(d,S)=>{if(x.length===0)return;const h=x.map(A=>A.id);if(t.length===0){const A=d==="ArrowLeft"||d==="ArrowUp"?h.length-1:0;v.current=A,b([h[A]]);return}const T=t[t.length-1];let N=h.indexOf(T);N===-1&&(N=v.current);
10const w=document.querySelector(".taxonomy-grid"),D=Math.max(1,Math.floor((w?.clientWidth||0)/296));let l=N;if(d==="ArrowRight"?l=Math.min(N+1,h.length-1):d==="ArrowLeft"?l=Math.max(N-1,0):d==="ArrowDown"?l=Math.min(N+D,h.length-1):d==="ArrowUp"&&(l=Math.max(N-D,0)),l===N)return;v.current=l;const i=h[l];if(S){const A=h.indexOf(t[0]);if(A!==-1){const I=Math.min(A,l),U=Math.max(A,l);b(h.slice(I,U+1))}else b([i])}else b([i]);setTimeout(()=>{document.querySelectorAll(".taxonomy-card")[l]?.scrollIntoView({behavior:"smooth",block:"nearest"})},0)};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[t,f,c,o,r,_,s,a,m,b,u,C,j,M,x])}function dt(t,s,f){const c=n.useMemo(()=>{const _=s.filter(a=>a.parentId===f.id).map(a=>a.childId);return t.filter(a=>_.includes(a.id))},[f.id,s,t]),o=n.useCallback(_=>{const a=s.filter(m=>m.childId===_).map(m=>m.parentId);return t.filter(m=>a.includes(m.id))},[s,t]),r=n.useCallback(_=>s.filter(a=>a.parentId===_).length,[s]);return{children:c,getParents:o,getChildrenCount:r}}function ct(){const[t,s]=n.useState([]),f=n.useCallback((c,o="info")=>{const r=Date.now();s(_=>[..._,{id:r,message:c,type:o}]),setTimeout(()=>s(_=>_.filter(a=>a.id!==r)),4e3)},[]);return{toasts:t,notify:f}}function mt({initialData:t={categories:Ke,relations:ze,rootCategory:{id:1,name:"Taxonomy"}},operations:s={},operationInProgress:f=!1,onReload:c}={}){const{toasts:o,notify:r}=ct(),[_,a]=n.useState(t.categories),[m,b]=n.useState(t.relations),[u,C]=n.useState([t.rootCategory]),[j,M]=n.useState(!1),[x,v]=n.useState(!1),[p,y]=n.useState(!1),[d,S]=n.useState(!1),[h,T]=n.useState(!1),[N,w]=n.useState(null),[D,l]=n.useState(!1);n.useEffect(()=>{a(t.categories),b(t.relations),C(k=>k.length===0||k[0].id!==t.rootCategory.id?[t.rootCategory]:k)},[t]);const i=u[u.length-1],{children:A,getParents:I,getChildrenCount:U}=dt(_,m,i),{selectedItems:L,setSelectedItems:V,handleCardClick:H,handleBackgroundClick:Q}=rt(A),{navigateInto:W,navigateTo:G,jumpToCategory:Z}=st(u,C,V,_,m),{createNewCategory:ee,bulkCreateCategories:te,renameCategory:ne,addExistingAsChild:g,moveSelectedToParent:E,deleteSelected:F,getCategoryById:K,wouldCreateCycle:Y}=it(_,a,m,b,i,u,C,L,V,l,r,s),{dragOverId:z,handleDragStart:we,handleDragOver:de,handleDragEnter:ce,handleDragLeave:me,handleDrop:ue,handleDragEnd:je}=lt(L,V,K,E);n.useEffect(()=>{if(!D)return;const k=setTimeout(()=>l(!1),100);return()=>clearTimeout(k)},[D]);const xe=n.useCallback(()=>{if(L.length!==1||L.includes(1))return;const k=K(L[0]);k?.slug&&w(k.slug)},[L,K]);ot({selectedItems:L,categories:_,breadcrumb:u,showSearch:j,showAddNode:x,showMoveNode:p,showRename:d,modalJustClosed:D,setBreadcrumb:C,setSelectedItems:V,setShowRename:S,setShowAddNode:v,setShowSearch:M,handleOpenProperties:xe,children:A});const Ne=L.length>0&&!L.includes(1),Ce=L.length===1&&!L.includes(1);return e.jsxs("div",{className:"flex flex-col h-full bg-admin_canvas select-none",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-admin_bordered flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-admin_text font-semibold text-base",children:"Taxonomy"}),f&&e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-admin_text_dim",children:[e.jsx("span",{className:"w-3 h-3 border-2 border-admin_primary border-t-transparent rounded-full animate-spin"}),"Saving..."]})]}),e.jsxs("button",{onClick:()=>M(!0),disabled:_.length<=1,className:"flex items-center gap-1.5 text-xs text-admin_text_dim hover:text-admin_text disabled:opacity-40 transition-colors",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),"Search (S)"]})]}),e.jsx("div",{className:"flex items-center gap-1 px-6 py-2.5 bg-admin_paper/40 border-b border-admin_bordered flex-shrink-0 flex-wrap",children:u.map((k,P)=>e.jsxs(be.Fragment,{children:[P>0&&e.jsx("span",{className:"text-admin_text_dim text-xs",children:"âº"}),e.jsxs("button",{onClick:$=>{const ae=P===u.length-1;$.shiftKey||$.metaKey||$.ctrlKey||ae?H($,k.id):G(P)},onDragOver:$=>de($,k.id),onDragEnter:$=>ce($,k.id),onDragLeave:me,onDrop:$=>ue($,k.id),className:`text-sm px-2 py-0.5 rounded transition-colors ${P===u.length-1?"text-admin_text font-medium":"text-admin_text_dim hover:text-admin_text"} ${z===k.id?"bg-admin_primary/20 text-admin_primary":""} 11 ${L.includes(k.id)?"text-admin_primary":""}`,children:[P===0?"â ":"",k.name]})]},`${k.id}-${P}`))}),e.jsxs("div",{className:"flex items-center justify-between px-6 py-2.5 border-b border-admin_bordered flex-shrink-0",children:[e.jsxs("span",{className:"text-xs text-admin_text_dim",children:[A.length===0?"N
11o children":`${A.length} children`,(()=>{const k=I(i.id);return i.id!==1&&k.length>1?` · ${k.length} parents`:null})(),L.length>0&&e.jsxs("span",{className:"text-admin_primary",children:[" · ",L.length," selected"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[Ce&&e.jsxs(e.Fragment,{children:[e.jsx(q,{onClick:()=>S(!0),children:"Rename (F2)"}),e.jsx(q,{onClick:xe,children:"Properties (Space)"})]}),Ne&&e.jsxs(e.Fragment,{children:[e.jsxs(q,{onClick:()=>y(!0),children:["Move",L.length>1?` (${L.length})`:""]}),e.jsxs(q,{onClick:()=>T(!0),danger:!0,children:["Remove",L.length>1?` (${L.length})`:""]}),e.jsx("div",{className:"w-px h-4 bg-admin_bordered mx-1"})]}),e.jsx(q,{primary:!0,onClick:()=>v(!0),children:"+ Add"})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 taxonomy-grid",style:A.length===0?{display:"flex",alignItems:"center",justifyContent:"center"}:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(280px, 280px))",gap:"16px",alignContent:"start"},onClick:Q,children:A.length===0?e.jsxs("div",{className:"taxonomy-empty flex flex-col items-center justify-center text-center gap-4",children:[e.jsx("div",{className:"text-4xl opacity-30",children:"â«"}),e.jsxs("p",{className:"text-admin_text_dim text-sm",children:['No children in "',i.name,'"']}),e.jsx("button",{onClick:()=>v(!0),className:"text-sm text-admin_primary hover:opacity-80 transition-opacity",children:"+ Add first node"})]}):A.map(k=>{const P=I(k.id),$=U(k.id),ae=L.includes(k.id),ke=z===k.id;return e.jsxs("div",{className:`taxonomy-card relative rounded-xl border bg-admin_paper cursor-pointer transition-all 12 ${ae?"border-admin_primary ring-1 ring-admin_primary/30 bg-admin_primary/5":"border-admin_bordered hover:border-admin_primary/50"} 13 ${ke?"border-admin_primary ring-2 ring-admin_primary/40 scale-[1.02]":""} 14 `,draggable:!0,onClick:B=>H(B,k.id),onDoubleClick:()=>W(k),onDragStart:B=>we(B,k.id),onDragOver:B=>de(B,k.id),onDragEnter:B=>ce(B,k.id),onDragLeave:me,onDrop:B=>ue(B,k.id),onDragEnd:je,children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-1 rounded-t-xl",style:{backgroundColor:k.color}}),e.jsxs("div",{className:"pt-4 px-4 pb-3",children:[e.jsxs("div",{className:"flex items-start gap-2 mb-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full flex-shrink-0 mt-1.5",style:{backgroundColor:k.color}}),e.jsx("span",{className:"text-admin_text text-sm font-medium leading-snug",children:k.name})]}),e.jsx("div",{className:"text-admin_text_dim text-xs pl-4",children:k.slug}),($>0||P.length>1)&&e.jsxs("div",{className:"flex gap-3 mt-2 pl-4",children:[$>0&&e.jsxs("span",{className:"text-xs text-admin_text_dim",children:["â ",$]}),P.length>1&&e.jsxs("span",{className:"text-xs text-admin_text_dim",children:["⢠",P.length," parents"]})]})]})]},k.id)})}),e.jsxs("div",{className:"flex items-center justify-between px-6 py-2.5 border-t border-admin_bordered flex-shrink-0",children:[e.jsxs("div",{className:"flex gap-4 text-xs text-admin_text_dim",children:[e.jsxs("span",{children:[_.length-1," total nodes"]}),e.jsxs("span",{children:[m.length," relations"]})]}),e.jsx("span",{className:"text-xs text-admin_text_dim hidden lg:block",children:"Arrows · Enter=open · Backspace=back · F2=rename · Space=properties · A=add · S=search · Drag=move"})]}),o.length>0&&e.jsx("div",{className:"fixed bottom-4 right-4 z-[100] flex flex-col gap-2",children:o.map(k=>e.jsx("div",{className:`px-4 py-2.5 rounded-lg text-sm shadow-lg text-white ${k.type==="error"?"bg-red-600":k.t
14ype==="warning"?"bg-amber-500":"bg-admin_primary"}`,children:k.message},k.id))}),e.jsx(Oe,{isOpen:j,onClose:()=>{M(!1),l(!0)},categories:_,relations:m,onSelect:Z}),e.jsx(Ve,{isOpen:x,onClose:()=>{v(!1),l(!0)},onCreateNew:ee,onBulkCreate:te,onSelectExisting:g,categories:_,excludeIds:[i.id,...A.map(k=>k.id)],parentName:i.name,currentCategoryId:i.id,wouldCreateCycle:Y}),e.jsx(Ue,{isOpen:p,onClose:()=>{y(!1),l(!0)},categories:_,onSelect:E,excludeIds:[...L,...L.includes(i.id)&&u.length>1?[u[u.length-2].id]:[i.id]],selectedCount:L.length,selectedNames:L.map(k=>K(k)?.name).filter(Boolean)}),d&&L.length===1&&(()=>{const k=K(L[0]);return k?e.jsx(ut,{category:k,onClose:()=>{S(!1),l(!0)},onRename:ne}):null})(),h&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:()=>T(!1),children:e.jsxs("div",{className:"w-[400px] bg-admin_paper rounded-2xl border border-admin_bordered shadow-2xl p-5 space-y-4",onClick:k=>k.stopPropagation(),children:[e.jsxs("h3",{className:"text-admin_text font-semibold text-sm",children:["Remove ",L.length>1?`${L.length} nodes`:`"${K(L[0])?.name}"`,"?"]}),e.jsxs("p",{className:"text-admin_text_dim text-sm",children:["This will permanently delete ",L.length>1?"these nodes":"this node"," and all their relations."]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:()=>{T(!1),l(!0)},className:"text-sm text-admin_text_dim hover:text-admin_text px-3 py-1.5",children:"Cancel"}),e.jsx("button",{onClick:()=>{T(!1),l(!0),F(G)},className:"text-sm bg-red-600 text-white px-4 py-1.5 rounded-lg hover:opacity-90",children:"Remove"})]})]})}),N&&e.jsx(at,{slug:N,onClose:()=>w(null),onSaved:()=>{w(null),c?.()}})]})}function q({children:t,onClick:s,danger:f,primary:c}){return e.jsx("button",{onClick:s,className:`text-xs px-3 py-1.5 rounded-lg transition-colors ${c?"bg-admin_primary text-white hover:opacity-90":f?"text-red-400 hover:bg-red-500/10":"text-admin_text_dim hover:text-admin_text hover:bg-admin_canvas"}`,children:t})}function ut({category:t,onClose:s,onRename:f}){const[c,o]=n.useState(t.name),r=be.useRef(null);n.useEffect(()=>{setTimeout(()=>{r.current?.focus(),r.current?.select()},50)},[]),n.useEffect(()=>{const a=m=>{m.key==="Escape"&&s(),m.key==="Enter"&&m.target===r.current&&(m.preventDefault(),_())};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[c]);const _=()=>{c.trim()&&(f(c.trim(),t.color),s())};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:s,children:e.jsxs("div",{className:"w-[400px] bg-admin_paper rounded-2xl border border-admin_bordered shadow-2xl p-5 space-y-4",onClick:a=>a.stopPropagation(),children:[e.jsxs("h3",{className:"text-admin_text font-semibold text-sm",children:['Rename "',t.name,'"']}),e.jsx("input",{ref:r,type:"text",value:c,onChange:a=>o(a.target.value),className:"w-full bg-admin_canvas border border-admin_bordered rounded-lg px-3 py-2 text-admin_text text-sm focus:outline-none focus:border-admin_primary"}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:s,className:"text-sm text-admin_text_dim hover:text-admin_text px-3 py-1.5",children:"Cancel"}),e.jsx("button",{onClick:_,disabled:!c.trim(),className:"text-sm bg-admin_primary text-white px-4 py-1.5 rounded-lg disabled:opacity-40 hover:opacity-90",children:"Save"})]})]})})}const ye=(t,s="",f={})=>{if(!t||typeof t!="object")return f;for(const[c,o]of Object.entries(t)){const r=s?`${s}.${c}`:c;o!==null&&typeof o=="object"&&!Array.isArray(o)&&!(o instanceof Date)?ye(o,r,f):f[r]=o}return f},xt=t=>t==null?e.jsx("span",{className:"text-admin_text_dim italic",children:"null"}):typeof t=="boolean"?e.jsx("span",{className:"text-admin_primary font-mono",children:String(t)}):Array.isArray(t)?e.jsxs("span",{className:"text-admin_text_secondary font-mono",children:["[",t.length," items]"]}):e.jsx("span",{className:"break-all",children:String(t)});function ft({item:t,title:s="Item Details",onClose:f}){const[c,o]=n.useState(""),r=n.useMemo(()=>t?ye(t):{},[t]),_=n.useMemo(()=>{const a=Object.entries(r);if(!c.trim())return a;const m=c.toLowerCase();return a.filter(([b,u])=>b.toLowerCase().includes(m)||String(u).toLowerCase().includes(m))},[r,c]);return e.jsx(ge,{isOpen:!!t,onClose:f,title:s,variant:"admin_drawer_right",closeOnClickOutside:!0,children:e.jsxs("div",{children:[e.jsx("div",{className:"sticky top-0 z-10 px-4 py-3 border-b border-admin_bordered bg-admin_paper",children:e.jsx(Te,{variant:"admin",value:c,onChange:a=>o(a.target.value),placeholder:"Search keys or values...",autoFocus:!0,className:"w-full",icon:e.jsx(Me,{className:"h-5 w-5 text-admin_text_secondary"}),showClearButton:c.length>0,onClear:()=>o("")})}),e.jsx("div",{children:_.length===0?e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(O,{variant:"admin_body1",className:"text-admin_text_dim",children:c?"No matching fields":"Empty object"})}):e.jsx("table",{className:"w-full text-sm",children:e.jsx("tbody",{children:_.map(([a,m])=>e.jsxs("tr",{className:"border-b border-admin_bordered/40 hover:bg-admin_canvas/50",children:[e.jsx("td",{className:"px-4 py-2 font-mono text-admin_text_secondary align-top w-[45%] truncate max-w-0",children:e.jsx("span",{title:a,children:a})}),e.jsx("td",{className:"px-4 py-2 text-admin_text align-top",children:xt(m)})]},a))})})}),e.jsxs("div",{className:"sticky bottom-0 px-4 py-2 border-t border-admin_bordered bg-admin_paper text-xs text-admin_text_dim",children:[_.length," field",_.length!==1?"s":"",c&&` matching "${c}"`]})]})})}const pt=new Set(["ContentType","FieldType","Group","Editor"]);function ht(){const{availableTypeNames:t}=Le(),[s,f]=n.useState([]),[c,o]=n.useState([]),[r,_]=n.useState(null),[a,m]=n.useState(null),[b,u]=n.useState([]),[C,j]=n.useState(0),[M,x]=n.useState(0),[v,p]=n.useState([]),[y,d]=n.useState([]),[S,h]=n.useState(null),[T,N]=n.useState(""),[w,D]=n.useState([]),[l,i]=n.useState([]);n.useEffect(()=>{Ye().then(g=>{g?.data&&f(g.data)})},[]),n.useEffect(()=>{_e({includeAll:!0}).then(g=>{g?.list&&o(g.list.map(E=>({value:E.content?.slug,label:E.content?.name||E.content?.slug})))})},[]),n.useEffect(()=>{u([]),!(!r?.value||!a)&&tt(r.value,a).then(g=>{g?.data&&u(g.data)})},[r?.value,a,M]),n.useEffect(()=>{D([]),i([])},[a]);const A=(()=>{const g=t().filter(F=>!pt.has(F)).sort(),E=[];return E.push({value:"__cms_header__",label:"CMS Types",disabled:!0}),g.forEach(F=>E.push({value:F,label:F,_kind:"cms"})),s.length>0&&(E.push({divider:!0}),E.push({value:"__db_header__",label:"DB Models",disabled:!0}
14),s.forEach(F=>E.push({value:F,label:F,_kind:"db"}))),E})(),I=n.useCallback(g=>r?r.kind==="db"?Je({modelName:r.value,page:g.page,itemsPerPage:g.itemsPerPage,search:g.search}):Ae({...g,match:{"content.type":r.value,deleted:{$ne:!0},...g.match||{}}}):Promise.resolve({data:[],total:0}),[r]),U=n.useCallback(g=>{if(!a)return Promise.resolve({data:[],total:0});const E={taxonomySlug:a};return r?.value&&(E.dataType=r.value),w.length>0&&(E.dataType={$in:w.map(F=>F.value)}),Qe({...g,match:E})},[a,r?.value,w]),L=async()=>{if(!r?.value||!a||v.length===0)return;const g=await Ze(v.map(String),r.value,a);g?.result?(X({message:`Assigned ${g.assigned} item(s)`,className:"bg-admin_success text-white"}),p([]),d([]),x(E=>E+1)):X({message:g?.error||"Assignment failed",className:"bg-admin_error text-white"})},V=async g=>{(await et({ids:[g._id]}))?.result&&(X({message:"Removed classification",className:"bg-admin_success text-white"}),x(F=>F+1))},H=async g=>{(await nt(g._id,!g.enabled))?.result?x(F=>F+1):X({message:"Failed to update",className:"bg-admin_error text-white"})},Q=async g=>{const E=await Xe(g.dataId,g.dataType);E?.data&&(h(E.data),N(g._itemName||g.dataId))},W=[...c],G=g=>g.content?.name||g.content?.title||g.name||g.title||g.email||g.displayName||String(g._id),Z=[{id:"name",title:"Name",render:(g,E)=>e.jsx("span",{className:"truncate block w-full",children:G(E)})},{id:"taxonomy",title:"Node",headerClassName:"w-48",render:(g,E)=>b.includes(String(E._id))?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs bg-admin_primary/10 text-admin_primary rounded-full px-2 py-0.5",children:[e.jsx(Pe,{className:"w-3 h-3"}),a||"tagged"]}):e.jsx("span",{className:"text-admin_text_dim text-xs",children:"â"})}],ee=[{id:"_itemName",title:"Item",render:(g,E)=>e.jsx("button",{className:"text-left truncate block w-full text-admin_primary hover:underline",onClick:()=>Q(E),title:"View item details",children:g||E.dataId})},{id:"dataType",title:"Type",headerClassName:"w-32",render:g=>e.jsx("span",{className:"text-admin_text_secondary text-xs",children:g})},{id:"enabled",title:"Enabled",headerClassName:"w-20 text-center",render:(g,E)=>e.jsx("div",{className:"flex justify-center",children:e.jsx(Fe,{variant:"admin",isOn:!!E.enabled,onChange:()=>H(E)})})},{id:"actions",title:"",headerClassName:"w-10",render:(g,E)=>e.jsx(se,{variant:"admin_icon",className:"p-1 text-admin_text_secondary hover:text-admin_error",onClick:()=>V(E),title:"Remove",children:e.jsx($e,{className:"w-4 h-4"})})}],te=v.length>0&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-admin_paper border-t border-admin_bordered",children:[e.jsxs(O,{variant:"admin_body1",children:[e.jsx("span",{className:"font-bold",children:v.length})," item(s) selected"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(se,{variant:"admin_secondary",onClick:()=>{p([]),d([])},children:"Deselect"}),e.jsx(se,{variant:"admin_primary",onClick:L,disabled:!a,title:a?void 0:"Select a taxonomy node first",children:"Assign to node"})]})]}),ne=r?[{value:r.value}]:[];return e.jsxs("div",{className:"flex flex-col h-full bg-admin_canvas",children:[e.jsxs("div",{className:"flex items-end gap-3 px-4 py-3 bg-admin_paper border-b border-admin_bordered",children:[e.jsxs("div",{className:"flex flex-col gap-1 w-64",children:[e.jsx(O,{variant:"admin_txt2_dim",children:"Data Source"}),e.jsx(re,{variant:"admin",options:A,value:ne,onChange:g=>{const E=g?.[0];if(!E?.value||E.value.startsWith("__")){_(null),p([]),d([]),j(F=>F+1);return}_({value:E.value,kind:E._kind||"cms"}),p([]),d([]),j(F=>F+1)},showCheckbox:!1,showSelectionTick:!0,highlightOnSelection:!0,searchEnabled:!0,placeholder:"Select data source"})]}),e.jsxs("div",{className:"flex flex-col gap-1 w-56",children:[e.jsx(O,{variant:"admin_txt2_dim",children:"Taxonomy Node"}),e.jsx(re,{variant:"admin",options:W,value:a?W.filter(g=>g.value===a):[],onChange:g=>{const E=g?.[0]?.value??null;m(E),x(F=>F+1)},showCheckbox:!1,showSelectionTick:!0,highlightOnSelection:!0,searchEnabled:!0,placeholder:"Select node"})]})]}),e.jsxs("div",{className:"flex flex-row gap-4 px-4 pb-4 mt-4",children:[e.jsxs("div",{className:"flex flex-col flex-1 bg-admin_paper rounded border border-admin_bordered overflow-hidden",children:[e.jsxs("div",{className:"px-4 pt-3 pb-1",children:[e.jsx(O,{variant:"admin_h4",children:"Content Items"}),e.jsx(O,{variant:"admin_txt2_dim",children:r?`${r.kind==="db"?"DB model":"CMS type"}: ${r.value}
14`:"Select a data source to browse items"})]}),e.jsx(fe,{variant:"admin_browser",apiMethod:I,apiDataField:"data",renders:Z,searchField:r?.kind==="db"?"name email title":"content.name content.title",refreshKey:`${C}-${r?.value}`,preferredHeight:"calc(100vh - 440px)",itemsPerPage:15,enableSelection:!0,selectedItems:v,selectedData:y,onSelectionChange:(g,E)=>{p(g),d(E)},itemIdField:"_id",tableFooter:te,noData:e.jsx(O,{variant:"admin_body1",className:"text-admin_text_dim",children:r?"No items found":"Select a data source"})})]}),e.jsxs("div",{className:"flex flex-col flex-1 bg-admin_paper rounded border border-admin_bordered overflow-hidden",children:[e.jsxs("div",{className:"px-4 pt-3 pb-2",children:[e.jsx(O,{variant:"admin_h4",children:"Classifications"}),e.jsx(O,{variant:"admin_txt2_dim",children:a?r?`Node "${a}" â ${r.value}`:`Node "${a}"`:"Select a taxonomy node"}),l.length>0&&e.jsx("div",{className:"mt-2",children:e.jsx(re,{variant:"admin",options:l,value:w,onChange:g=>{D(g||[]),x(E=>E+1)},multiSelection:!0,searchEnabled:!0,showCheckbox:!0,placeholder:"Filter by type"})})]}),e.jsx(fe,{variant:"admin_browser",apiMethod:U,apiDataField:"data",renders:ee,searchField:"_itemName dataType dataId",refreshKey:`${M}-${a}-${r?.value}-${w.map(g=>g.value).join(",")}`,preferredHeight:"calc(100vh - 440px)",itemsPerPage:15,onDataLoaded:g=>{const E=[...new Set(g.map(F=>F.dataType).filter(Boolean))];return i(F=>{const K=new Set(F.map(z=>z.value)),Y=[...F];return E.forEach(z=>{K.has(z)||Y.push({value:z,label:z})}),Y}),g},noData:e.jsx(O,{variant:"admin_body1",className:"text-admin_text_dim",children:a?"No classifications":"Select a taxonomy node"})})]})]}),e.jsx(ft,{item:S,title:T,onClose:()=>h(null)})]})}const he={id:1,name:"Taxonomy",slug:"_root",color:"#6366f1"};function gt(){const[t,s]=n.useState(!0),[f,c]=n.useState(!1),[o,r]=n.useState(null),[_,a]=n.useState(0),m=n.useRef(!0);n.useEffect(()=>{let p=!1;return(async()=>{m.current&&s(!0);try{const d=await _e({includeAll:!0});p||r(d?.list||[])}catch(d){console.error("[Taxonomy] Failed to load nodes:",d),p||r([])}finally{!p&&m.current&&(s(!1),m.current=!1)}})(),()=>{p=!0}},[_]);const b=n.useCallback(()=>a(p=>p+1),[]),u=n.useCallback(p=>async(...y)=>{c(!0);try{return await p(...y)}finally{c(!1)}},[]),C=n.useRef({byMongoId:new Map,next:2}),{initialData:j,idMap:M,reverseIdMap:x}=n.useMemo(()=>{if(!o)return{initialData:null,idMap:new Map,reverseIdMap:new Map};const p=C.current,y=new Map,d=new Map;for(const T of o){const N=String(T._id);let w=p.byMongoId.get(N);w===void 0&&(w=p.next++,p.byMongoId.set(N,w)),y.set(N,w),d.set(w,{_id:T._id,slug:T.content.slug})}const S=[he],h=[];for(const T of o){const N=y.get(String(T._id));S.push({id:N,name:T.content.name||T.content.slug,slug:T.content.slug,color:T.content.color||"#607D8B"});const w=T.content.parents||[];
14if(w.length===0)h.push({parentId:1,childId:N});else for(const D of w){const l=y.get(String(D._id));h.push({parentId:l??1,childId:N})}}return{initialData:{categories:S,relations:h,rootCategory:he},idMap:y,reverseIdMap:d}},[o]),v=n.useMemo(()=>j?{onCreate:u(async(p,y)=>{await le({slug:p.slug,data:{name:p.name,color:p.color,status:"draft"}});const d=x.get(y);d?.slug&&d.slug!=="_root"&&await oe([p.slug],d.slug),b()}),onBulkCreate:u(async(p,y)=>{for(const d of p){await le({slug:d.slug,data:{name:d.name,color:d.color,status:"draft"}});const S=x.get(y);S?.slug&&S.slug!=="_root"&&await oe([d.slug],S.slug)}b()}),onRename:u(async(p,y,d)=>{const S=x.get(p);S&&(await le({_id:String(S._id),slug:S.slug,data:{name:y,color:d}}),b())}),onMove:u(async(p,y)=>{const d=p.map(h=>x.get(h)?.slug).filter(Boolean),S=x.get(y)?.slug??"_root";d.length&&(await qe(d,S),b())}),onDelete:u(async p=>{for(const y of p){const d=x.get(y);d&&await Ge(d.slug)}b()}),onAddRelation:u(async(p,y)=>{const d=x.get(y),S=x.get(p);!d||!S||(await oe([d.slug],S.slug),b())}),onRemoveRelation:u(async(p,y)=>{const d=x.get(y),S=x.get(p);!d||!S||(await We([d.slug],S.slug),b())})}:{},[j,x,u,b]);return{initialData:j,operations:v,loading:t,operationInProgress:f,reload:b,reverseIdMap:x}}const bt=()=>{const{initialData:t,operations:s,loading:f,operationInProgress:c,reload:o}=gt();return f?e.jsx("div",{className:"flex items-center justify-center h-full bg-admin_canvas",children:e.jsxs("div",{className:"flex items-center gap-2 text-admin_text_dim text-sm",children:[e.jsx("span",{className:"w-4 h-4 border-2 border-admin_primary border-t-transparent rounded-full animate-spin"}),"Loading taxonomy..."]})}):t?e.jsx(mt,{initialData:t,operations:s,operationInProgress:c,onReload:o}):null};function Ot(){return e.jsx(Re,{menuName:"AdminTaxonomyMenu",tabs:{nodes:bt,classify:ht}})}export{Ot as default}; 15//# sourceMappingURL=chunk-DG6lX-Aj.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.