1import{r as o,j as e,g as Le,h as De,i as ce,k as Ee,D as ie,l as de,m as xe,n as me,o as V,p as H,q,s as K,t as j,f as w,L as N,u as _,v as Ie,w as Oe,C as Ae,x as Ge}from"./index-D3Di9rth.js";import{C as te}from"./checkbox-beSo7t1v.js";import{C as X}from"./ConfirmDialog-QAS5aQot.js";import{P as Re}from"./plus-D6t-Yt8c.js";import{U as $}from"./upload-BOeqcQdb.js";import{D as J}from"./download-DCzeficB.js";import{C as Ue}from"./circle-x-DLXeRR07.js";import{C as Pe}from"./circle-check-Bv8mKxoS.js";import{R as be}from"./refresh-cw-CoFwkxTG.js";import{G as Me}from"./globe-D-qUthaL.js";const Q=[{code:"en",label:"English (US)"},{code:"fr",label:"French"},{code:"es",label:"Spanish"},{code:"de",label:"German"},{code:"it",label:"Italian"},{code:"pt",label:"Portuguese"},{code:"ru",label:"Russian"},{code:"pl",label:"Polish"},{code:"uk",label:"Ukrainian"},{code:"cs",label:"Czech"},{code:"bg",label:"Bulgarian"},{code:"ro",label:"Romanian"},{code:"sr",label:"Serbian"},{code:"nl",label:"Dutch"},{code:"sv",label:"Swedish"},{code:"nb",label:"Norwegian"},{code:"da",label:"Danish"},{code:"fi",label:"Finnish"},{code:"is",label:"Icelandic"},{code:"el",label:"Greek"},{code:"tr",label:"Turkish"},{code:"hu",label:"Hungarian"},{code:"sk",label:"Slovak"},{code:"sl",label:"Slovenian"},{code:"lt",label:"Lithuanian"},{code:"hi",label:"Hindi"},{code:"bn",label:"Bengali"},{code:"gu",label:"Gujarati"},{code:"pa",label:"Punjabi"},{code:"mr",label:"Marathi"},{code:"ur",label:"Urdu"},{code:"ta",label:"Tamil"},{code:"te",label:"Telugu"},{code:"kn",label:"Kannada"},{code:"ml",label:"Malayalam"},{code:"ne",label:"Nepali"},{code:"dv",label:"Dhivehi (Maldivian)"},{code:"zh-Hans",label:"Chinese (Simplified)"},{code:"zh-Hant",label:"Chinese (Traditional)"},{code:"ja",label:"Japanese"},{code:"ko",label:"Korean"},{code:"th",label:"Thai"},{code:"vi",label:"Vietnamese"},{code:"id",label:"Indonesian"},{code:"ms",label:"Malay"},{code:"az",label:"Azerbaijani"},{code:"uz",label:"Uzbek"},{code:"mn",label:"Mongolian"},{code:"my",label:"Burmese (Myanmar)"},{code:"am",label:"Amharic"},{code:"ps",label:"Pashto"},{code:"so",label:"Somali"},{code:"ha",label:"Hausa"},{code:"sw",label:"Swahili"},{code:"jv",label:"Javanese"},{code:"ar",label:"Arabic"},{code:"fil",label:"Filipino"},{code:"he",label:"Hebrew"},{code:"fa",label:"Persian"},{code:"pcm",label:"Nigerian Pidgin"}],B=[{key:"names-people",label:"Names â People",category:"names",subCategory:"standard",showGender:!0},{key:"names-animals",label:"Names â Animals",category:"names",subCategory:"animals",showGender:!1},{key:"countries",label:"Countries",category:"countries",subCategory:"standard",showGender:!1},{key:"hobbies",label:"Hobbies",category:"hobbies",subCategory:"standard",showGender:!1},{key:"words",label:"Words",category:"words",subCategory:"standard",showGender:!1},{key:"dates",label:"Dates (Events)",category:"dates",subCategory:"standard",showGender:!1}];function Fe(s,g=!1){const[i,c]=o.useState(()=>{try{const t=localStorage.getItem(s);return t!==null?JSON.parse(t):g}catch{return g}});return[i,()=>c(t=>{const l=!t;try{localStorage.setItem(s,JSON.stringify(l))}catch{}return l})]}function _e(s){const g=s.toLowerCase().trim(),i=Q.find(c=>c.code.toLowerCase()===g);return i?i.code:g}function ue(s){const g=s.replace(/^\uFEFF/,"").trim();if(!g)return{headers:[],rows:[]};const i=g.split(/\r?\n/);if(i.length<2)return{headers:[],rows:[]};const c=l=>{const b=[];let d="",p=!1;for(let n=0;n<l.length;n++){const m=l[n];p?m==='"'&&l[n+1]==='"'?(d+='"',n++):m==='"'?p=!1:d+=m:m==='"'?p=!0:m===","?(b.push(d.trim()),d=""):d+=m}return b.push(d.trim()),b},x=c(i[0]).map(l=>_e(l)),t=[];for(let l=1;l<i.length;l++){if(!i[l].trim())continue;const b=c(i[l]),d={};x.forEach((p,n)=>{b[n]&&(d[p]=b[n])}),Object.values(d).some(Boolean)&&t.push(d)}return{headers:x,rows:t}}function $e(s){try{const g=JSON.parse(s);if(Array.isArray(g))return g.map(i=>String(i).trim()).filter(Boolean)}catch{}return s.split(",").map(g=>g.trim()).filter(Boolean)}function Je(s){const g=s.filter(t=>t.entryIndex!=null),i=s.filter(t=>t.entryIndex==null),c=new Map;for(const t of g)c.has(t.entryIndex)||c.set(t.entryIndex,{}),c.get(t.entryIndex)[t.language]=t.text;const x=[...c.entries()].sort(([t],[l])=>t-l).map(([,t])=>t);for(const t of i)x.push({[t.language]:t.text});return x.sort((t,l)=>{const b=t.en??Object.values(t)[0]??"",d=l.en??Object.values(l)[0]??"";return b.localeCompare(d,void 0,{sensitivity:"base"})}),x}function Be(s){if(s.length===0)return"";const i=[...new Set(s.flatMap(t=>Object.keys(t)))].sort((t,l)=>
1t==="en"?-1:l==="en"?1:t.localeCompare(l)),c=t=>t?t.includes(",")||t.includes('"')||t.includes(` 2`)?`"${t.replace(/"/g,'""')}"`:t:"",x=[i.join(",")];for(const t of s)x.push(i.map(l=>c(t[l]??"")).join(","));return x.join(` 3`)}function ge(s,g,i){const c=new Blob([s],{type:i}),x=URL.createObjectURL(c),t=document.createElement("a");t.href=x,t.download=g,document.body.appendChild(t),t.click(),document.body.removeChild(t),URL.revokeObjectURL(x)}function Ve({tab:s,refreshKey:g}){const[i,c]=Fe(`admin-textdata-coverage-${s.key}`,!0),[x,t]=o.useState(null),[l,b]=o.useState(!1),d=o.useCallback(async()=>{b(!0);try{const n={category:s.category};s.subCategory!==null&&(n.subCategory=s.subCategory??"null");const m=await w.get("/api/admin/text-data/coverage",{params:n,withCredentials:!0});t(m.data)}catch{}finally{b(!1)}},[s]);o.useEffect(()=>{!i&&!x&&d()},[i,x,d]),o.useEffect(()=>{g&&!i&&d()},[g]);const p=x?Object.fromEntries(x.byLanguage.map(n=>[n.language,n])):{};return e.jsxs("div",{className:"bg-card-dark border border-border-dark rounded-2xl overflow-hidden",children:[e.jsxs("button",{onClick:c,className:"w-full flex items-center justify-between px-4 py-3 text-sm font-semibold text-white hover:bg-white/5 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Me,{size:15,className:"text-accent"}),"Language Coverage",x&&e.jsxs("span",{className:"text-xs font-normal text-gray-400 ml-1",children:[x.byLanguage.length," / ",Q.length," languages · ",x.reference.toLocaleString()," EN entries"]})]}),i?e.jsx(Ae,{size:15,className:"text-gray-400"}):e.jsx(Ge,{size:15,className:"text-gray-400"})]}),!i&&e.jsxs("div",{className:"border-t border-border-dark p-4",children:[l?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(N,{size:18,className:"animate-spin text-gray-400"})}):x?e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-1.5",children:Q.map(n=>{const m=p[n.code],L=(m==null?void 0:m.count)??0,C=(m==null?void 0:m.coverage)??0,k=C>=100?"text-green-400 border-green-500/30 bg-green-500/5":C>0?"text-yellow-400 border-yellow-500/30 bg-yellow-500/5":"text-gray-500 border-border-dark bg-transparent";return e.jsxs("div",{className:`flex items-center justify-between px-2.5 py-1.5 rounded-lg border text-xs ${k}`,children:[e.jsx("span",{className:"truncate mr-1",children:n.label}),e.jsx("span",{className:"shrink-0 tabular-nums",children:L>0?L.toLocaleString():"â"})]},n.code)})}):null,x&&e.jsxs("button",{onClick:d,disabled:l,className:"mt-3 flex items-center gap-1.5 text-xs text-gray-400 hover:text-white hover:bg-white/5 border border-border-dark px-3 py-1.5 rounded-lg transition-all active:scale-95 disabled:opacity-40",children:[e.jsx(be,{size:12,className:l?"animate-spin":""}),"Refresh"]})]})]})}function He({tab:s}){const[g,i]=o.useState([]),[c,x]=o.useState(0),[t,l]=o.useState(1),[b,d]=o.useState(!1),[p,n]=o.useState(new Set),[m,L]=o.useState("multi"),[C,k]=o.useState(""),[U,W]=o.useState("en"),[R,r]=o.useState("none"),[f,O]=o.useState(""),[h,A]=o.useState(null),[Y,pe]=o.useState("none"),[P,M]=o.useState(!1),[S,ae]=o.useState(!1),[D,E]=o.useState(null),[fe,se]=o.useState(!1),[ye,re]=o.useState(0),[T,I]=o.useState(null),Z=Math.ceil(c/50),v=o.useCallback(async(a=1)=>{d(!0);try{const u={category:s.category,page:a};s.subCategory!==null&&(u.subCategory=s.subCategory??"null");const y=await w.get("/api/admin/text-data",{params:u,withCredentials:!0});i(y.data.items),x(y.data.total),l(a),n(new Set)}catch{}finally{d(!1)}},[s]);o.useEffect(()=>{v(1)},[v]);const le=c>0&&p.size===c,je=async()=>{if(le){n(new Set);return}se(!0);try{const a={category:s.category,page:1,limit:1e5};s.subCategory!==null&&(a.subCategory=s.subCategory??"null");const u=await w.get("/api/admin/text-data",{params:a,withCredentials:!0});n(new Set(u.data.items.map(y=>y._id)))}catch{}finally{se(!1)}},we=a=>{const u=new Set(p);u.has(a)?u.delete(a):u.add(a),n(u)},ve=async a=>{d(!0);try{await w.delete(`/api/admin/text-data/${a}`,{withCredentials:!0})}catch{d(!1);return}v(t)},Ne=async()=>{d(!0);try{await w.delete("/api/admin/text-data/bulk",{data:{ids:[...p]},withCredentials:!0})}catch{d(!1);return}v(1)},Ce=async()=>{d(!0);try{const u=(await w.get("/api/admin/text-data",{params:{category:s.category,...s.subCategory!==null?{subCategory:s.subCategory}:{},page:1,limit:1e5},withCredentials:!0})).data.items.map(y=>y._id);u.length>0&&await w.delete("/api/admin/text-data/bulk",{data:{ids:u},withCredentials:!0})}catch{d(!1);return}v(1)},F=async a=>{ae(!0);try{const u={category:s.category};s.subCategory!==null&&(u.subCategory=s.subCategory??"null");const y=await w.get("/api/admin/text-data/export",{params:u,withCredentials:!0}),z=Je(y.data.items),G=s.key;if(a==="csv"){const ee=Be(z);ge(ee,`${G}.csv`,"text/csv;charset=utf-8;")}else{const ee=JSON.stringify(z,null,2);ge(ee,`${G}.json`,"application/json")}}catch{alert("Export failed")}finally{ae(!1)}},ke=async()=>{const a=$e(C);if(a.length!==0){M(!0),E(null);try{const u=a.map(z=>({text:z,category:s.category,subCategory:s.subCategory,language:U,gender:R==="none"?null:R})),y=await w.post("/api/admin/text-data/bulk",{items:u},{withCredentials:!0});E({mode:"single",...y.data}),k(""),re(z=>z+1),v(1)}catch{E({mode:"single",error:!0})}finally{M(!1)}}},Se=async()=>
3{if(!(!h||h.rows.length===0)){M(!0),E(null);try{const a=await w.post("/api/admin/text-data/multi-lang",{category:s.category,subCategory:s.subCategory,gender:Y==="none"?null:Y,rows:h.rows},{withCredentials:!0});E({mode:"multi",...a.data}),O(""),A(null),re(u=>u+1),v(1)}catch{E({mode:"multi",error:!0})}finally{M(!1)}}},ne=a=>{const u=a.target.files[0];if(!u)return;const y=new FileReader;y.onload=z=>{const G=z.target.result;m==="multi"?(O(G),A(ue(G))):k(G)},y.readAsText(u),a.target.value=""},Te=a=>{O(a),a.trim()?A(ue(a)):A(null)},ze=(h==null?void 0:h.rows.slice(0,5))??[],oe=(h==null?void 0:h.headers)??[];return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"bg-card-dark border border-border-dark rounded-2xl p-4 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("p",{className:"text-sm font-semibold text-white",children:["Upload ",s.label]}),e.jsxs("div",{className:"flex items-center gap-1 bg-dark3 border border-border-dark rounded-lg p-1",children:[e.jsx("button",{onClick:()=>L("multi"),className:`px-3 py-1 rounded-md text-xs font-medium transition-colors ${m==="multi"?"bg-accent/15 text-accent":"text-gray-400 hover:text-white"}`,children:"Multi-Language CSV"}),e.jsx("button",{onClick:()=>L("single"),className:`px-3 py-1 rounded-md text-xs font-medium transition-colors ${m==="single"?"bg-accent/15 text-accent":"text-gray-400 hover:text-white"}`,children:"Single Language"})]})]}),m==="multi"?e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("p",{className:"text-xs text-gray-400",children:["First row = language ISO codes (e.g. ",e.jsx("code",{className:"bg-dark3 px-1 rounded",children:"en,es,fr,de"}),"). Each subsequent row = one translation set."]}),e.jsx("textarea",{value:f,onChange:a=>Te(a.target.value),placeholder:`en,es,fr 4John,Juan,Jean 5Mary,MarÃa,Marie`,rows:5,className:"bg-dark3 border border-border-dark rounded-lg p-2.5 text-sm text-white font-mono resize-y w-full placeholder-gray-400"}),h&&h.rows.length>0&&e.jsxs("div",{className:"overflow-x-auto rounded-lg border border-border-dark",children:[e.jsxs("table",{className:"text-xs w-full",children:[e.jsx("thead",{children:e.jsx("tr",{className:"bg-dark3",children:oe.map(a=>e.jsx("th",{className:"px-3 py-1.5 text-left text-gray-300 font-medium border-b border-border-dark",children:a},a))})}),e.jsx("tbody",{children:ze.map((a,u)=>e.jsx("tr",{className:"border-b border-border-dark last:border-0",children:oe.map(y=>e.jsx("td",{className:"px-3 py-1.5 text-gray-200",children:a[y]??""},y))},u))})]}),h.rows.length>5&&e.jsxs("p",{className:"text-xs text-gray-500 px-3 py-1.5",children:["â¦and ",h.rows.length-5," more rows (",h.rows.length," total)"]})]}),e.jsx("div",{className:"flex gap-3 flex-wrap items-end",children:s.showGender&&e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-xs text-gray-300",children:"Gender (optional)"}),e.jsxs(V,{value:Y,onValueChange:pe,children:[e.jsx(H,{className:"bg-dark3 border-border-dark w-32 text-sm text-white",children:e.jsx(q,{})}),e.jsxs(K,{className:"bg-dark3 border-border-dark",children:[e.jsx(j,{value:"none",className:"text-sm text-white focus:bg-dark4",children:"None"}),e.jsx(j,{value:"male",className:"text-sm text-white focus:bg-dark4",children:"Male"}),e.jsx(j,{value:"female",className:"text-sm text-white focus:bg-dark4",children:"Female"})]})]})]})}),e.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[e.jsxs("button",{onClick:Se,disabled:P||!h||h.rows.length===0,className:"flex items-center gap-1.5 bg-main text-white px-3 py-2 rounded-lg text-sm font-medium disabled:opacity-50 active:scale-95 transition-all",children:[P?e.jsx(N,{size:14,className:"animate-spin"}):e.jsx($,{size:14}),"Upload ",h?`${h.rows.length} rows`:""]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-sm text-gray-300 hover:text-white cursor-pointer border border-border-dark px-3 py-2 rounded-lg hover:bg-dark3 transition-colors",children:[e.jsx($,{size:14}),"Import CSV file",e.jsx("input",{type:"file",accept:".csv,.txt",className:"hidden",onChange:ne})]}),e.jsxs("button",{onClick:()=>F("csv"),disabled:S||c===0,className:"flex items-center gap-1.5 text-sm text-gray-300 hover:text-white border border-border-dark px-3 py-2 rounded-lg hover:bg-dark3 transition-colors disabled:opacity-40 active:scale-95",children:[S?e.jsx(N,{size:14,className:"animate-spin"}):e.jsx(J,{size:14}),"Export CSV"]}),e.jsxs("button",{onClick:()=>F("json"),disabled:S||c===0,className:"flex items-center gap-1.5 text-sm text-gray-300 hover:text-white border border-border-dark px-3 py-2 rounded-lg hover:bg-dark3 transition-colors disabled:opacity-40 active:scale-95",children:[S?e.jsx(N,{size:14,className:"animate-spin"}):e.jsx(J,{size:14}),"Export JSON"]}),e.jsxs("button",{onClick:()=>I("all"),className:"flex items-center gap-1.5 border border-red-500/40 text-red-400 hover:bg-red-500/10 px-3 py-2 rounded-lg text-sm transition-colors active:scale-95",children:[e.jsx(_,{size:14}),"Delete All"]})]})]}):e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex gap-3 flex-wrap items-end",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-xs text-gray-300",children:"Language"}),e.jsxs(V,{value:U,onValueChange:W,children:[e.jsx(H,{className:"bg-dark3 border-border-dark w-44 text-sm text-white",children:e.jsx(q,{})}),e.jsx(K,{className:"bg-dark3 border-border-dark max-h-60",children:Q.map(a=>e.jsx(j,{value:a.code,className:"text-sm text-white focus:bg-dark4",children:a.label},a.code))})]})]}),s.showGender&&e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-xs text-gray-300",children:"Gender (optional)"}),e.jsxs(V,{value:R,onValueChange:r,children:[e.jsx(H,{className:"bg-dark3 border-border-dark w-32 text-sm text-white",children:e.jsx(q,{})}),e.jsxs(K,{className:"bg-dark3 border-border-dark",children:[e.jsx(j,{value:"none",className:"text-sm text-white focus:bg-dark4",children:"None"}),e.jsx(j,{value:"male",className:"text-sm text-white focus:bg-dark4",children:"Male"}),e.jsx(j,{value:"female",className:"text-sm text-white focus:bg-dark4",children:"Female"})]})]})]})]}),e.jsx("textarea",{value:C,onChange:a=>k(a.target.value),placeholder:`Paste comma-separated values or JSON array... 6Alice, Bob, Carol 7or ["Alice", "Bob", "Carol"]`,rows:4,className:"bg-dark3 border border-border-dark rounded-lg p-2.5 text-sm text-white resize-y w-full placeholder-gray-400"}),e.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[e.jsxs("button",{onClick:ke,disabled:P||!C.trim(),className:"flex items-center gap-1.5 bg-main text-white px-3 py-2 rounded-lg text-sm font-medium disabled:opacity-50 active:scale-95 transition-all",children:[P?e.jsx(N,{size:14,className:"animate-spin"}):e.jsx($,{size:14}),"Upload"]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-sm text-gray-300 hover:text-white cursor-pointer border border-border-dark px-3 py-2 rounded-lg hover:bg-dark3 transition-colors",children:[e.jsx($,{size:14}),"Import file (.csv/.json)",e.jsx("input",{type:"file",accept:".csv,.json,.txt",className:"hidden",onChange:ne})]}),e.jsxs("button",{onClick:()=>F("csv"),disabled:S||c===0,className:"flex items-center gap-1.5 text-sm text-gray-300 hover:text-white border border-border-dark px-3 py-2 rounded-lg hover:bg-dark3 transition-colors disabled:opacity-40 active:scale-95",children:[S?e.jsx(N,{size:14,className:"animate-spin"}):e.jsx(J,{size:14}),"Export CSV"]}),e.jsxs("button",{onClick:()=>F("json"),disabled:S||c===0,className:"flex items-center gap-1.5 text-sm text-gray-300 hover:text-white border border-border-dark px-3 py-2 rounded-lg hover:bg-dark3 transition-colors disabled:opacity-40 active:scale-95",children:[S?e.jsx(N,{size:14,className:"animate-spin"}):e.jsx(J,{size:14}),"Export JSON"]}),e.jsxs("button",{onClick:()=>I("all"),className:"flex items-center gap-1.5 border border-red-500/40 text-red-400 hover:bg-red-500/10 px-3 py-2 rounded-lg text-sm transition-colors active:scale-95",children:[e.jsx(_,{size:14}),"Delete All"]})]})]}),D&&e.jsxs("div",{className:"bg-dark3 border border-border-dark rounded-lg p-3 flex flex-col gap-1.5",children:[D.error?e.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-xs",children:[e.jsx(Ue,{size:13}),e.jsx("span",{children:"Upload failed â check your connection and try again"})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex items-center gap-2 text-green-400 text-xs",children:[e.jsx(Pe,{size:13}),D.mode==="multi"?e.jsxs("span",{children:[D.inserted," docs inserted across ",D.rows," rows"]}):e.jsxs("span",{children:[D.inserted," item",D.inserted!==1?"s":""," inserted"]})]})}),e.jsx("button",{onClick:()=>E(null),className:"text-[11px] text-gray-500 hover:text-gray-300 self-start mt-0.5 transition-colors",children:"Dismiss"})]})]}),e.jsx(Ve,{tab:s,refreshKey:ye}),p.size>0&&e.jsxs("div",{className:"flex items-center justify-between bg-accent/10 border border-accent/30 rounded-xl px-4 py-2",children:[e.jsxs("span",{className:"text-sm text-white",children:[p.size," selected"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>n(new Set),className:"text-xs text-gray-300 hover:text-white px-2 py-1 rounded",children:"Clear"}),e.jsxs("button",{onClick:()=>I("bulk"),className:"flex items-center gap-1 text-xs bg-red-600 hover:bg-red-500 text-white px-2.5 py-1.5 rounded-lg transition-colors active:scale-95",children:[e.jsx(_,{size:12}),"Delete ",p.size]})]})]}),e.jsxs("div",{className:"bg-card-dark border border-border-dark rounded-2xl",children:[e.jsxs("div",{className:"p-4 border-b border-border-dark flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[fe?e.jsx(N,{size:16,className:"animate-spin text-gray-400"}):e.jsx(te,{checked:le,onCheckedChange:je,"aria-label":"Select all"}),e.jsxs("p",{className:"text-sm font-medium text-white",children:[c.toLocaleStr
7ing()," entries"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[Z>1&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-300",children:[e.jsx("button",{onClick:()=>v(t-1),disabled:t<=1,className:"disabled:opacity-30 hover:text-white",children:e.jsx(Ie,{size:16})}),e.jsxs("span",{children:[t," / ",Z]}),e.jsx("button",{onClick:()=>v(t+1),disabled:t>=Z,className:"disabled:opacity-30 hover:text-white",children:e.jsx(Oe,{size:16})})]}),e.jsx("button",{onClick:()=>v(t),disabled:b,title:"Refresh list",className:"flex items-center justify-center w-8 h-8 rounded-lg text-gray-400 hover:text-white hover:bg-white/10 border border-border-dark transition-all active:scale-95 disabled:opacity-30",children:e.jsx(be,{size:14,className:b?"animate-spin":""})})]})]}),b?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(N,{size:20,className:"animate-spin text-gray-400"})}):g.length===0?e.jsx("p",{className:"text-center py-10 text-gray-400 text-sm",children:"No entries yet"}):e.jsx("div",{className:"divide-y divide-border-dark",children:g.map(a=>{const u=p.has(a._id);return e.jsxs("div",{className:`flex items-center gap-3 px-4 py-2.5 text-sm ${u?"bg-accent/5":""}`,children:[e.jsx(te,{checked:u,onCheckedChange:()=>we(a._id)}),e.jsx("span",{className:"flex-1 truncate text-white",children:a.text}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[a.entryIndex!=null&&e.jsxs("span",{className:"text-xs text-gray-500 tabular-nums",children:["#",a.entryIndex]}),a.gender&&e.jsx("span",{className:"text-xs text-gray-400 bg-dark3 px-1.5 py-0.5 rounded",children:a.gender}),e.jsx("span",{className:"text-xs text-gray-400",children:a.language}),e.jsx("button",{onClick:()=>I({id:a._id}),className:"text-gray-400 hover:text-red-400 transition-colors active:scale-95",children:e.jsx(_,{size:14})})]})]},a._id)})})]}),e.jsx(X,{open:T!==null&&typeof T=="object"&&"id"in T,onOpenChange:a=>{a||I(null)},title:"Delete this entry?",description:"This will permanently remove it from the database.",onConfirm:()=>ve(T==null?void 0:T.id)}),e.jsx(X,{open:T==="bulk",onOpenChange:a=>{a||I(null)},title:`Delete ${p.size} entries?`,description:"The selected entries will be permanently removed.",onConfirm:Ne}),e.jsx(X,{open:T==="all",onOpenChange:a=>{a||I(null)},title:`Delete ALL ${c.toLocaleString()} entries?`,description:`Every entry in ${s.label} will be permanently deleted. This cannot be undone.`,confirmLabel:"Delete All",onConfirm:Ce})]})}const he="admin-custom-text-tabs";function rt(){const[s,g]=o.useState(()=>{try{return JSON.parse(localStorage.getItem(he))??[]}catch{return[]}}),[i,c]=o.useState(B[0].key),[x,t]=o.useState(!1),[l,b]=o.useState({label:"",categoryPreset:"",category:"",subCategory:"",showGender:!1}),[d,p]=o.useState(""),[n,m]=o.useState(null),L=[...B,...s],C=!!(l.label||l.category||l.subCategory),k=r=>{g(r);try{localStorage.setItem(he,JSON.stringify(r))}catch{}},U=()=>{const r=l.label.trim(),f=l.category.trim().toLowerCase(),O=l.subCategory.trim().toLowerCase()||null;if(!r){p("Label is required.");return}if(!f){p("Category is required.");return}const h=`custom-${Date.now()}`,A={key:h,label:r,category:f,subCategory:O,showGender:l.showGender,custom:!0};k([...s,A]),c(h),t(!1),b({label:"",categoryPreset:"",category:"",subCategory:"",showGender:!1}),p("")},W=async r=>{try{const f={category:r.category,page:1,limit:1};r.subCategory!==null&&(f.subCategory=r.subCategory??"null");const h=(await w.get("/api/admin/text-data",{params:f,withCredentials:!0})).data.total;m({tab:r,status:h>0?"has-data":"confirm",count:h})}catch{m({tab:r,status:"confirm",count:0})}},R=()=>{n&&(i===n.tab.key&&c(B[0].key),k(s.filter(r=>r.key!==n.tab.key)),m(null))};return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-white",children:"Event Text Data"}),e.jsxs(Le,{value:i,onValueChange:c,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(De,{className:"bg-dark3 border border-border-dark rounded-xl flex flex-wrap h-auto gap-1 p-1.5",children:[B.map(r=>e.jsx(ce,{value:r.key,className:"text-xs sm:text-sm text-gray-200 hover:text-white px-3 sm:px-4 py-2 rounded-lg transition-colors data-[state=active]:bg-accent/15 data-[state=active]:text-accent data-[state=active]:font-medium",children:r.label},r.key)),s.map(r=>e.jsx(ce,{value:r.key,className:"text-xs sm:text-sm text-gray-200 hover:text-white px-3 sm:px-4 py-2 rounded-lg transition-colors data-[state=active]:bg-accent/15 data-[state=active]:text-accent data-[state=active]:font-medium",children:e.jsxs("span",{className:"flex items-center gap-1",children:[r.label,e.jsx("span",{role:"button",onClick:f=>{f.stopPropagation(),W(r)},className:"ml-1.5 w-4 h-4 inline-flex items-center justify-center rounded-full bg-white/0 hover:bg-red-500/25 text-gray-400 hover:text-red-400 transition-all text-[11px] font-bold leading-none",title:"Remove tab",children:"Ã"})]})},r.key))]}),e.jsxs("button",{onClick:()=>t(!0),className:"flex items-center gap-1.5 text-xs text-gray-300 hover:text-white border border-dashed border-border-dark hover:border-accent/50 px-3 py-2 rounded-lg transition-colors",children:[e.jsx(Re,{size:13}),"New Tab"]})]}),L.map(r=>e.jsx(Ee,{value:r.key,className:"mt-4",children:e.jsx(He,{tab:r})},r.key))]}),e.jsx(ie,{open:x,onOpenChange:r=>{t(r),r||p("")},children:e.jsxs(de,{className:"bg-dark2 border-border-dark text-white max-w-sm",onInteractOutside:r=>{C&&r.preventDefault()},children:[e.jsx(xe,{children:e.jsx(me,{children:"New Text Data Tab"})}),e.jsxs("div",{className:"flex flex-col gap-3 text-sm",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"text-xs text-gray-300",children:["Label ",e.jsx("span",{className:"text-gray-500",children:"(display name)"})]}),e.jsx("input",{value:l.label,onChange:r=>b(f=>({...f,label:r.target.value})),placeholder:"e.g. Names â Cats",className:"bg-dark3 border border-border-dark rounded-lg px-3 py-2 text-sm text-white placeholder-gray-500 focus:outline-none focus:border-accent/50"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"text-xs text-gray-300",children:["Category ",e.jsx("span",{className:"text-gray-500",children:"(stored
7in DB)"})]}),e.jsxs(V,{value:l.categoryPreset,onValueChange:r=>{b(r==="_custom"?f=>({...f,categoryPreset:"_custom",category:""}):f=>({...f,categoryPreset:r,category:r}))},children:[e.jsx(H,{className:"bg-dark3 border-border-dark text-sm text-white",children:e.jsx(q,{placeholder:"Select existing or customâ¦"})}),e.jsxs(K,{className:"bg-dark3 border-border-dark",children:[e.jsx(j,{value:"names",className:"text-sm text-white focus:bg-dark4",children:"names"}),e.jsx(j,{value:"countries",className:"text-sm text-white focus:bg-dark4",children:"countries"}),e.jsx(j,{value:"hobbies",className:"text-sm text-white focus:bg-dark4",children:"hobbies"}),e.jsx(j,{value:"words",className:"text-sm text-white focus:bg-dark4",children:"words"}),e.jsx(j,{value:"dates",className:"text-sm text-white focus:bg-dark4",children:"dates"}),e.jsx(j,{value:"_custom",className:"text-sm text-gray-400 italic focus:bg-dark4",children:"Customâ¦"})]})]}),l.categoryPreset==="_custom"&&e.jsx("input",{value:l.category,onChange:r=>b(f=>({...f,category:r.target.value})),placeholder:"e.g. sports",autoFocus:!0,className:"bg-dark3 border border-border-dark rounded-lg px-3 py-2 text-sm text-white placeholder-gray-500 focus:outline-none focus:border-accent/50 mt-1"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"text-xs text-gray-300",children:["Sub-Category ",e.jsx("span",{className:"text-gray-500",children:"(optional â leave empty for none)"})]}),e.jsx("input",{value:l.subCategory,onChange:r=>b(f=>({...f,subCategory:r.target.value})),placeholder:"e.g. cats",className:"bg-dark3 border border-border-dark rounded-lg px-3 py-2 text-sm text-white placeholder-gray-500 focus:outline-none focus:border-accent/50"})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer select-none",children:[e.jsx(te,{checked:l.showGender,onCheckedChange:r=>b(f=>({...f,showGender:!!r})),className:"mt-0.5"}),e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("span",{className:"text-sm text-gray-200",children:"Enable gender tagging"}),e.jsx("span",{className:"text-xs text-gray-500",children:"Check this if entries in this category can be male or female (e.g. person names). A gender selector will appear on the upload form so you can tag each batch."})]})]}),d&&e.jsx("p",{className:"text-xs text-red-400",children:d}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx("button",{onClick:()=>{t(!1),p("")},className:"text-sm text-gray-300 hover:text-white px-3 py-2 rounded-lg border border-border-dark hover:bg-dark3 transition-colors",children:"Cancel"}),e.jsx("button",{onClick:U,className:"text-sm bg-accent text-dark1 px-4 py-2 rounded-lg font-medium hover:bg-accent/90 active:scale-95 transition-all",children:"Add Tab"})]})]})]})}),e.jsx(X,{open:(n==null?void 0:n.status)==="confirm",onOpenChange:r=>{r||m(null)},title:`Remove "${n==null?void 0:n.tab.label}" tab?`,description:"This removes the tab from the panel. It does not delete any data already uploaded â you can re-add the tab at any time to access that data again.",confirmLabel:"Remove Tab",onConfirm:R}),e.jsx(ie,{open:(n==null?void 0:n.status)==="has-data",onOpenChange:r=>{r||m(null)},children:e.jsxs(de,{className:"bg-dark2 border-border-dark text-white max-w-sm",children:[e.jsx(xe,{children:e.jsx(me,{children:"Tab still has data"})}),e.jsxs("p",{className:"text-sm text-gray-300",children:["This tab has ",e.jsxs("span",{className:"text-white font-medium",children:[n==null?void 0:n.count.toLocaleString()," ",(n==null?void 0:n.count)===1?"entry":"entries"]}),". Delete all the data in this category first, then you can remove the tab."]}),e.jsx("div",{className:"flex justify-end pt-2",children:e.jsx("button",{onClick:()=>m(null),className:"text-sm bg-dark3 border border-border-dark text-white px-4 py-2 rounded-lg hover:bg-dark4 transition-colors",children:"OK"})})]})})]})}export{rt 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.