1import{c as $e,d as G,b as mt,a as ut,bN as pt,c2 as It,r as n,c3 as Ve,j as e,l as Tt,cb as Se,cc as we,cd as ke,ce as ae,$ as tt,aD as We,m as Mt,aA as Ie,aq as Be,d2 as ft,cp as Ke,c$ as At,aB as Rt,d1 as He,aH as rt,X as ze,c6 as Pt,aK as Lt,a0 as Dt,cl as Et,bf as Ot}from"./index-76bdc72b.js";import{A as Ft}from"./AdminPageHeader-580e5517.js";import{P as Wt}from"./PillTabs-d7ec756f.js";import{u as Vt}from"./NavigationGuardContext-65095c63.js";import{A as Bt}from"./AdminDataTable-d8249af3.js";import{A as Ht}from"./AdminStatusBadge-bc39fbb9.js";import{u as Ut,M as $t}from"./useDeleteConfirm-539fc159.js";import{M as _t,G as Qt}from"./MediaThumbnail-6afe877c.js";import{g as Ce}from"./errorMessages-0bf20f9f.js";import{D as gt}from"./DeleteConfirmDialog-2440a777.js";import{C as ht,a as xt,g as Gt,s as yt}from"./usageChecks-0b7c8019.js";import{G as nt}from"./globe-6ee84621.js";import{E as bt}from"./ellipsis-18e8c6f3.js";import{P as vt}from"./pencil-001687a3.js";import{C as Yt}from"./copy-201468ba.js";import{T as Je}from"./trash-2-bbcb0843.js";import{L as et}from"./layers-7ca262e4.js";import{F as Ct}from"./folder-plus-c3b9e298.js";import{H as jt}from"./house-b889e0bc.js";import{u as qt,a as ot,K as Kt,P as Xt,D as Zt,c as Jt,S as er,v as tr,b as rr,d as ar,C as sr,G as Nt,e as nr}from"./sortable.esm-b73a416a.js";import{A as or}from"./SettingsFormComponents-8abe3b19.js";import{i as ir}from"./usageGuards-07104b9d.js";import{T as lr}from"./triangle-alert-26c2fab2.js";import{D as dr}from"./download-4cd73ae0.js";import"./chevrons-right-250ac711.js";import"./alert-dialog-8e242f14.js";import"./eye-off-4a48edf6.js";import"./eye-63bd2005.js";import"./upload-b43fe249.js";import"./external-link-381fafa4.js";(function(){typeof globalThis=="undefined"&&(typeof global!="undefined"?global.globalThis=global:typeof window!="undefined"?window.globalThis=window:typeof self!="undefined"?self.globalThis=self:this.globalThis=this);var t=typeof globalThis!="undefined"?globalThis:window;typeof t.Request=="undefined"&&(t.Request=function(i,x){this.url=i,this.options=x||{},this.method=this.options.method||"GET",this.headers=this.options.headers||{},this.body=this.options.body,this.mode=this.options.mode||"cors",this.credentials=this.options.credentials||"same-origin"}),typeof t.Response=="undefined"&&(t.Response=function(i,x){this.body=i,this.options=x||{},this.status=this.options.status||200,this.statusText=this.options.statusText||"OK",this.ok=this.status>=200&&this.status<300,this.headers=this.options.headers||{}}),typeof t.Headers=="undefined"&&(t.Headers=function(i){if(this._headers={},i&&typeof i=="object")for(var x in i)i.hasOwnProperty(x)&&(this._headers[x.toLowerCase()]=i[x]);this.get=function(m){return this._headers[m.toLowerCase()]},this.set=function(m,h){this._headers[m.toLowerCase()]=h},this.has=function(m){return m.toLowerCase()in this._headers}})})();/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const cr=$e("ChevronsDownUp",[["path",{d:"m7 20 5-5 5 5",key:"13a0gw"}],["path",{d:"m7 4 5 5 5-5",key:"1kwcof"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const mr=$e("ChevronsUpDown",[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const St=$e("FolderInput",[["path",{d:"M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1",key:"fm4g5t"}],["path",{d:"M2 13h10",key:"pgb2dq"}],["path",{d:"m9 16 3-3-3-3",key:"6m91ic"}]]);/** 17 * @license lucide-react v0.462.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const Ue=$e("FolderTree",[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]]),Xe={category:"Dynamic Rows (Netflix Look)",gallery:"Gallery",slider:"Hero Slider",two_columns:"2 Columns",series:"Series",courses:"Course",top10:"Top 10",poster_carousel:"Poster Row",vertical_cards:"Portrait Cards",horizontal_cards:"Landscape Cards"};function it(t){const o=t.info&&typeof t.info=="object"?t.info:void 0,i=o==null?void 0:o.privacy;return i===0||i==="0"?"private":"public"}function lt(t,o){return!o||!t?t:t.startsWith(o+">")?t.slice(o.length+1).trim():t}const Ze=[{value:"-createdAt",label:"Newest First"},{value:"+createdAt",label:"Oldest First"},{value:"+name",label:"Name AâZ"},{value:"-name",label:"Name ZâA"}],wt="categoryList_state",ur="/admin/content/categories";function dt(t){try{sessionStorage.setItem(wt,JSON.stringify(t))}catch(o){}}function pr(){try{return JSON.parse(sessionStorage.getItem(wt)||"null")}catch(t){return null}}function fr({onTotalChange:t}){var Pe,Le,De,Ee,ce,ne,fe,ye,be,Oe;const o=G(s=>s.config),i=G(s=>s.token),x=G(s=>s.adminConfig),m=mt(),h=ut(),u=pt(o)==="contributorRole",b=It(o),[v,I]=n.useState(0),[c,N]=n.useState(!0),[R,$]=n.useState(null),w=pr(),[P,Y]=n.useState((Pe=w==null?void 0:w.pageIndex)!=null?Pe:1),[L,X]=n.useState((Le=w==null?void 0:w.pageSize)!=null?Le:10),[M,y]=n.useState((De=w==null?void 0:w.searchQuery)!=null?De:""),[S,F]=n.useState((Ee=w==null?void 0:w.sortBy)!=null?Ee:Ze[0].value),[a,j]=n.useState((ce=w==null?void 0:w.privacyFilter)!=null?ce:"all"),[f,k]=n.useState((ne=w==null?void 0:w.viewT
21ypeFilter)!=null?ne:"all"),[D,q]=n.useState([]),[xe,Te]=n.useState({});n.useEffect(()=>{dt({pageIndex:P,pageSize:L,searchQuery:M,sortBy:S,privacyFilter:a,viewTypeFilter:f})},[P,L,M,S,a,f]);const Z=n.useRef(S);Z.current=S;const ue=n.useRef(P);ue.current=P,n.useEffect(()=>()=>{window.location.pathname.startsWith(ur)||dt({sortBy:Z.current,pageIndex:ue.current})},[]);const ee=n.useCallback(async(s,g,p,K,te,J)=>{var oe,ie;if(o)try{N(!0),$(null);const se={orderBy:K||S,...p?{freeText:`*${p}*`}:{}},H={};u&&b&&(H["info.owner"]=b),te==="public"&&(H["info.privacy"]=1),te==="private"&&(H["info.privacy"]=0),J&&J!=="all"&&(H["info.mobileViewType"]=J);const le=await Ve(o,i,{pager:{pageIndex:s,pageSize:g},filter:se,customData:Object.keys(H).length>0?H:void 0});let _=le.data||[],r=((oe=le.meta)==null?void 0:oe.total)||0;const l={};if(p&&_.length>0){const d=new Map(_.map(z=>[String(z.id),z.name]));try{const z=await Ve(o,i,{pager:{pageSize:100},filter:{parentIdIn:Array.from(d.keys()).join(","),orderBy:K||S},customData:Object.keys(H).length>0?H:void 0});if((ie=z.data)!=null&&ie.length){const A=new Set(_.map(O=>String(O.id))),E=z.data.filter(O=>!A.has(String(O.id)));for(const O of E){const V=d.get(String(O.parentId));V&&(l[String(O.id)]=V)}_=[..._,...E],r+=E.length}}catch(z){}}Te(l),q(_),I(r),t==null||t(r)}catch(se){$(Ce(se,"Failed to load categories"))}finally{N(!1)}},[o,i,S,t]);n.useEffect(()=>{ee(P,L,M,S,a,f)},[ee,P,L,M,S,a,f,m.key,(fe=m.state)==null?void 0:fe.savedAt]),n.useEffect(()=>{Y(1)},[M]);const Me=n.useCallback(s=>{F(s),Y(1)},[]),_e=n.useCallback(s=>{j(s),Y(1)},[]),je=n.useCallback(s=>{k(s),Y(1)},[]),{ask:Ae,dialogProps:Qe}=Ut(),pe=s=>!o||!s.length?Promise.resolve(!1):Ae({title:s.length>1?`Delete ${s.length} categories`:"Delete category",description:s.length>1?`Are you sure you want to delete ${s.length} categories? This can't be undone.`:`Are you sure you want to delete "${s[0].name}"? This can't be undone.`,details:ht,check:()=>xt(o,x,s.map(g=>({id:g.id,name:g.name,fullName:g.fullName})),i),onConfirm:async()=>{await Promise.all(s.map(g=>ft(o,String(g.id),i))),ee(P,L,M,S,a,f)}}),Ge=async s=>{var g,p,K,te,J,oe,ie,se,H,le,_;if(o)try{const r=await Ke(o,s,i),l={name:`${r.name} (Copy)`,label:((g=r.info)==null?void 0:g.label)||"",description:((p=r.info)==null?void 0:p.description)||r.description||"",privacy:String((te=(K=r.info)==null?void 0:K.privacy)!=null?te:1),mobileViewType:((J=r.info)==null?void 0:J.mobileViewType)||"",sortBy:((oe=r.info)==null?void 0:oe.sortBy)||"",thumbnailUrl:((ie=r.info)==null?void 0:ie.thumbnailUrl)||r.thumbnailUrl||"",posterImgUrl:((se=r.info)==null?void 0:se.posterImgUrl)||"",coverImgUrl:((H=r.info)==null?void 0:H.coverImgUrl)||"",speakers:((le=r.info)==null?void 0:le.speakers)||[],packages:At(r.info),owner:((_=r.info)==null?void 0:_.owner)||"",additionalInfo:{},rawInfo:r.info||{}};h("/admin/content/categories/new",{state:{prefill:l}})}catch(r){console.error("Copy failed:",r)}},Re=n.useCallback(s=>{Y(s.pageIndex),X(s.pageSize)},[]),Ne=n.useMemo(()=>[{accessorKey:"name",header:"Category",cell:({row:s,table:g})=>{var O,V,ve,me;const p=s.original,K=((V=(O=o==null?void 0:o.config)==null?void 0:O.application)==null?void 0:V.rootCategory)||"",te=p.info&&typeof p.info=="object"?p.info:void 0,J=(te==null?void 0:te.thumbnailUrl)||p.thumbnailUrl,oe=p.fullName&&p.fullName!==p.name?(()=>{const re=lt(p.fullName,K);return re&&re!==p.name?re:void 0})():void 0,ie=it(p)==="public",se=(ve=g.getState().rowSelection[s.id])!=null?ve:!1,H=`/admin/content/categories/${p.id}`,le=e.jsx(_t,{src:J,alt:p.name,className:"h-10 w-[71px]",fallbackIcon:e.jsx(Ue,{size:16,style:{color:"var(--admin-text-muted)"}})}),_=!!xe[String(p.id)],r=re=>{if(!M)return re;const Q=new RegExp(`(${M.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi");return re.split(Q).map((he,at)=>Q.test(he)?e.jsx("span",{style:{color:"var(--admin-primary)",fontWeight:600},children:he},at):he)},l=oe||(_&&p.fullName?lt(p.fullName,K)||p.fullName:void 0),d=l?e.jsx("p",{className:"text-xs truncate",style:{color:"var(--admin-text-muted)"},children:r(l)}):void 0,z=(me=p.directEntriesCount)!=null?me:p.entriesCount,A=p.directSubCategoriesCount,E=z!=null||A!=null?e.jsxs("div",{className:"flex items-center gap-3 text-xs",style:{color:"var(--admin-text-muted)"},children:[z!=null&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Rt,{size:11}),z," ",z===1?"video":"videos"]}),A!=null&&A>0&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(et,{size:11}),A," sub"]})]}):void 0;return e.jsx($t,{name:p.name,href:H,thumbnail:le,isPublic:ie,isSelected:se,onToggleSelect:()=>s.toggleSelected(),actions:null,desktopSubtitle:d,mobileSubtitle:E})}},{accessorKey:"info.mobileViewType",header:"View Type",meta:{hideOnMobile:!0},cell:({row:s})=>{const g=s.original.info&&typeof s.original.info=="object"?s.original.info:void 0,p=g==null?void 0:g.mobileViewType,K=Xe[p||""];return K?e.jsx("span",{className:"rounded-md px-2 py-1 text-xs font-medium",style:{backgroundColor:"var(--admin-border-light)",color:"var(--admin-text-secondary)"},children:K}):e.jsx("span",{className:"text-sm",style:{color:"var(--admin-text-muted)"},children:"-"})}},{id:"entries",header:"Videos",meta:{hideOnMobile:!0},cell:({row:s})=>{var g,p;return e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--admin-text)"},children:(p=(g=s.original.directEntriesCount)!=null?g:s.original.entriesCount)!=null?p:"-"})}},{id:"children",header:"Sub-categories",meta:{hideOnMobile:!0},cell:({row:s})=>{const g=s.original.directSubCategoriesCount;return e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--admin-text)"},children:g!=null?g:"-"})}},{id:"visibility",header:"Privacy",meta:{hideOnMobile:!0},cell:({row:s})=>{const g=it(s.original);return e.jsx(Ht,{variant:g==="public"?"success":"warning",icon:g==="public"?e.jsx(nt,{size:11}):e.jsx(Tt,{size:11}),children:g==="public"?"Public":"Private"})}},{id:"actions",header:"",cell:({row:s})=>e.jsxs(Se,{children:[e.jsx(we,{asChild:!0,children:e.jsx("button",{className:"flex h-8 w-8 items-center justify-center rounded-lg transition-colors hover:bg-[var(--admin-surface-hover)]",children:e.jsx(bt,{size:16,style:{color:"var(--admin-text-muted)"}})})}),e.jsxs(ke,{align:"end",className:"w-40 border",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)"},children:[e.jsx(ae,{asChild:!0,className:"cursor-pointer !bg-transparent hover:!bg-[var(--admin-surface-hover)] focus:!bg-[var(--admin-surface-hover)]",style:{color:"var(--admin-text)"},children:e.jsxs(tt,{to:`/admin/content/categories/${s.original.id}`,className:"flex items-center gap-2",children:[e.jsx(vt,{size:14})," Edit"]})}),!u&&e.jsxs(ae,{className:"flex items-center gap-2 cursor-pointer !bg-transparent hover:!bg-[var(--admin-surface-hover)] focus:!bg-[var(--admin-surface-hover)]",style:{color:"var(--admin-text)"},onClick:()=>Ge(String(s.original.id)),children:[e.jsx(Yt,{size:14})," Copy Category"]}),!u&&e.jsxs(ae,{className:"flex items-center gap-2 cursor-pointer !bg-transparent hover:!bg-[var(--admin-surface-hover)] focus:!bg-[var(--admin-surface-hover)]",style:{color:"var(--admin-danger, #dc2626)"},onClick:()=>pe([s.original]),children:[e.jsx(Je,{size:14})," Delete"]})]})]})}],[o,i,xe]),Ye=[{label:"Make Public",icon:e.jsx(nt,{size:14}),onClick:async s=>{if(!o)return;const g=await Promise.all(s.map(p=>Ke(o,String(p.id),i)));await Promise.all(g.map(p=>He(o,String(p.id),{info:{...p.info,privacy:1}},i))),ee(P,L,M,S,a,f)}},{label:"Make Private",icon:e.jsx(Qt,{size:14}),onClick:async s=>{if(!o)return;const g=await Promise.all(s.map(p=>Ke(o,String(p.id),i)));await Promise.all(g.map(p=>He(o,String(p.id),{info:{...p.info,privacy:0}},i))),ee(P,L,M,S,a,f)}},{label:"Delete",icon:e.jsx(Je,{size:14}),onClick:s=>pe(s),variant:"danger",separator:!0}];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-end justify-between gap-3",children:[e.jsx("div",{className:"flex flex-wrap items-end gap-2",children:e.jsxs("div",{children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium",style:{color:"var(--admin-text-muted)"},children:"Filter by"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Se,{children:[e.jsx(we,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-sm font-medium transition-colors",style:{backgroundColor:a!=="all"?"var(--admin-primary)":"var(--admin-surface)",borderColor:a!=="all"?"var(--admin-primary)":"var(--admin-border)",color:a!=="all"?"var(--admin-primary-foreground)":"var(--admin-text)"},children:[a==="all"?"Privacy":a==="public"?"Public":"Private",e.jsx(We,{size:14})]})}),e.jsx(ke,{align:"start",className:"w-36 border",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)"},children:[{value:"all",label:"All"},{value:"public",label:"Public"},{value:"private",label:"Private"}].map(s=>e.jsx(ae,{onClick:()=>
21_e(s.value),className:"cursor-pointer !bg-transparent hover:!bg-[var(--admin-surface-hover)] focus:!bg-[var(--admin-surface-hover)]",style:{color:a===s.value?"var(--admin-primary)":"var(--admin-text)",fontWeight:a===s.value?600:void 0},children:s.label},s.value))})]}),e.jsxs(Se,{children:[e.jsx(we,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-sm font-medium transition-colors",style:{backgroundColor:f!=="all"?"var(--admin-primary)":"var(--admin-surface)",borderColor:f!=="all"?"var(--admin-primary)":"var(--admin-border)",color:f!=="all"?"var(--admin-primary-foreground)":"var(--admin-text)"},children:[f==="all"?"View Type":(ye=Xe[f])!=null?ye:f,e.jsx(We,{size:14})]})}),e.jsxs(ke,{align:"start",className:"w-52 border",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)"},children:[e.jsx(ae,{onClick:()=>je("all"),className:"cursor-pointer !bg-transparent hover:!bg-[var(--admin-surface-hover)] focus:!bg-[var(--admin-surface-hover)]",style:{color:f==="all"?"var(--admin-primary)":"var(--admin-text)",fontWeight:f==="all"?600:void 0},children:"All"}),Object.entries(Xe).map(([s,g])=>e.jsx(ae,{onClick:()=>je(s),className:"cursor-pointer !bg-transparent hover:!bg-[var(--admin-surface-hover)] focus:!bg-[var(--admin-surface-hover)]",style:{color:f===s?"var(--admin-primary)":"var(--admin-text)",fontWeight:f===s?600:void 0},children:g},s))]})]})]})]})}),e.jsx("div",{className:"flex items-end gap-2",children:e.jsxs("div",{children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium",style:{color:"var(--admin-text-muted)"},children:"Sort by"}),e.jsxs(Se,{children:[e.jsx(we,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-sm font-medium transition-colors",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)",color:"var(--admin-text)"},children:[(Oe=(be=Ze.find(s=>s.value===S))==null?void 0:be.label)!=null?Oe:"Sort",e.jsx(We,{size:14,style:{color:"var(--admin-text-muted)"}})]})}),e.jsx(ke,{align:"end",className:"w-44 border",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)"},children:Ze.map(s=>e.jsx(ae,{onClick:()=>Me(s.value),className:"cursor-pointer !bg-transparent hover:!bg-[var(--admin-surface-hover)] focus:!bg-[var(--admin-surface-hover)]",style:{color:S===s.value?"var(--admin-primary)":"var(--admin-text)",fontWeight:S===s.value?600:void 0},children:s.label},s.value))})]})]})})]}),R&&!c?e.jsxs("div",{className:"rounded-lg border p-8 text-center",style:{borderColor:"var(--admin-danger)",color:"var(--admin-danger)"},children:[e.jsx("p",{children:R}),e.jsx("button",{onClick:()=>ee(P,L,M),className:"mt-3 text-sm underline",style:{color:"var(--admin-primary)"},children:"Try again"})]}):e.jsxs("div",{className:"relative",children:[u&&e.jsx("div",{className:"mb-4 rounded-lg border px-4 py-3 text-sm",style:{backgroundColor:"var(--admin-info-bg, #f0f9ff)",borderColor:"var(--admin-info, #3b82f6)",color:"var(--admin-text)"},children:"Categories are assigned to you by an admin. You can edit categories assigned to you, but you cannot create new ones. Contact your account admin to request additional categories."}),e.jsx(Bt,{loading:c,columns:Ne,data:D,searchPlaceholder:"Search categories...",bulkActions:Ye,totalItems:v,pageIndex:P,pageSize:L,onPaginationChange:Re,onSearch:y,searchValue:M,emptyState:M||a!=="all"||f!=="all"?void 0:u?e.jsxs("div",{style:{padding:"24px",textAlign:"center"},children:[e.jsx("div",{style:{width:56,height:56,borderRadius:14,backgroundColor:"var(--admin-info-bg, #f0f9ff)",display:"inline-flex",alignItems:"center",justifyContent:"center",marginBottom:16,color:"var(--admin-info, #3b82f6)"},children:e.jsx(et,{size:28})}),e.jsx("h3",{style:{fontSize:18,fontWeight:600,color:"var(--admin-text, #111827)",margin:"0 0 6px"},children:"No categories assigned yet"}),e.jsx("p",{style:{fontSize:13,color:"var(--admin-text-muted, #6b7280)",margin:0,maxWidth:400,marginLeft:"auto",marginRight:"auto",lineHeight:1.5},children:"Categories must be assigned to you by an account admin. Once assigned, they will appear here and
21you'll be able to manage their content."})]}):e.jsxs("div",{style:{padding:"12px 24px 20px",textAlign:"center"},children:[e.jsx("div",{style:{width:56,height:56,borderRadius:14,backgroundColor:"var(--admin-info-bg, #f0f9ff)",display:"inline-flex",alignItems:"center",justifyContent:"center",marginBottom:16,color:"var(--admin-primary, #16a34a)"},children:e.jsx(Ct,{size:28})}),e.jsx("h3",{style:{fontSize:18,fontWeight:600,color:"var(--admin-text, #111827)",margin:"0 0 6px"},children:"Create your first category"}),e.jsx("p",{style:{fontSize:13,color:"var(--admin-text-muted, #6b7280)",margin:"0 0 14px",maxWidth:400,marginLeft:"auto",marginRight:"auto",lineHeight:1.5},children:"Categories control how your content is organized and displayed."}),e.jsxs("button",{onClick:()=>{h("/admin/content/categories/new"),Mt.track("Add Category",{source:"category_list"})},style:{display:"inline-flex",alignItems:"center",gap:6,padding:"8px 20px",borderRadius:8,border:"none",background:"var(--admin-add-gradient, linear-gradient(92.53deg, rgb(127, 228, 37) -8.94%, rgb(33, 193, 31) 97.09%))",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer"},children:[e.jsx(Ie,{size:16}),"Add Category"]}),e.jsxs("div",{style:{marginTop:20,borderTop:"1px solid var(--admin-border, #e5e7eb)",paddingTop:16,maxWidth:360,marginLeft:"auto",marginRight:"auto",textAlign:"left"},children:[e.jsx("p",{style:{fontSize:13,fontWeight:500,color:"var(--admin-text-muted, #6b7280)",marginBottom:12},children:"Once you create categories, you'll be able to:"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,color:"var(--admin-text, #111827)"},children:[e.jsx(Ue,{size:14,style:{color:"var(--admin-primary, #16a34a)",flexShrink:0}})," Organize your videos into sections"]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,color:"var(--admin-text, #111827)"},children:[e.jsx(jt,{size:14,style:{color:"var(--admin-primary, #16a34a)",flexShrink:0}})," Control what appears on your site and apps"]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,color:"var(--admin-text, #111827)"},children:[e.jsx(Be,{size:14,style:{color:"var(--admin-primary, #16a34a)",flexShrink:0}})," Help users browse and find your content"]})]})]})]})})]}),e.jsx(gt,{...Qe})]})}const Fe=["#66bb6a","#42a5f5","#fbc02d","#ef5350","#ab47bc"];function gr(t){var m;const o=new Set(t.map(h=>Number(h.id))),i=new Map;for(const h of t){const C=Number((m=h.parentId)!=null?m:0);i.has(C)||i.set(C,[]),i.get(C).push(h)}i.forEach(h=>{h.sort((C,u)=>{var I,c;
21const b=Number((I=C.partnerSortValue)!=null?I:999),v=Number((c=u.partnerSortValue)!=null?c:999);return b!==v?b-v:Number(C.id)-Number(u.id)})});let x=0;for(const[h]of i)if(!o.has(h)){x=h;break}return{childMap:i,rootParentId:x}}function kt(t,o,i,x,m){let h=i.get(t)||[];const C=m.get(t);if(C){const b=new Map(h.map(v=>[Number(v.id),v]));h=C.map(v=>b.get(v)).filter(Boolean)}const u=[];for(let b=0;b<h.length;b++){const v=h[b],I=Number(v.id),c=i.get(I)||[],N=c.length>0,R=b===h.length-1;u.push({id:I,name:v.name||"",parentId:t,depth:o,hasChildren:N,childCount:c.length,isLastChild:R}),N&&!x.has(I)&&u.push(...kt(I,o+1,i,x,m))}return u}function hr(t,o){var v,I;if(!o)return new Set;const i=o.toLowerCase(),x=new Set;for(const c of t)(c.name||"").toLowerCase().includes(i)&&x.add(Number(c.id));const m=new Map;for(const c of t)m.set(Number(c.id),Number((v=c.parentId)!=null?v:0));const h=new Map;for(const c of t){const N=Number((I=c.parentId)!=null?I:0);h.has(N)||h.set(N,[]),h.get(N).push(Number(c.id))}const C=new Set(t.map(c=>Number(c.id))),u=new Set,b=c=>{u.add(c);for(const N of h.get(c)||[])b(N)};for(const c of x){b(c);let N=c;for(;N;){u.add(N);const R=m.get(N)||0;if(!C.has(R)||R===N)break;N=R}}return u}function xr({defaultParentId:t,categories:o,onClose:i,onCreated:x}){var X,M;const m=G(y=>y.config),h=G(y=>y.token),[C,u]=n.useState(""),[b,v]=n.useState(t!=null?String(t):""),[I,c]=n.useState(!1),[N,R]=n.useState(null),$=n.useRef(null),w=((M=(X=m==null?void 0:m.config)==null?void 0:X.application)==null?void 0:M.rootCategory)||"";n.useEffect(()=>{setTimeout(()=>{var y;return(y=$.current)==null?void 0:y.focus()},50)},[]);function P(y){return!w||!y?y:y.startsWith(w+">")?y.slice(w.length+1).trim():y}const Y=n.useMemo(()=>[...o].sort((y,S)=>(y.fullName||y.name).localeCompare(S.fullName||S.name)),[o]),L=async y=>{var S,F,a,j,f;if(y.preventDefault(),!(!C.trim()||!m)){c(!0),R(null);try{const k={name:C.trim(),...b?{parentId:Number(b)}:{}};await Et(m,k,h),x(),i()}catch(k){const D=((F=(S=k==null?void 0:k.response)==null?void 0:S.data)==null?void 0:F.message)||((j=(a=k==null?void 0:k.response)==null?void 0:a.data)==null?void 0:j.error)||"";((f=k==null?void 0:k.response)==null?void 0:f.status)===500||D.toLowerCase().includes("duplicate")||D.toLowerCase().includes("already exists")?R("A category with this name already exists under the same parent."):R(Ce(k,"Failed to create category"))}finally{c(!1)}}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",style:{backgroundColor:"rgba(0,0,0,0.5)"},children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border shadow-xl",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)"},children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-5 py-4",style:{borderColor:"var(--admin-border)"},children:[e.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--admin-text)"},children:t!=null?"Add Subcategory":"Add Category"}),e.jsx("button",{type:"button",onClick:i,className:"rounded-md p-1 hover:opacity-70",style:{color:"var(--admin-text-muted)"},children:e.jsx(ze,{size:18})})]}),e.jsxs("form",{onSubmit:L,className:"p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"mb-1.5 block text-sm font-medium",style:{color:"var(--admin-text-secondary)"},children:["Category Name ",e.jsx("span",{style:{color:"var(--admin-danger)"},children:"*"})]}),e.jsx("input",{ref:$,type:"text",value:C,onChange:y=>u(y.target.value),placeholder:"Enter category name",className:"h-10 w-full rounded-lg border px-3 text-sm outline-none focus:ring-2 focus:ring-[var(--admin-primary)]",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)",color:"var(--admin-text)"},required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-sm font-medium",style:{color:"var(--admin-text-secondary)"},children:"Parent Category"}),e.jsxs("select",{value:b,onChange:y=>v(y.target.value),className:"h-10 w-full rounded-lg border px-3 text-sm outline-none focus:ring-2 focus:ring-[var(--admin-primary)]",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)",color:b?"var(--admin-text)":"var(--admin-text-muted)"},children:[e.jsx("option",{value:"",children:"None (top level)"}),Y.map(y=>e.jsx("option",{value:y.id,children:P(y.fullName||y.name)},y.id))]})]}),N&&e.jsx("p",{className:"text-xs",style:{color:"var(--admin-danger)"},children:N}),e.jsx("p",{className:"text-xs font-semibold",style:{color:"var(--admin-text-muted)"},children:"New categories will be added to the end of the tree."}),e.jsx("p",{className:"text-xs",style:{color:"var(--admin-text-muted)"},children:"For advanced settings, you can edit the category later."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx("button",{type:"button",onClick:i,className:"rounded-lg border px-4 py-2 text-sm font-medium hover:opacity-80",style:{borderColor:"var(--admin-border)",color:"var(--admin-text-secondary)",backgroundColor:"var(--admin-surface)"},children:"Cancel"}),e.jsxs("button",{type:"submit",disabled:I||!C.trim(),className:"inline-flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium disabled:opacity-50",style:{backgroundColor:"var(--admin-primary)",color:"var(--admin-primary-foreground)"},children:[I&&e.jsx(rt,{size:14,className:"animate-spin"}),"Create Category"]})]})]})]})})}function yr({node:t,categories:o,onClose:i,onMoved:x}){var S,F;const m=G(a=>a.config),h=G(a=>a.token),C=G(a=>a.adminConfig),u=G(a=>a.loadAdminConfig),b=((F=(S=m==null?void 0:m.config)==null?void 0:S.application)==null?void 0:F.rootCategory)||"",[v,I]=n.useState(""),[c,N]=n.useState(""),[R,$]=n.useState(!1),[w,P]=n.useState(null);function Y(a){return!b||!a?a:a.startsWith(b+">")?a.slice(b.length+1).trim():a}const L=n.useMemo(()=>{var f;const a=new Set([t.id]);let j=!0;for(;j;){j=!1;
21for(const k of o){const D=Number(k.id),q=Number((f=k.parentId)!=null?f:0);!a.has(D)&&a.has(q)&&(a.add(D),j=!0)}}return a},[o,t.id]),X=n.useMemo(()=>{const a=c.toLowerCase();return o.filter(j=>!L.has(Number(j.id))).filter(j=>!a||(j.fullName||j.name).toLowerCase().includes(a)).sort((j,f)=>(j.fullName||j.name).localeCompare(f.fullName||f.name))},[o,L,c]),M=(()=>{var f,k,D;const a=o.find(q=>Number(q.id)===t.id),j=((f=C!=null?C:m)==null?void 0:f.config)||{};return ir("move",{name:t.name,fullName:a==null?void 0:a.fullName},{main:(k=j.mobile)==null?void 0:k.navMenu,bottom:(D=j.mobile)==null?void 0:D.bottomNavMenu},Gt(m,C))})(),y=async()=>{var a,j;if(m){$(!0),P(null);try{const f={};v?f.parentId=Number(v):(f.parentId=Number((j=(a=o.find(D=>Number(D.id)===t.id))==null?void 0:a.parentId)!=null?j:0),f.parentId=0);const k=o.find(D=>Number(D.id)===t.id);await He(m,String(t.id),f,h);try{await yt(m,C,t.id,{name:t.name,fullName:k==null?void 0:k.fullName},h)&&await u()}catch(D){console.error("Menu update after category move failed:",D)}x(),i()}catch(f){P(Ce(f,"Failed to move category"))}finally{$(!1)}}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",style:{backgroundColor:"rgba(0,0,0,0.5)"},children:e.jsxs("div",{className:"w-full max-w-lg rounded-xl border shadow-xl",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)"},children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-5 py-4",style:{borderColor:"var(--admin-border)"},children:[e.jsx("h2",{className:"text-base font-semibold",style:{color:"var(--admin-text)"},children:"Move Category"}),e.jsx("button",{type:"button",onClick:i,className:"rounded-md p-1 hover:opacity-70",style:{color:"var(--admin-text-muted)"},children:e.jsx(ze,{size:18})})]}),e.jsxs("div",{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"rounded-lg px-4 py-3",style:{backgroundColor:"rgba(99,102,241,0.08)",borderLeft:"3px solid var(--admin-primary)"},children:[e.jsx("span",{className:"text-sm font-semibold",style:{color:"var(--admin-text-secondary)"},children:"Moving: "}),e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--admin-text)"},children:t.name})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-2 block text-sm font-semibold",style:{color:"var(--admin-text-secondary)"},children:"Move to Category:"}),e.jsxs("div",{className:"relative mb-1",children:[e.jsx(Be,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2",style:{color:"var(--admin-text-muted)"}}),e.jsx("input",{type:"text",value:c,onChange:a=>N(a.target.value),placeholder:"Search categories...",className:"w-full rounded-lg border py-2 pl-8 pr-3 text-sm outline-none focus:ring-2 focus:ring-[var(--admin-primary)]",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)",color:"var(--admin-text)"},autoFocus:!0})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto rounded-lg border",style:{borderColor:"var(--admin-border)"},children:[(!c||"root category no parent".includes(c.toLowerCase()))&&e.jsx("button",{type:"button",onClick:()=>I(""),className:"flex w-full items-center px-3 py-2.5 text-left text-sm transition-colors hover:bg-[var(--admin-surface-hover)]",style:{backgroundColor:v===""?"var(--admin-primary)":void 0,color:v===""?"var(--admin-primary-foreground)":"var(--admin-text)",fontWeight:v===""?600:400},children:"Root Category (No Parent)"}),X.map(a=>{const j=v===String(a.id),f=Y(a.fullName||a.name);return e.jsx("button",{type:"button",onClick:()=>I(String(a.id)),className:"flex w-full items-center px-3 py-2.5 text-left text-sm transition-colors hover:bg-[var(--admin-surface-hover)]",style:{backgroundColor:j?"var(--admin-primary)":void 0,color:j?"var(--admin-primary-foreground)":"var(--admin-text)",fontWeight:j?600:400},children:f},a.id)}),X.length===0&&c&&e.jsx("div",{className:"px-3 py-4 text-center text-sm",style:{color:"var(--admin-text-muted)"},children:"No categories found"})]}),e.jsx("p",{className:"mt-1.5 text-xs",style:{color:"var(--admin-text-muted)"},children:"Select where to move this category. It will be placed at the end of the target category."})]}),M.warning&&e.jsxs("p",{className:"flex items-start gap-1.5 text-xs",style:{color:"var(--admin-warning, #d97706)"},children:[e.jsx(lr,{size:12,className:"mt-0.5 shrink-0"})," ",M.warning]}),w&&e.jsx("p",{className:"text-xs",style:{color:"var(--admin-danger)"},children:w}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx("button",{type:"button",onClick:i,className:"rounded-lg border px-4 py-2 text-sm font-medium hover:opacity-80",style:{borderColor:"var(--admin-border)",color:"var(--admin-text-secondary)",backgroundColor:"var(--admin-surface)"},children:"Cancel"}),e.jsxs("button",{type:"button",onClick:y,disabled:R,className:"inline-flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium disabled:opacity-50",style:{backgroundColor:"var(--admin-primary)",color:"var(--admin-primary-foreground)"},children:[R?e.jsx(rt,{size:14,className:"animate-spin"}):e.jsx(St,{size:14}
21),"Move Category"]})]})]})]})})}const br=()=>!1;function vr({name:t,query:o}){if(!o)return e.jsx(e.Fragment,{children:t});const i=t.toLowerCase().indexOf(o.toLowerCase());return i===-1?e.jsx(e.Fragment,{children:t}):e.jsxs(e.Fragment,{children:[t.slice(0,i),e.jsx("strong",{style:{fontWeight:700},children:t.slice(i,i+o.length)}),t.slice(i+o.length)]})}function Cr({node:t,isOver:o,collapsed:i,onToggle:x,isSearchMatch:m,parentName:h,showParentContext:C,searchQuery:u,onAddChild:b,onMove:v,onDelete:I,onNameTap:c,rowRefCallback:N,ancestorIsLast:R}){const{attributes:$,listeners:w,setNodeRef:P,transform:Y,transition:L,isDragging:X}=ar({id:t.id,animateLayoutChanges:br}),M=t.depth*24,y={transform:sr.Transform.toString(Y),transition:L!=null?L:void 0,opacity:X?.3:1,borderColor:"var(--admin-border)",borderTopWidth:o?"2px":void 0,borderTopColor:o?"#4cf3d1":void 0,borderTopStyle:o?"solid":void 0,backgroundColor:X?"var(--admin-surface-hover)":void 0},S=i.has(t.id);return e.jsxs("div",{ref:F=>{P(F),N(t.id,F)},style:y,className:["group flex items-center border-b text-sm transition-colors hover:bg-[var(--admin-surface-hover)]",m?"bg-[rgba(99,102,241,0.06)]":""].join(" "),children:[e.jsx("button",{type:"button",className:"shrink-0 cursor-grab touch-none opacity-40 active:cursor-grabbing px-1",style:{color:"var(--admin-text-muted)"},...w,...$,tabIndex:-1,children:e.jsx(Nt,{size:14})}),e.jsx("div",{className:"flex shrink-0 self-stretch",style:{width:`${M}px`},children:Array.from({length:t.depth},(F,a)=>{var D;const j=(D=R[a])!=null?D:!1,f=a===t.depth-1,k=Fe[a%Fe.length];return e.jsx("div",{className:"relative shrink-0 self-stretch",style:{width:"24px"},children:f?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute",style:{top:0,bottom:t.isLastChild&&!(t.hasChildren&&!i.has(t.id))?"50%":0,left:"11px",width:"1px",backgroundColor:k}}),e.jsx("div",{className:"absolute",style:{top:"50%",left:"11px",width:"10px",height:"1px",backgroundColor:k}})]}):a===0&&!j?(()=>{const q=Fe[a%Fe.length];return t.isLastChild&&R.slice(a+1).every(Boolean)&&!(t.hasChildren&&!i.has(t.id))?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute",style:{top:0,bottom:"50%",left:"11px",width:"1px",backgroundColor:q}}),e.jsx("div",{className:"absolute",style:{top:"50%",left:"11px",width:"10px",height:"1px",backgroundColor:q}})]}):e.jsx("div",{className:"absolute",style:{top:0,bottom:0,left:"11px",width:"1px",backgroundColor:q}})})():null},a)})}),e.jsx("button",{type:"button",onClick:()=>t.hasChildren&&x(t.id),className:"flex h-5 w-5 shrink-0 items-center justify-center rounded",style:{color:t.hasChildren?"var(--admin-text-secondary)":"transparent",cursor:t.hasChildren?"pointer":"default"},tabIndex:-1,children:t.hasChildren?S?e.jsx(Dt,{size:14,strokeWidth:2.5}):e.jsx(We,{size:14,strokeWidth:2.5}):null}),e.jsxs("div",{className:"flex items-center gap-1 py-[5px] pl-0.5 pr-1",children:[e.jsx("span",{className:"truncate",style:{color:t.depth===0?"var(--admin-text)":"var(--admin-text-secondary)",fontWeight:t.depth===0?600:t.hasChildren?500:400,fontSize:t.depth===0?"13.5px":"13px"},title:t.name,onClick:F=>c(t.name,F.clientX,F.clientY),children:e.jsx(vr,{name:t.name,query:u||""})}),t.childCount>0&&e.jsxs("span",{className:"shrink-0 text-[11px]",style:{color:"var(--admin-text-muted)"},children:["(",t.childCount,")"]}),C&&h&&e.jsxs("span",{className:"hidden md:inline shrink-0 text-xs",style:{color:"var(--admin-text-muted)"},children:["in ",h]}),e.jsxs(Se,{children:[e.jsx(we,{asChild:!0,children:e.jsx("button",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded hover:bg-[var(--admin-border-light)]",style:{color:"var(--admin-text-muted)"},children:e.jsx(bt,{size:15})})}),e.jsxs(ke,{align:"start",className:"w-44 border",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)"},children:[e.jsx(ae,{asChild:!0,className:"cursor-pointer !bg-transparent hover:!bg-[var(--admin-surface-hover)] focus:!bg-[var(--admin-surface-hover)]",style:{color:"var(--admin-text)"},children:e.jsxs(tt,{to:`/admin/content/categories/${t.id}`,className:"flex items-center gap-2",children:[e.jsx(vt,{size:14})," Edit"]})}),e.jsxs(ae,{className:"flex items-center gap-2 cursor-pointer !bg-transparent hover:!bg-[var(--admin-surface-hover)] focus:!bg-[var(--admin-surface-hover)]",style:{color:"var(--admin-text)"},onClick:()=>b(t.id),children:[e.jsx(Ie,{size:14})," Add Subcategory"]}),e.jsxs(ae,{className:"flex items-center gap-2 cursor-pointer !bg-transparent hover:!bg-[var(--admin-surface-hover)] focus:!bg-[var(--admin-surface-hover)]",style:{color:"var(--admin-text)"},onClick:()=>v(t),children:[e.jsx(St,{size:14})," Move to"]}),e.jsxs(ae,{className:"flex items-center gap-2 cursor-pointer !bg-transparent hover:!bg-[var(--admin-surface-hover)] focus:!bg-[var(--admin-surface-hover)]",style:{color:"var(--admin-danger, #dc2626)"},onClick:()=>I(t),children:[e.jsx(Je,{size:14})," Delete"]})]})]})]})]})}
21function jr({node:t}){return e.jsxs("div",{className:"flex items-center gap-1.5 border-b py-[5px] px-2.5 text-[13px]",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)",color:"var(--admin-text)",boxShadow:"0 4px 12px rgba(0,0,0,0.12)",cursor:"grabbing"},children:[e.jsx(Nt,{size:14,style:{color:"var(--admin-text-muted)",flexShrink:0,opacity:.5}}),e.jsx("span",{className:"truncate font-medium",children:t.name}),t.childCount>0&&e.jsxs("span",{className:"shrink-0 text-[11px]",style:{color:"var(--admin-text-muted)"},children:["(",t.childCount,")"]})]})}const Nr=n.forwardRef(function(o,i){const x=G(r=>r.config),m=G(r=>r.token),h=G(r=>r.adminConfig),C=G(r=>r.loadAdminConfig),[u,b]=n.useState([]),[v,I]=n.useState(new Set),[c,N]=n.useState(new Set),[R,$]=n.useState(new Map),[w,P]=n.useState(!0),[Y,L]=n.useState(!1),[X,M]=n.useState(!1),y=n.useRef(),[S,F]=n.useState(null),[a,j]=n.useState(""),[f,k]=n.useState(void 0),[D,q]=n.useState(!1),[xe,Te]=n.useState(null),[Z,ue]=n.useState(null),[ee,Me]=n.useState(null),_e=n.useCallback((r,l,d)=>{Me({name:r,x:l,y:d})},[]),[je,Ae]=n.useState(null),[Qe,pe]=n.useState(null),Ge=n.useRef(0),Re=n.useRef(new Map),Ne=n.useRef(null),[Ye,Pe]=n.useState(()=>localStorage.getItem("categoryTreeHintDismissed")!=="1"),Le=n.useCallback(({transform:r,draggingNodeRect:l})=>{if(!Ne.current||!l)return r;const d=Ne.current.getBoundingClientRect(),z=d.top-l.top,A=d.bottom-l.bottom,E=d.left-l.left,O=d.right-l.right;return{...r,x:Math.max(E,Math.min(r.x,O)),y:Math.max(z,Math.min(r.y,A))}},[]),De=n.useCallback((r,l)=>{l?Re.current.set(r,l):Re.current.delete(r)},[]);n.useEffect(()=>{const r=l=>{Ge.current=l.clientY};return window.addEventListener("pointermove",r),()=>window.removeEventListener("pointermove",r)},[]);const Ee=qt(ot(Xt,{activationConstraint:{distance:8}}),ot(Kt)),ce=n.useCallback(async()=>{var r;if(x)try{P(!0),F(null);const l=await Ve(x,m,{filter:{},pager:{pageIndex:1,pageSize:500}});let d=l.data||[];const z=((r=l.meta)==null?void 0:r.total)||0;if(z>500){const A=Math.ceil(z/500),E=await Promise.all(Array.from({length:A-1},(O,V)=>Ve(x,m,{filter:{},pager:{pageIndex:V+2,pageSize:500}})));for(const O of E)d=d.concat(O.data||[])}b(d),$(new Map)}catch(l){F(Ce(l,"Failed to load categories"))}finally{P(!1)}},[x,m]);n.useEffect(()=>{ce()},[ce]);const{childMap:ne,rootParentId:fe}=n.useMemo(()=>gr(u),[u]),ye=n.useMemo(()=>hr(u,a),[u,a]),be=n.useMemo(()=>{if(!a)return new Set;const r=a.toLowerCase(),l=new Set;for(const d of u)(d.name||"").toLowerCase().includes(r)&&l.add(Number(d.id));return l},[u,a]),Oe=n.useMemo(()=>{var l;const r=new Map;for(const d of u){const z=Number((l=d.parentId)!=null?l:0),A=u.find(E=>Number(E.id)===z);A&&r.set(Number(d.id),A.name||"")}return r},[u]),s=n.useRef("");s.current!==a&&(s.current=a,N(new Set));const g=n.useMemo(()=>{if(a){const r=[],l=(d,z)=>{const A=(ne.get(d)||[]).filter(E=>ye.has(Number(E.id)));for(let E=0;E<A.length;E++){const O=A[E],V=Number(O.id),me=(ne.get(V)||[]).filter(ge=>ye.has(Number(ge.id))).length>0,re=ne.get(V)||[],Q=E===A.length-1;r.push({id:V,name:O.name||"",parentId:d,depth:z,hasChildren:me,childCount:re.length,isLastChild:Q}),me&&!c.has(V)&&l(V,z+1)}};return l(fe,0),r}return kt(fe,0,ne,v,R)},[u,ne,fe,v,c,a,ye,R]),p=r=>{a?N(l=>{const d=new Set(l);return d.has(r)?d.delete(r):d.add(r),d}):I(l=>{const d=new Set(l);return d.has(r)?d.delete(r):d.add(r),d})},K=()=>{var d;const r=new Set(u.map(z=>Number(z.id))),l=new Set;for(const z of u){const A=Number((d=z.parentId)!=null?d:0);r.has(A)&&l.add(A)}I(l)},te=()=>I(new Set),J=r=>{k(r),q(!0)};n.useImperativeHandle(i,()=>({openQuickAdd:()=>J()}));const oe=async()=>{if(!(!x||!Z))try{await ft(x,String(Z.id),m),ue(null),ce()}catch(r){F(Ce(r,"Failed to delete category")),ue(null)}},ie=({active:r})=>{Ae(r.id),pe(null)},se=({active:r,over:l})=>{if(!l||r.id===l.id){pe(null);return}pe(l.id)},H=({active:r,over:l})=>{if(Ae(null),pe(null),!l||r.id===l.id)return;const d=Number(r.id),z=Number(l.id),A=g,E=A.find(T=>T.id===d),O=A.find(T=>T.id===z);if(!E||!O)return;const V=T=>R.get(T)||(ne.get(T)||[]).map(W=>Number(W.id)),ve=new Map(u.map(T=>[Number(T.id),T])),me=T=>{var W,U;return Number((U=(W=ve.get(T))==null?void 0:W.partnerSortValue)!=null?U:0)},re=(T,W)=>{const U=W>0?me(T[W-1]):null,B=W<T.length-1?me(T[W+1]):null;return U===null&&B===null?0:U===null?B-1:B===null?U+1:B-U>=2?Math.floor((U+B)/2):U+1},Q=O.parentId,ge=E.parentId;let he;if(ge===Q){const T=V(Q),W=T.indexOf(d),U=T.indexOf(z);if(W===-1||U===-1)return;const B=nr(T,W,U);$(de=>{const st=new Map(de);return st.set(Q,B),st}),he=re(B,B.indexOf(d))}
21else{const T=V(ge).filter(B=>B!==d),W=V(Q).filter(B=>B!==d),U=W.indexOf(z);U===-1?W.push(d):W.splice(U,0,d),$(B=>{const de=new Map(B);return de.set(ge,T),de.set(Q,W),de}),b(B=>B.map(de=>Number(de.id)===d?{...de,parentId:Q}:de)),he=re(W,W.indexOf(d))}const zt={id:d,parentId:Q===fe?null:Q,partnerSortValue:he};L(!0);const qe=ge!==Q?ve.get(d):void 0;He(x,String(d),zt,m).then(async()=>{if(qe)try{await yt(x,h,d,{name:qe.name,fullName:qe.fullName},m)&&await C()}catch(T){console.error("Menu update after category move failed:",T)}M(!0),clearTimeout(y.current),y.current=setTimeout(()=>M(!1),2e3)}).catch(T=>F(Ce(T,"Failed to save"))).finally(()=>L(!1))},le=n.useMemo(()=>{const r=new Map,l=[];for(const d of g){for(;l.length>d.depth;)l.pop();r.set(d.id,[...l]),l[d.depth]=d.isLastChild}return r},[g]),_=je?g.find(r=>r.id===Number(je)):null;return e.jsxs("div",{className:"mx-auto max-w-4xl",children:[e.jsx(or,{saving:Y,saved:X,error:S}),S&&e.jsx("div",{className:"mb-4 rounded-lg border px-4 py-3 text-sm",style:{borderColor:"var(--admin-danger)",color:"var(--admin-danger)",backgroundColor:"var(--admin-danger-bg, #fef2f2)"},children:S}),w?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(rt,{size:32,className:"animate-spin",style:{color:"var(--admin-primary)"}})}):e.jsxs("div",{className:"rounded-xl border",style:{backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)"},children:[e.jsxs("div",{className:"flex flex-col gap-2 border-b px-4 py-3 md:flex-row md:items-center",style:{borderColor:"var(--admin-border)"},children:[e.jsxs("div",{className:"relative w-full md:flex-1",children:[e.jsx(Be,{size:14,className:"absolute left-2.5 top-1/2 -translate-y-1/2",style:{color:"var(--admin-text-muted)"}}),e.jsx("input",{type:"text",value:a,onChange:r=>j(r.target.value),placeholder:"Search categories...",className:"w-full rounded-lg border bg-transparent py-1.5 pl-8 pr-8 text-sm outline-none focus:ring-1 focus:ring-[var(--admin-primary)]",style:{borderColor:"var(--admin-border)",color:"var(--admin-text)"}}),a&&e.jsx("button",{type:"button",onClick:()=>j(""),className:"absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 hover:opacity-70",style:{color:"var(--admin-text-muted)"},children:e.jsx(ze,{size:13})})]}),!a&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:te,className:"inline-flex items-center gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs font-medium hover:opacity-80",style:{borderColor:"var(--admin-border)",color:"var(--admin-text-secondary)",backgroundColor:"var(--admin-surface)"},children:[e.jsx(mr,{size:13})," Expand all"]}),e.jsxs("button",{type:"button",onClick:K,className:"inline-flex items-center gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs font-medium hover:opacity-80",style:{borderColor:"var(--admin-border)",color:"var(--admin-text-secondary)",backgroundColor:"var(--admin-surface)"},children:[e.jsx(cr,{size:13})," Collapse all"]})]}),a&&e.jsxs("span",{className:"shrink-0 text-xs",style:{color:"var(--admin-text-muted)"},children:[be.size," result",be.size!==1?"s":""]})]}),Ye&&g.length>0&&e.jsxs("div",{className:"flex items-start gap-3 border-b px-4 py-3 text-[13px]",style:{borderColor:"var(--admin-border)",backgroundColor:"var(--admin-surface-hover, rgba(99,102,241,0.04))"},children:[e.jsxs("span",{style:{color:"var(--admin-text-secondary)"},children:[e.jsx("strong",{style:{color:"var(--admin-text)"},children:"Drag"})," to reorder categories within the same level. To move a category under another category, use ",e.jsx("strong",{style:{color:"var(--admin-text)"},children:"Move To"})," from the menu."]}),e.jsx("button",{type:"button",onClick:()=>{Pe(!1),localStorage.setItem("categoryTreeHintDismissed","1")},className:"ml-auto shrink-0 rounded p-0.5 hover:opacity-70",style:{color:"var(--admin-text-muted)"},children:e.jsx(ze,{size:13})})]}),g.length===0?a?e.jsxs("div",{className:"p-12 text-center",children:[e.jsx(Pt,{size:40,className:"mx-auto mb-3",style:{color:"var(--admin-text-muted)"}}),e.jsx("p",{className:"text-sm",style:{color:"var(--admin-text-muted)"},children:"No categories match your search."})]}):e.jsxs("div",{style:{padding:"12px 24px 20px",textAlign:"center"},children:[e.jsx("div",{style:{width:56,height:56,borderRadius:14,backgroundColor:"var(--admin-info-bg, #f0f9ff)",display:"inline-flex",alignItems:"center",justifyContent:"center",marginBottom:16,color:"var(--admin-primary, #16a34a)"},children:e.jsx(Ct,{size:28})}),e.jsx("h3",{style:{fontSize:18,fontWeight:600,color:"var(--admin-text, #111827)",margin:"0 0 6px"},children:"Create your first category"}),e.jsx("p",{style:{fontSize:13,color:"var(--admin-text-muted, #6b7280)",margin:"0 0 14px",maxWidth:400,marginLeft:"auto",marginRight:"auto",lineHeight:1.5},children:"Categories control how your content is organized and displayed."}),e.jsxs("button",{onClick:()=>J(),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"8px 20px",borderRadius:8,border:"none",background:"var(--admin-add-gradient, linear-gradient(92.53deg, rgb(127, 228, 37) -8.94%, rgb(33, 193, 31) 97.09%))",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer"},children:[e.jsx(Ie,{size:16}),"Add Category"]}),e.jsxs("div",{style:{marginTop:20,borderTop:"1px solid var(--admin-border, #e5e7eb)",paddingTop:16,maxWidth:360,marginLeft:"auto",marginRight:"auto",textAlign:"left"},children:[e.jsx("p",{style:{fontSize:13,fontWeight:500,color:"var(--admin-text-muted, #6b7280)",marginBottom:12},children:"Once you create categories, you'll be able to:"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,color:"var(--admin-text, #111827)"},children:[e.jsx(Ue,{size:14,style:{color:"var(--admin-primary, #16a34a)",flexShrink:0}})," Organize your videos into sections"]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,color:"var(--admin-text, #111827)"},children:[e.jsx(jt,{size:14,style:{color:"var(--admin-primary, #16a34a)",flexShrink:0}})," Control what appears on your site and apps"]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,color:"var(--admin-text, #111827)"},children:[e.jsx(Be,{size:14,style:{color:"var(--admin-primary, #16a34a)",flexShrink:0}})," Help users browse and find your content"]})]})]})]}):e.jsx("div",{className:"px-2 py-1",ref:Ne,children:e.jsxs(Zt,{sensors:Ee,collisionDetection:Jt,modifiers:[Le],onDragStart:ie,onDragOver:se,onDragEnd:H,children:[e.jsx(er,{items:g.map(r=>r.id),strategy:tr,children:e.jsx("div",{children:g.map(r=>e.jsx(Cr,{node:r,isOver:Qe===r.id,collapsed:a?c:v,onToggle:p,isSearchMatch:be.has(r.id),parentName:Oe.get(r.id),showParentContext:!!a&&r.depth>0,searchQuery:a,onAddChild:J,onMove:Te,onDelete:ue,onNameTap:_e,rowRefCallback:De,ancestorIsLast:le.get(r.id)||[]},r.id))})}),e.jsx(rr,{dropAnimation:null,children:_?e.jsx(jr,{node:_}):null})]})})]}),xe&&e.jsx(yr,{node:xe,categories:u,onClose:()=>Te(null),onMoved:ce}),D&&e.jsx(xr,{defaultParentId:f,categories:u,onClose:()=>q(!1),onCreated:ce}),e.jsx(gt,{open:!!Z,title:"Delete category?",description:`"${Z==null?void 0:Z.name}
21" will be permanently removed. This can't be undone.`,details:ht,check:()=>{const r=u.find(l=>Number(l.id)===Z.id);return xt(x,h,[{id:Z.id,name:Z.name,fullName:r==null?void 0:r.fullName}],m)},onConfirm:oe,onCancel:()=>ue(null)}),ee&&Lt.createPortal(e.jsxs("div",{className:"fixed z-50 max-w-[260px] rounded-xl border shadow-xl px-4 py-3 text-sm",style:{top:Math.max(8,ee.y-16),left:Math.min(ee.x,window.innerWidth-276),transform:"translateY(-100%)",backgroundColor:"var(--admin-surface)",borderColor:"var(--admin-border)",color:"var(--admin-text)"},children:[e.jsx("button",{type:"button",onClick:()=>Me(null),className:"absolute right-2 top-2 rounded p-0.5 hover:opacity-70",style:{color:"var(--admin-text-muted)"},children:e.jsx(ze,{size:14})}),e.jsx("p",{className:"pr-5 font-medium leading-snug",children:ee.name})]}),document.body)]})}),Sr=Nr,ct={categories:"/admin/content/categories","category-tree":"/admin/content/category-tree"};function wr(t){return t.includes("/category-tree")?"category-tree":"categories"}function ra(){const t=ut(),o=mt(),i=wr(o.pathname),{getActiveGuard:x}=Vt(),m=n.useRef(null),h=G(c=>c.config),C=pt(h),u=C==="contributorRole",[b,v]=n.useState(0),I=c=>{const N=x();if(N){N.requestNavigate(ct[c]);return}t(ct[c])};return e.jsxs("div",{children:[e.jsx(Ft,{title:"Categories",description:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[u?"Your categories":"Manage categories and content organization",b>0?` (${b.toLocaleString()} total)`:"",(C==="adminRole"||C==="rootRole")&&e.jsxs("a",{href:`${Ot}/api/export?format=csv&type=category`,className:"ml-1 inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-sm font-medium opacity-90 hover:opacity-100 transition-opacity",style:{color:"var(--admin-text)",borderColor:"var(--admin-border)"},download:!0,children:[e.jsx(dr,{size:15}),"Export CSV"]})]}),actions:u?void 0:i==="categories"?e.jsxs(tt,{to:"/admin/content/categories/new",className:"inline-flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium transition-colors hover:opacity-90",style:{background:"var(--admin-add-gradient, linear-gradient(92.53deg, rgb(127, 228, 37) -8.94%, rgb(33, 193, 31) 97.09%))",color:"#fff"},children:[e.jsx(Ie,{size:16})," Add Category"]}):e.jsxs("button",{type:"button",onClick:()=>{var c;return(c=m.current)==null?void 0:c.openQuickAdd()},className:"inline-flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium transition-colors hover:opacity-90",style:{background:"var(--admin-add-gradient, linear-gradient(92.53deg, rgb(127, 228, 37) -8.94%, rgb(33, 193, 31) 97.09%))",color:"#fff"},children:[e.jsx(Ie,{size:16})," Add Category"]})}),!u&&e.jsx(Wt,{tabs:[{key:"categories",label:"Categories",icon:e.jsx(Ue,{size:14})},{key:"category-tree",label:"Category Tree",icon:e.jsx(et,{size:14})}],activeTab:i,onChange:I}),(u||i==="categories")&&e.jsx(fr,{onTotalChange:v}),!u&&i==="category-tree"&&e.jsx(Sr,{ref:m})]})}export{ra as default};
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.