1import{r as y,k as W,a as I,ah as X,l as E,j as e,B as N,a2 as $,J as u,x as H,D as K,ao as Z,af as ee,I as c,ap as se,aq as ae,ar as te,as as re,at as ne,E as ie,F as le,s as oe,a6 as de,a7 as ce,a8 as ue,a9 as he,h as g,t as S,a3 as me,aH as xe,a4 as ge,G as pe}from"./index-C4LWZPK9.js";import{T as je}from"./textarea-G6LYtFU8.js";import{F as ve}from"./FileUploader-DVCKECt2.js";import{T as ye,a as be,b as Q}from"./tabs-k4Vtuswt.js";import{U as fe}from"./users-round-Chmwqkee.js";import{P as Ne}from"./plus-Nk5sUbpA.js";import{P as we}from"./pencil-DiYrB8i9.js";import{H as Ce}from"./hash-Co3Nw00Q.js";import"./eye-BuNnJwN2.js";import"./upload-CkiK-kaT.js";import"./external-link-lrsG04FH.js";const q={name:"",email:"",bio:"",photo_url:"",instagram:"",youtube:"",tiktok:"",twitter:"",website:"",goby_hashtag:"",city:"",country:""};function Ae({form:r,setForm:o,onSubmit:p,onCancel:w,isPending:b}){return e.jsxs("form",{onSubmit:t=>{t.preventDefault(),p()},className:"space-y-4",children:[e.jsx(ve,{label:"Profile Photo",value:r.photo_url,onChange:t=>o({...r,photo_url:t}),accept:"image/*",previewType:"image",dimensionHint:"Square image recommended (400Ã400px)"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"col-span-2",children:[e.jsx(c,{children:"Name *"}),e.jsx(u,{value:r.name,onChange:t=>o({...r,name:t.target.value}),required:!0})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(c,{children:"Email"}),e.jsx(u,{type:"email",value:r.email,onChange:t=>o({...r,email:t.target.value}),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(c,{children:"Bio"}),e.jsx(je,{value:r.bio,onChange:t=>o({...r,bio:t.target.value}),rows:3,placeholder:"Short biography..."})]}),e.jsxs("div",{children:[e.jsx(c,{children:"City"}),e.jsx(u,{value:r.city,onChange:t=>o({...r,city:t.target.value}),placeholder:"e.g. Los Angeles"})]}),e.jsxs("div",{children:[e.jsx(c,{children:"Country"}),e.jsx(u,{value:r.country,onChange:t=>o({...r,country:t.target.value}),placeholder:"e.g. USA"})]})]}),e.jsxs("div",{className:"border-t border-border pt-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-3 font-medium uppercase tracking-wide",children:"Social Links"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsxs(c,{className:"flex items-center gap-1",children:[e.jsx(me,{className:"w-3 h-3"})," Instagram handle"]}),e.jsx(u,{value:r.instagram,onChange:t=>o({...r,instagram:t.target.value}),placeholder:"username"})]}),e.jsxs("div",{children:[e.jsxs(c,{className:"flex items-center gap-1",children:[e.jsx(xe,{className:"w-3 h-3"})," X / Twitter handle"]}),e.jsx(u,{value:r.twitter,onChange:t=>o({...r,twitter:t.target.value}),placeholder:"username"})]}),e.jsxs("div",{children:[e.jsxs(c,{className:"flex items-center gap-1",children:[e.jsx(ge,{className:"w-3 h-3"})," YouTube"]}),e.jsx(u,{value:r.youtube,onChange:t=>o({...r,youtube:t.target.value}),placeholder:"@channel or URL"})]}),e.jsxs("div",{children:[e.jsx(c,{children:"TikTok handle"}),e.jsx(u,{value:r.tiktok,onChange:t=>o({...r,tiktok:t.target.value}),placeholder:"username"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsxs(c,{className:"flex items-center gap-1",children:[e.jsx(pe,{className:"w-3 h-3"})," Website"]}),e.jsx(u,{value:r.website,onChange:t=>o({...r,website:t.target.value}),placeholder:"https://..."})]})]})]}),e.jsxs("div",{children:[e.jsxs(c,{className:"flex items-center gap-1",children:[e.jsx(Ce,{className:"w-3 h-3"})," Goby Chat Hashtag (without #)"]}),e.jsx(u,{value:r.goby_hashtag,onChange:t=>o({...r,goby_hashtag:t.target.value}),placeholder:"e.g. JohnSmithFilms"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2 border-t border-border",children:[e.jsx(N,{type:"button",variant:"outline",onClick:w,children:"Cancel"}),e.jsx(N,{type:"submit",disabled:b,children:b?"Saving...":"Save Author"})]})]})}function Ie(){const[r,o]=y.useState(!1),[p,w]=y.useState(null),[b,t]=y.useState(q),[f,V]=y.useState(""),[m,B]=y.useState(""),[C,R]=y.useState("authors"),A=W(),{data:k=[],isLoading:L}=I({queryKey:["authors-admin"],queryFn:()=>g.entities.Author.list("-created_date",200)}),{data:x=[]}=I({queryKey:["all-content-for-authors"],queryFn:()=>g.entities.VideoContent.list("-created_date",500)}),j=k.find(s=>s.id===m),P=k.filter(s=>{var n,a,l;return!f||((n=s.name)==null?void 0:n.toLowerCase().includes(f.toLowerCase()))||((a=s.city)==null?void 0:a.toLowerCase().includes(f.toLowerCase()))||((l=s.country)==null?void 0:l.toLowerCase().includes(f.toLowerCase()))}),F=X.useMemo(()=>{const s=new Map,n=[];return x.forEach(a=>{a.series_name?(s.has(a.series_name)||s.set(a.series_name,{isSeries:!0,seriesName:a.series_name,episodes:[],firstEpisode:a}),s.get(a.series_name).episodes.push(a)):n.push(a)}),[...Array.from(s.values()),...n].sort((a,l)=>(a.seriesName||a.title).localeCompare(l.seriesName||l.title))},[x]),G=async(s,n,a)=>{const l=n?x.filter(d=>d.series_name===a):[x.find(d=>d.id===s)],i=l.every(d=>(d.author_ids||[]).includes(m));await Promise.all(l.map(async d=>{const h=i?(d.author_ids||[]).filter(v=>v!==m):[...d.author_ids||[],m],_=i?(d.author_names||[]).filter(v=>v!==(j==null?void 0:j.name)):[...d.author_names||[],j==null?void 0:j.name];await g.entities.VideoContent.update(d.id,{author_ids:h,author_names:_})}
1)),A.invalidateQueries({queryKey:["all-content-for-authors"]}),S.success(i?"Author removed":"Author added")},O=(s,n,a)=>(n?x.filter(i=>i.series_name===a):[x.find(i=>i.id===s)]).every(i=>(i.author_ids||[]).includes(m)),z=(s,n)=>{if(!s)return!1;const a=x.filter(i=>i.series_name===n),l=a.filter(i=>(i.author_ids||[]).includes(m)).length;return l>0&&l<a.length},M=E({mutationFn:s=>p?g.entities.Author.update(p.id,s):g.entities.Author.create(s),onSuccess:()=>{A.invalidateQueries({queryKey:["authors-admin"]}),S.success(p?"Author updated":"Author created"),T()}}),J=E({mutationFn:s=>g.entities.Author.delete(s),onSuccess:()=>{A.invalidateQueries({queryKey:["authors-admin"]}),S.success("Author deleted")}});E({mutationFn:async({contentId:s,authorId:n,authorName:a})=>{const l=x.find(h=>h.id===s),i=(l.author_ids||[]).filter(h=>h!==n),d=(l.author_names||[]).filter(h=>h!==a);return g.entities.VideoContent.update(s,{author_ids:i,author_names:d})},onSuccess:()=>{A.invalidateQueries({queryKey:["all-content-for-authors"]}),S.success("Author removed from content")}});const T=()=>{o(!1),w(null),t(q)},Y=s=>{w(s),t({...q,...s}),o(!0)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(fe,{className:"w-6 h-6 text-primary"}),e.jsx("h1",{className:"text-2xl font-display font-bold",children:"Authors / Creators"})]}),e.jsxs(N,{className:"gap-2 bg-primary hover:bg-primary/90",onClick:()=>o(!0),children:[e.jsx(Ne,{className:"w-4 h-4"})," Add Author"]})]}),e.jsx(ye,{value:C,onValueChange:R,className:"mb-4",children:e.jsxs(be,{children:[e.jsx(Q,{value:"authors",children:"All Authors"}),e.jsx(Q,{value:"manage",children:"Manage Author Assignments"})]})}),C==="authors"&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"relative mb-4",children:[e.jsx($,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(u,{placeholder:"Search by name, city or country...",value:f,onChange:s=>V(s.target.value),className:"pl-9"})]})}),C==="authors"&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:[L&&Array.from({length:8}).map((s,n)=>e.jsx("div",{className:"h-24 rounded-xl bg-secondary/40 animate-pulse"},n)),P.map(s=>{var n,a;return e.jsx(H,{className:"bg-secondary/30 hover:bg-secondary/50 transition-colors",children:e.jsxs(K,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-secondary overflow-hidden shrink-0",children:s.photo_url?e.jsx("img",{src:s.photo_url,alt:s.name,className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-lg font-bold text-muted-foreground",children:(a=(n=s.name)==null?void 0:n[0])==null?void 0:a.toUpperCase()})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm truncate",children:s.name}),(s.city||s.country)&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1 mt-0.5",children:[e.jsx(Z,{className:"w-3 h-3 shrink-0"}),[s.city,s.country].filter(Boolean).join(", ")]}),s.goby_hashtag&&e.jsxs("p",{className:"text-xs text-primary mt-0.5",children:["#",s.goby_hashtag]})]})]}),e.jsxs("div",{className:"flex justify-end gap-1 mt-3",children:[e.jsx(N,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>Y(s),children:e.jsx(we,{className:"w-3 h-3"})}),e.jsx(N,{variant:"ghost",size:"icon",className:"h-7 w-7 text-destructive",onClick:()=>{confirm("Delete this author?")&&J.mutate(s.id)},children:e.jsx(ee,{className:"w-3 h-3"})})]})]})},s.id)}),!L&&P.length===0&&e.jsx("div",{className:"col-span-full text-center py-12 text-muted-foreground",children:"No authors found."})]}),C==="manage"&&e.jsx(H,{className:"bg-secondary/30",children:e.jsxs(K,{className:"p-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx(c,{children:"Select Author to Manage"}),e.jsxs(se,{value:m,onValueChange:B,children:[e.jsx(ae,{children:e.jsx(te,{placeholder:"Choose an author..."})}),e.jsx(re,{children:k.map(s=>e.jsx(ne,{value:s.id,children:s.name},s.id))})]})]}),m&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"border-t border-border pt-4",children:[e.jsx(c,{className:"mb-3 block",children:"Assign / Unassign Content"}),e.jsx("div",{className:"space-y-2 max-h-[60vh] overflow-y-auto p-2 bg-background rounded-lg border border-border",children:F.map(s=>{var d,h,_,v,U;const n=O(((d=s.firstEpisode)==null?void 0:d.id)||s.id,s.isSeries,s.seriesName),a=z(s.isSeries,s.seriesName),l=s.isSeries?s.seriesName:((h=s.firstEpisode)==null?void 0:h.title)||s.title,i=s.isSeries?s.episodes.length:0;return e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-secondary/50 cursor-pointer transition-colors",onClick:()=>{var D;return G(((D=s.firstEpisode)==null?void 0:D.id)||s.id,s.isSeries,s.seriesName)},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${n?"bg-primary border-primary":a?"bg-muted border-primary":"border-border"}`,children:[n&&e.jsx(ie,{className:"w-3 h-3 text-white"}),a&&e.jsx("div",{className:"w-2 h-2 bg-primary rounded-sm"})]}),(_=s.firstEpisode)!=null&&_.thumbnail_url||s.thumbnail_url?e.jsx("img",{src:((v=s.firstEpisode)==null?void 0:v.thumbnail_url)||s.thumbnail_url,alt:"",className:"w-16 h-9 object-cover rounded"}):e.jsx("div",{className:"w-16 h-9 rounded bg-secondary flex items-center justify-center",children:e.jsx(le,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:l}),i>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[i," episode",i>1?"s":""]})]})]}),e.jsx(oe,{variant:n?"default":"secondary",children:n?"Assigned":a?"Partial":"Unassigned"})]},s.isSeries?s.seriesName:((U=s.firstEpisode)==null?void 0:U.id)||s.id)})})]})})]})}),e.jsx(de,{open:r,onOpenChange:s=>!s&&T(),children:e.jsxs(ce,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(ue,{children:e.jsx(he,{className:"font-display",children:p?"Edit Author":"Add New Author"})}),e.jsx(Ae,{form:b,setForm:t,onSubmit:()=>M.mutate(b),onCancel:T,isPending:M.isPending})]})})]})}export{Ie 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.