PageSourceSearch

https://trueth.io/assets/TalentRoster-BckBblY-.js

js trueth.io collected 2026-09-30 06:37:09 UTC 56,993 bytes, 31 lines download raw bytes

1import{k as ne,r as i,s as p,A as Ae,q as R,j as e,x as Ze,T as es,v as ss,w as ts,X as js,B as w,d as Me,D as vs,m as ys,n as Ns,o as bs,u as ws}from"./index-cvSkj9Gc.js";import{u as Pe}from"./useQuery-BaZlE4Aw.js";import{T as Ss,a as ks,b as qe,c as X,d as Cs,e as W}from"./table-BQ9xcjEo.js";import{B as _}from"./badge-CD9B5Ww7.js";import{S as $e}from"./skeleton-DP0Xl8C1.js";import{C as Ge}from"./checkbox-CyP_ifK1.js";import{A as me,h as _s,a as ue,b as he,c as xe,d as ge,e as pe,f as fe,g as je}from"./alert-dialog-Dz2WDbz4.js";import{T as Le}from"./textarea-Di3UPXhW.js";import{a as Ue,b as Ds}from"./storage-utils-A2yuX6qq.js";import{C as le,b as oe,c as ce,d as Is,a as de}from"./card-kUfaaxnq.js";import{C as ke}from"./camera-BP62gzVQ.js";import{I as Ts}from"./info-C8d4d-2b.js";import{L as M}from"./loader-circle-BHdvxr0p.js";import{I as Fs}from"./image-plus-CRydrXBs.js";import{T as De}from"./triangle-alert-DqVARltb.js";import{R as zs}from"./rotate-ccw-yNwIaUcU.js";import{S as rs}from"./save-BwTxAKyo.js";import{M as Ee}from"./mail-Bdy5kZCG.js";import{P as Es}
1from"./phone-yDPTsswU.js";import{M as As}from"./map-pin-yuM0EvhC.js";import{C as Ms}from"./calendar-7_83RPV2.js";import{R as Ce}from"./refresh-cw-BHJPvvxj.js";import{F as _e}from"./fingerprint-CZ0cx0-9.js";import{P as we}from"./pencil-3pdssFnX.js";import{T as as}from"./trending-up-B_vY8RNk.js";import{D as is}from"./dollar-sign-B3U1E1S-.js";import{C as Ie}from"./circle-check-CEqj24aO.js";import{C as Je}from"./circle-x-CtQdT30R.js";import{C as Ps}from"./clock-BWvPf1LY.js";import{U as Fe}from"./user-C1KZlg1f.js";import{E as ns}from"./eye-BVdopAAE.js";import{P as $s}from"./palette-D17TNDEQ.js";import{f as Re}from"./format-CMz-2fmV.js";import{a as Rs,i as Os}from"./email-blast-staging-BGqhcnyB.js";import{S as Bs,G as qs,a as Gs}from"./GiftCreditsDialog-D3h2Rhz4.js";import{S as Ls}from"./send-BPxfIN1f.js";import{T as Ke}from"./trash-2-CUDHfk0K.js";import{E as Ve}from"./eye-off-CejuYCMI.js";import{C as He}from"./check-CPGULxQ-.js";import{S as Us}from"./sparkles-BQPrnr3K.js";import{S as Qe,a as Xe,b as We,c as Ye,d as te}from"./select-CmFQSFAI.js";import{I as Js}from"./input-D3lfeLZA.js";import{U as Ks}from"./users-B_GuppMO.js";import{S as Vs}from"./search-DwHJ0dm_.js";import"./index-BdQq_4o_.js";import"./index-BGsNGv2O.js";import"./chevron-down-BOzbTpI_.js";import"./chevron-up-CppM1k62.js";/**
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 Te=ne("Award",[["path",{d:"m15.477 12.89 1.515 8.526a.5.5 0 0 1-.81.47l-3.58-2.687a1 1 0 0 0-1.197 0l-3.586 2.686a.5.5 0 0 1-.81-.469l1.514-8.526",key:"1yiouv"}],["circle",{cx:"12",cy:"8",r:"6",key:"1vp47v"}]]);/**
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 Hs=ne("Banknote",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"2",key:"9lu3g6"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M6 12h.01M18 12h.01",key:"113zkx"}]]);/**
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 Qs=ne("FileCheck2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m3 15 2 2 4-4",key:"1lhrkk"}]]);/**
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 Xs=ne("ScanFace",[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["path",{d:"M8 14s1.5 2 4 2 4-2 4-2",key:"1y1vjs"}],["path",{d:"M9 9h.01",key:"1q5me6"}],["path",{d:"M15 9h.01",key:"x1ddxp"}]]);/**
22 * @license lucide-react v0.462.0 - ISC
23 *
24 * This source code is licensed under the ISC license.
25 * See the LICENSE file in the root directory of this source tree.
26 */const ze=ne("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
27 * @license lucide-react v0.462.0 - ISC
28 *
29 * This source code is licensed under the ISC license.
30 * See the LICENSE file in the root directory of this source tree.
31 */const Ws=ne("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]);function Ys(s){const{data:D,isLoading:y,error:v,refetch:k}=Pe({queryKey:["talent-roster",s],queryFn:async()=>{let g=p.from("talents").select("*").in("status",["approved","suspended"]).order("created_at",{ascending:!1});const{data:I,error:S}=await g;if(S)throw S;return I}});return i.useEffect(()=>{const g=p.channel("talents-changes").on("postgres_changes",{event:"*",schema:"public",table:"talents"},()=>{k()}).subscribe();return()=>{p.removeChannel(g)}},[k]),{talents:D||[],isLoading:y,error:v,refetch:k}}const Zs=4,et=1,Se=30,st=10*1024*1024,tt=["image/jpeg","image/png","image/webp"];function rt(s,D,y){const v=y!=null&&y.adminMode?et:Zs,k=Ae(),[g,I]=i.useState(D||[]),[S,O]=i.useState([]),[T,B]=i.useState(!1),[z,C]=i.useState(!1),{data:P,isLoading:U,refetch:q}=Pe({queryKey:["reference-images",s,g],queryFn:async()=>
31{if(!g||g.length===0)return[];const r=[];for(const d of g)try{const{data:a}=await p.storage.from("founding-talent-images").createSignedUrl(d,3600);a!=null&&a.signedUrl&&r.push({path:d,url:a.signedUrl})}catch(a){console.error(`Error getting signed URL for ${d}:`,a)}return r},enabled:!!s&&g.length>0}),$=i.useCallback(r=>{I(r||[])},[]),G=async r=>{var d;if(!tt.includes(r.type))return R.error("Only JPEG, PNG, and WebP images are allowed"),null;if(r.size>st)return R.error("File size must be less than 10MB"),null;if(g.length>=Se)return R.error(`Maximum ${Se} images allowed`),null;B(!0);try{const{data:a}=await p.from("talents").select("email").eq("id",s).single();if(!(a!=null&&a.email))throw new Error("Could not fetch talent info");const f=((d=r.name.split(".").pop())==null?void 0:d.toLowerCase())||"jpg",L=Date.now(),l=Math.random().toString(36).substring(2,8),V=`${L}-${l}.${f}`,J=`approved/${a.email}/${V}`,{error:Z}=await p.storage.from("founding-talent-images").upload(J,r,{cacheControl:"3600",upsert:!1});if(Z)throw Z;return I(re=>[...re,J]),R.success("Image uploaded"),J}catch(a){return console.error("Upload error:",a),R.error("Failed to upload image"),null}finally{B(!1)}},o=r=>g.length<=v?(R.error(`Minimum ${v} images required`),!1):(I(d=>d.filter(a=>a!==r)),!0),n=async()=>{if(g.length<v)return R.error(`Minimum ${v} images required`),{success:!1};C(!0);try{const{error:r}=await p.from("talents").update({onboarding_image_paths:g}).eq("id",s);if(r)throw r;const{data:d,error:a}=await p.functions.invoke("reanalyze-talent-profile",{body:{talentId:s}});if(a)throw a;if(d!=null&&d.error)throw new Error(d.error);return k.invalidateQueries({queryKey:["talent-profile"]}),k.invalidateQueries({queryKey:["reference-images",s]}),R.success("Training images updated and profile re-analyzed"),{success:!0}}catch(r){return console.error("Save and reanalyze error:",r),R.error(r instanceof Error?r.message:"Failed to update profile"),{success:!1}}finally{C(!1)}},x=JSON.stringify(g)!==JSON.stringify(D||[]),m=()=>{I(D||[]),O([])},F=g.length>=v,N=g.length<Se,K=g.length>v;return{imageUrls:P||[],localPaths:g,loadingUrls:U,isUploading:T,isReanalyzing:z,hasChanges:x,canSave:F,canAddMore:N,canRemove:K,uploadImage:G,removeImage:o,saveAndReanalyze:n,resetChanges:m,syncPaths:$,refetchUrls:q,MIN_IMAGES:v,MAX_IMAGES:Se}}function at({talentId:s,currentImages:D,onImagesUpdated:y,adminMode:v=!1}){const k=i.useRef(null),[g,I]=i.useState(!1),{imageUrls:S,localPaths:O,loadingUrls:T,isUploading:B,isReanalyzing:z,hasChanges:C,canSave:P,canAddMore:U,canRemove:q,uploadImage:$,removeImage:G,saveAndReanalyze:o,resetChanges:n,syncPaths:x,MIN_IMAGES:m,MAX_IMAGES:F}=rt(s,D,{adminMode:v});i.useEffect(()=>{x(D)},[D,x]);const N=i.useCallback(async l=>{if(!(!l||l.length===0))for(const V of Array.from(l))await $(V)},[$]),K=i.useCallback(l=>{l.preventDefault(),I(!1),N(l.dataTransfer.files)}
31,[N]),r=l=>{l.preventDefault(),I(!0)},d=l=>{l.preventDefault(),I(!1)},a=async()=>{(await o()).success&&y()},L=O.length<m;return e.jsxs(le,{children:[e.jsx(oe,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsxs(ce,{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-5 w-5"}),"Training Images"]}),e.jsxs(Is,{className:"flex items-center gap-2 mt-1",children:["These images are used to train your AI likeness",e.jsx(Ze,{children:e.jsxs(es,{children:[e.jsx(ss,{asChild:!0,children:e.jsx(Ts,{className:"h-4 w-4 text-muted-foreground hover:text-foreground cursor-help"})}),e.jsx(ts,{side:"top",className:"max-w-xs",children:e.jsx("p",{className:"text-xs",children:"For best results, include clear photos of your face from different angles. Changes will trigger a re-analysis of your profile."})})]})})]})]})})}),e.jsxs(de,{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 gap-3",children:T?Array.from({length:(D==null?void 0:D.length)||4}).map((l,V)=>e.jsx($e,{className:"aspect-square rounded-lg"}
31,V)):e.jsxs(e.Fragment,{children:[S.map(l=>e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"aspect-square rounded-lg overflow-hidden border border-border bg-muted",children:e.jsx("img",{src:l.url,alt:"Reference",className:"w-full h-full object-cover"})}),e.jsxs(me,{children:[e.jsx(_s,{asChild:!0,children:e.jsx("button",{className:`absolute -top-2 -right-2 w-6 h-6 rounded-full bg-destructive text-destructive-foreground flex items-center justify-center shadow-md opacity-0 group-hover:opacity-100 transition-opacity ${q?"":"cursor-not-allowed opacity-50"}`,disabled:!q||z,children:e.jsx(js,{className:"h-3 w-3"})})}),e.jsxs(ue,{children:[e.jsxs(he,{children:[e.jsx(xe,{children:"Remove Image?"}),e.jsx(ge,{children:"This will remove the image from your reference photos. You'll need to save changes to apply the update."})]}),e.jsxs(pe,{children:[e.jsx(fe,{children:"Cancel"}),e.jsx(je,{onClick:()=>G(l.path),children:"Remove"})]})]})]})]},l.path)),U&&e.jsx("div",{className:`aspect-square rounded-lg border-2 border-dashed transition-colors flex flex-col items-center justify-center cursor-pointer ${g?"border-primary bg-primary/10":"border-muted-foreground/25 hover:border-primary/50"} ${B?"pointer-events-none opacity-50":""}`,onClick:()=>{var l;return(l=k.current)==null?void 0:l.click()},onDrop:K,onDragOver:r,onDragLeave:d,children:B?e.jsx(M,{className:"h-6 w-6 animate-spin text-muted-foreground"}):e.jsxs(e.Fragment,{children:[e.jsx(Fs,{className:"h-6 w-6 text-muted-foreground mb-1"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Add"})]})})]})}),e.jsx("input",{ref:k,type:"file",accept:"image/jpeg,image/png,image/webp",multiple:!0,className:"hidden",onChange:l=>N(l.target.files)}),L&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-destructive bg-destructive/10 p-3 rounded-lg",children:[e.jsx(De,{className:"h-4 w-4"}),e.jsxs("span",{children:["Minimum ",m," images required to save changes"]})]}),C&&e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs(w,{variant:"ghost",size:"sm",onClick:n,disabled:z,children:[e.jsx(zs,{className:"h-4 w-4 mr-2"}),"Reset Changes"]}),e.jsx(w,{onClick:a,disabled:!P||z,size:"sm",children:z?e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"h-4 w-4 mr-2 animate-spin"}),"Re-analyzing Profile..."]}):e.jsxs(e.Fragment,{children:[e.jsx(rs,{className:"h-4 w-4 mr-2"}),"Save & Re-analyze"]})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Accepted formats: JPEG, PNG, WebP. Max 10MB per image. Up to ",F," images total."]})]})]})}function it({result:s}){return s==="loading"?e.jsxs(_,{variant:"outline",className:"border-muted-foreground text-muted-foreground",children:[e.jsx(M,{className:"h-3 w-3 mr-1 animate-spin"}),"Verifying Identity..."]}):s==="error"||!s?null:s.confidence>=90?e.jsxs("div",{className:"space-y-1",children:[e.jsxs(_,{variant:"outline",className:"border-emerald-500 text-emerald-600",children:[e.jsx(Ie,{className:"h-3 w-3 mr-1"}),"Identity Match: ",s.confidence,"% ✓"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.explanation})]}):s.confidence>=60?e.jsxs("div",{className:"space-y-1",children:[e.jsxs(_,{variant:"outline",className:"border-amber-500 text-amber-600",children:[e.jsx(De,{className:"h-3 w-3 mr-1"}),"Uncertain Match: ",s.confidence,"% — Review Carefully"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.explanation})]}):e.jsxs("div",{className:"space-y-1",children:[e.jsxs(_,{variant:"outline",className:"border-destructive text-destructive",children:[e.jsx(De,{className:"h-3 w-3 mr-1"}),"Identity Mismatch: ",s.confidence,"% ⚠️"]}),e.jsx("p",{className:"text-xs text-destructive",children:s.explanation})]})}function nt({talentId:s,talentName:D,talentEmail:y,onRefetch:v}){const{toast:k}=Me(),g=Ae(),[I,S]=i.useState({}),[O,T]=i.useState(null),[B,z]=i.useState({}),{data:C,isLoading:P}=Pe({queryKey:["likeness-requests",s],queryFn:async()=>{const{data:o,error:n}=await p.from("likeness_requests").select("*").eq("talent_id",s).order("created_at",{ascending:!1});if(n)throw n;return o||[]}}),U=i.useRef(new Set);i.useEffect(()=>{if(!C)return;C.filter(n=>n.status==="pending"||n.status==="in_progress").forEach(n=>{U.current.has(n.id)||(U.current.add(n.id),z(x=>({...x,[n.id]:"loading"})),p.functions.invoke("verify-likeness-match",{body:{talentId:s,requestId:n.id}}).then(({data:x,error:m})=>{z(m||!x?F=>({...F,[n.id]:"error"}):F=>({...F,[n.id]:x}))}))})},[C,s]),i.useEffect(()=>{if(!C)return;const o=C.flatMap(x=>x.image_paths),n=[...new Set(o)].filter(x=>!I[x]);n.length!==0&&Promise.all(n.map(async x=>{const m=await Ds(x);return{path:x,url:m}})).then(x=>{S(m=>{const F={...m};return x.forEach(N=>{N.url&&(F[N.path]=N.url)}),F})})},[C]);const q=async o=>{T(o.id);try{const{error:n}=await p.from("likeness_requests").update({status:"completed",reviewed_at:new Date().toISOString()}
31).eq("id",o.id);if(n)throw n;k({title:"Approved",description:"Replacing reference images and retraining..."});const{error:x}=await p.from("talents").update({onboarding_image_paths:o.image_paths,sample_image_urls:[],updated_at:new Date().toISOString()}).eq("id",s);if(x)throw x;k({title:"Retraining",description:"Regenerating facial fingerprint..."}),await p.functions.invoke("reanalyze-talent-profile",{body:{talentId:s}}),k({title:"Retraining",description:"Generating new profile images..."}),await p.functions.invoke("generate-sample-images",{body:{talentId:s,promptIndex:0,totalPrompts:3}}),await p.functions.invoke("notify-likeness-request",{body:{type:"resolved",talentId:s,talentName:D,talentEmail:y,status:"completed"}}),k({title:"Profile Refreshed",description:"Fingerprint regenerated and new sample images are being generated."}),g.invalidateQueries({queryKey:["likeness-requests",s]}),g.invalidateQueries({queryKey:["admin-stats"]}),v==null||v()}catch(n){k({title:"Error",description:n.message,variant:"destructive"})}finally{T(null)}},$=async o=>{T(o);try{const{error:n}=await p.from("likeness_requests").update({status:"dismissed",reviewed_at:new Date().toISOString()}).eq("id",o);if(n)throw n;await p.functions.invoke("notify-likeness-request",{body:{type:"resolved",talentId:s,talentName:D,talentEmail:y,status:"dismissed"}}),k({title:"Declined",description:"Request has been declined and talent notified."}),g.invalidateQueries({queryKey:["likeness-requests",s]}),g.invalidateQueries({queryKey:["admin-stats"]}),v==null||v()}catch(n){k({title:"Error",description:n.message,variant:"destructive"})}finally{T(null)}};if(P||!C||C.length===0)return null;const G=o=>{switch(o){case"pending":return e.jsxs(_,{variant:"outline",className:"border-amber-500 text-amber-600",children:[e.jsx(Ps,{className:"h-3 w-3 mr-1"}),"Pending"]});case"in_progress":return e.jsxs(_,{variant:"outline",className:"border-blue-500 text-blue-600",children:[e.jsx(M,{className:"h-3 w-3 mr-1"}),"In Progress"]});case"completed":return e.jsxs(_,{variant:"outline",className:"border-emerald-500 text-emerald-600",children:[e.jsx(Ie,{className:"h-3 w-3 mr-1"}),"Approved & Retrained"]});case"dismissed":return e.jsxs(_,{variant:"outline",className:"border-muted-foreground text-muted-foreground",children:[e.jsx(Je,{className:"h-3 w-3 mr-1"}),"Declined"]});default:return e.jsx(_,{variant:"outline",children:o})}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h4",{className:"font-semibold text-foreground flex items-center gap-2",children:[e.jsx(De,{className:"h-5 w-5 text-amber-500"}),"Likeness Update Requests"]}),C.map(o=>e.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[G(o.status),e.jsx("span",{className:"text-xs text-muted-foreground",children:Re(new Date(o.created_at),"MMM dd, yyyy h:mm a")})]}),(o.status==="pending"||o.status==="in_progress")&&e.jsx(it,{result:B[o.id]||null}),e.jsx("p",{className:"text-sm text-foreground",children:o.message}),o.image_paths.length>0&&e.jsx("div",{className:"grid grid-cols-4 gap-2",children:o.image_paths.map((n,x)=>e.jsx("div",{className:"aspect-square rounded-lg overflow-hidden border border-border bg-muted",children:I[n]?e.jsx("img",{src:I[n],alt:`Ref ${x+1}`,className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(M,{className:"h-4 w-4 animate-spin text-muted-foreground"})})},x))}),(o.status==="pending"||o.status==="in_progress")&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(w,{size:"sm",onClick:()=>q(o),disabled:!!O,children:[O===o.id?e.jsx(M,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Ie,{className:"h-4 w-4 mr-1"}),"Approve & Retrain"]}),e.jsxs(w,{size:"sm",variant:"destructive",onClick:()=>$(o.id),disabled:!!O,children:[e.jsx(Je,{className:"h-4 w-4 mr-1"}),"Decline"]})]})]},o.id))]})}const lt={craniofacial_structure:{label:"Craniofacial Structure",icon:e.jsx(Fe,{className:"h-4 w-4 text-muted-foreground"})},orbital_region:{label:"Orbital Region",icon:e.jsx(ns,{className:"h-4 w-4 text-muted-foreground"})},nasal_geometry:{label:"Nasal Geometry",icon:e.jsx(Fe,{className:"h-4 w-4 text-muted-foreground"})},perioral_region:{label:"Perioral Region",icon:e.jsx(Fe,{className:"h-4 w-4 text-muted-foreground"})},surface_maps:{label:"Surface Maps",icon:e.jsx($s,{className:"h-4 w-4 text-muted-foreground"})}};function ot({talent:s,open:D,onOpenChange:y,onGenerateDescription:v,isGeneratingDescription:k=!1,onGenerateSamples:g,isGeneratingSamples:I=!1,onRefetch:S,onRegenerateSingleSample:O,regeneratingSampleIndex:T=null}){const[B,z]=i.useState({profileImage:null,onboardingImages:[]}),[C,P]=i.useState(!1),[U,q]=i.useState(!1),[$,G]=i.useState(""),[o,n]=i.useState(!1),[x,m]=i.useState(!1),[F,N]=i.useState(null),[K,r]=i.useState(""),[d,a]=i.useState(!1),{toast:f}=Me(),L=Ae();i.useEffect(()=>{s&&D&&(P(!0),Ue(s).then(z).finally(()=>P(!1)),q(!1),m(!1))},[s,D]);const l=i.useMemo(()=>
31{if(!(s!=null&&s.visual_description))return null;try{return JSON.parse(s.visual_description)}catch{return null}},[s==null?void 0:s.visual_description]),V=l&&!!l.craniofacial_structure,J=!!(s!=null&&s.visual_description)&&!l,Z=()=>{J&&(s!=null&&s.visual_description)?(G(s.visual_description),q(!0)):l&&(G(JSON.stringify(l,null,2)),q(!0))},re=async()=>{if(!(!s||!$)){n(!0);try{let h;try{const H=JSON.parse($);h=JSON.stringify(H)}catch{h=$}const{error:b}=await p.from("talents").update({visual_description:h}).eq("id",s.id);if(b)throw b;f({title:"Description Saved",description:"Visual description updated successfully."}),q(!1),S==null||S()}catch(h){f({title:"Save Failed",description:h.message||"Save error.",variant:"destructive"})}finally{n(!1)}}},ve=async()=>{if(!(!s||F===null||!K.trim())){a(!0);try{const h=[...s.sample_image_urls||[]],b=h[F];h.splice(F,1);const H={sample_image_urls:h,profile_generation_credits:(s.profile_generation_credits??0)+1};s.profile_image_url===b&&(H.profile_image_url=null);const{error:Q}=await p.from("talents").update(H).eq("id",s.id);if(Q)throw Q;const{error:se}=await p.functions.invoke("send-content-violation-email",{body:{talentId:s.id,customMessage:K.trim()}});se&&console.error("Content violation email error:",se);const ie={sample_image_urls:h};s.profile_image_url===b&&(ie.profile_image_url=null),await p.from("public_talent_profiles").update(ie).eq("id",s.id),f({title:"Image Taken Down",description:"Image removed, credit refunded, and content violation email sent."}),N(null),r(""),L.invalidateQueries({queryKey:["talent-roster"]}),S==null||S()}catch(h){f({title:"Error",description:h.message,variant:"destructive"})}finally{a(!1)}}};if(!s)return null;const ae=!!l||J,ye=s.sample_image_urls&&s.sample_image_urls.length>0,Ne=(h,b)=>{if(!b||h==="prompt_injection"||h==="summary"||h==="detailed")return null;const H=lt[h];if(!H)return null;const Q=Object.entries(b);return e.jsxs("div",{className:"p-3 border border-border rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[H.icon,e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase",children:H.label})]}),e.jsx("div",{className:"space-y-1",children:Q.map(([se,ie])=>e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground min-w-[100px] capitalize",children:[se.replace(/_/g," "),":"]}),e.jsx("span",{className:"text-sm text-foreground",children:String(ie)})]},se))})]},h)},be=()=>{if(!l)return null;const h=l;return e.jsxs("div",{className:"space-y-4",children:[h.summary&&e.jsx("div",{className:"p-4 bg-muted/50 rounded-lg border border-border",children:e.jsx("p",{className:"text-foreground font-medium",children:h.summary})}),h.detailed&&e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:Object.entries(h.detailed).map(([b,H])=>e.jsxs("div",{className:"p-3 border border-border rounded-lg",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase",children:b}),e.jsx("p",{className:"text-sm text-foreground mt-1",children:H})]},b))}),h.prompt_injection&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-sm font-medium text-muted-foreground",children:"Prompt Injection"}),e.jsx("div",{className:"p-3 bg-background border border-border rounded-lg",children:e.jsx("p",{className:"text-sm text-foreground font-mono whitespace-pre-wrap",children:h.prompt_injection})})]})]})};return e.jsx(vs,{open:D,onOpenChange:y,children:e.jsxs(ys,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsx(Ns,{children:e.jsx(bs,{className:"text-2xl",children:"Talent Profile"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[C?e.jsx($e,{className:"h-24 w-24 rounded-full"}):B.profileImage?e.jsx("img",{src:B.profileImage,alt:s.name,className:"h-24 w-24 rounded-full object-cover border-2 border-border"}):e.jsx("div",{className:"h-24 w-24 rounded-full bg-muted flex items-center justify-center border-2 border-border",children:e.jsx("span",{className:"text-2xl font-bold text-muted-foreground",children:s.name.charAt(0).toUpperCase()})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h3",{className:"text-xl font-bold text-foreground",children:s.name}),s.is_founding_talent&&e.jsx(_,{className:"bg-primary",children:"Founding Talent"}),e.jsx(_,{variant:"outline",children:s.status})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(Ee,{className:"h-3.5 w-3.5"}),s.email]}),s.phone&&e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(Es,{className:"h-3.5 w-3.5"}),s.phone]}),s.location&&e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(As,{className:"h-3.5 w-3.5"}),s.location]}),s.approved_at&&e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(Ms,{className:"h-3.5 w-3.5"}),"Approved ",Re(new Date(s.approved_at),"MMM dd, yyyy")]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"font-semibold text-foreground flex items-center gap-2",children:[e.jsx(ke,{className:"h-5 w-5 text-accent"}),"Sample Images"]}),g&&e.jsx(w,{variant:"outline",size:"sm",onClick:()=>g(s),disabled:I,children:I?e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"h-4 w-4 mr-1 animate-spin"}),"Generating..."]}):ye?e.jsxs(e.Fragment,{children:[e.jsx(Ce,{className:"h-4 w-4 mr-1"}),"Regenerate"]}):e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"h-4 w-4 mr-1"}),"Generate"]})})]}),ye?e.jsx("div",{className:"grid grid-cols-3 gap-4",children:s.sample_image_urls.map((h,b)=>e.jsxs("div",{className:"relative group aspect-square rounded-lg overflow-hidden border border-border",children:[e.jsx("img",{src:h,alt:`Sample ${b+1}`,className:"w-full h-full object-cover"}),e.jsx("div",{className:"absolute top-0 right-0 p-1.5 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(w,{variant:"ghost",size:"icon",className:"h-6 w-6 bg-destructive/80 hover:bg-destructive text-white",onClick:()=>{N(b),r("")},title:"Take down this image",children:e.jsx(ze,{className:"h-3.5 w-3.5"})})}),e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/60 to-transparent p-2 flex items-end justify-between",children:[e.jsx("span",{className:"text-xs text-white font-medium",children:b===0?"Headshot":b===1?"Lifestyle":"Creative"}),O&&e.jsx(w,{variant:"ghost",size:"icon",className:"h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity bg-black/40 hover:bg-black/60 text-white",onClick:()=>O(s,b,b),disabled:I||T!==null,title:`Regenerate ${b===0?"Headshot":b===1?"Lifestyle":"Creative"}`,children:T===b?e.jsx(M,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ce,{className:"h-3.5 w-3.5"})})]})]},b))}):e.jsxs("div",{className:"p-6 border-2 border-dashed border-border rounded-lg flex flex-col items-center justify-center text-center",children:[e.jsx(ke,{className:"h-8 w-8 text-muted-foreground mb-2"}),e.jsx("p",{className:"text-muted-foreground mb-1",children:"No sample images generated yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sample images showcase how the talent looks in AI-generated scenes"})]})]}),e.jsx(me,{open:F!==null,onOpenChange:h=>{h||(N(null),r(""))},children:e.jsxs(ue,{children:[e.jsxs(he,{children:[e.jsxs(xe,{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-5 w-5 text-destructive"}),"Take Down Profile Image"]}),e.jsx(ge,{children:"This will remove the image from the talent's profile, refund them a generation credit, and send them a notification with your reason."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-foreground",children:"Reason for takedown *"}),e.jsx(Le,{placeholder:"e.g. Image contains multiple people which violates our solo-shot policy...",value:K,onChange:h=>r(h.target.value),className:"min-h-[100px]"})]}),e.jsxs(pe,{children:[e.jsx(fe,{disabled:d,children:"Cancel"}),e.jsxs(je,{onClick:h=>{h.preventDefault(),ve()},disabled:!K.trim()||d,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[d?e.jsx(M,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(ze,{className:"h-4 w-4 mr-1"}),"Take Down & Notify"]})]})]})}),s.bio&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-semibold text-foreground",children:"Bio"}),e.jsx("p",{className:"text-foreground",children:s.bio})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"font-semibold text-foreground flex items-center gap-2",children:[e.jsx(_e,{className:"h-5 w-5 text-accent"}),J?"Visual Description":"Identity Lock"," ",V?e.jsx(_,{variant:"outline",className:"text-xs",children:"Fingerprint"}):J?e.jsx(_,{variant:"outline",className:"text-xs text-emerald-600 border-emerald-600",children:"Prose"}):l?e.jsx(_,{variant:"outline",className:"text-xs text-amber-600 border-amber-600",children:"Legacy"}):null]}),e.jsxs("div",{className:"flex items-center gap-2",children:[ae&&!J&&e.jsx(w,{variant:"ghost",size:"sm",onClick:()=>m(!x),children:x?"Structured":"Raw JSON"}),v&&e.jsx(w,{variant:"outline",size:"sm",onClick:()=>v(s),disabled:k,children:k?e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"h-4 w-4 mr-1 animate-spin"}),"Generating..."]}):ae?e.jsxs(e.Fragment,{children:[e.jsx(Ce,{className:"h-4 w-4 mr-1"}),"Regenerate"]}):e.jsxs(e.Fragment,{children:[e.jsx(_e,{className:"h-4 w-4 mr-1"}),"Generate"]})})]})]}),ae?e.jsx("div",{className:"space-y-4",children:U?e.jsxs("div",{className:"space-y-3",children:[e.jsx(Le,{value:$,onChange:h=>G(h.target.value),className:J?"min-h-[300px] text-sm":"min-h-[400px] font-mono text-xs"}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(w,{variant:"outline",size:"sm",onClick:()=>q(!1),disabled:o,children:"Cancel"}),e.jsxs(w,{size:"sm",onClick:re,disabled:o,children:[o?e.jsx(M,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(rs,{className:"h-4 w-4 mr-1"}),"Save"]})]})]}):J?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"p-4 bg-muted/30 rounded-lg border border-border",children:e.jsx("p",{className:"text-sm text-foreground leading-relaxed whitespace-pre-wrap",children:s.visual_description})}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{variant:"outline",size:"sm",onClick:Z,children:[e.jsx(we,{className:"h-4 w-4 mr-1"}),"Edit"]})})]}):x?e.jsxs("div",{className:"space-y-3",children:[e.jsx("pre",{className:"p-4 bg-muted/50 rounded-lg border border-border text-xs font-mono overflow-auto max-h-[500px] text-foreground",children:JSON.stringify(l,null,2)}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{variant:"outline",size:"sm",onClick:Z,children:[e.jsx(we,{className:"h-4 w-4 mr-1"}),"Edit JSON"]})})]}):V?e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:Object.entries(l).map(([h,b])=>Ne(h,b))}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{variant:"outline",size:"sm",onClick:Z,children:[e.jsx(we,{className:"h-4 w-4 mr-1"}),"Edit JSON"]})})]}):e.jsxs("div",{className:"space-y-4",children:[be(),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{variant:"outline",size:"sm",onClick:Z,children:[e.jsx(we,{className:"h-4 w-4 mr-1"}),"Edit JSON"]})})]})}):e.jsxs("div",{className:"p-6 border-2 border-dashed border-border rounded-lg flex flex-col items-center justify-center text-center",children:[e.jsx(_e,{className:"h-8 w-8 text-muted-foreground mb-2"}),e.jsx("p",{className:"text-muted-foreground mb-1",children:"No visual description generated yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:`Click "Generate" to create a visual description from the talent's images`})]})]}),s.portfolio_url&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-semibold text-foreground",children:"Portfolio"}),e.jsx("a",{href:s.portfolio_url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:s.portfolio_url})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-semibold text-foreground",children:"Statistics"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"p-4 border border-border rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(as,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Current Month"})]}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:s.current_month_generations}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generations"})]}),e.jsxs("div",{className:"p-4 border border-border rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Te,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total"})]}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:s.total_generations}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generations"})]}),e.jsxs("div",{className:"p-4 border border-border rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(is,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Royalties"})]}),e.jsxs("p",{className:"text-2xl font-bold text-foreground",children:["$",Number(s.total_royalties_earned).toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Earned"})]}),e.jsxs("div",{className:"p-4 border border-border rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Te,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Tier"})]}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:s.current_royalty_tier}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Royalty Tier"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-semibold text-foreground",children:"Content Restrictions"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.exclude_politics&&e.jsx(_,{variant:"outline",children:"Exclude Politics"}),s.exclude_religion&&e.jsx(_,{variant:"outline",children:"Exclude Religion"}),s.exclude_alcohol&&e.jsx(_,{variant:"outline",children:"Exclude Alcohol"}),!s.exclude_politics&&!s.exclude_religion&&!s.exclude_alcohol&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No content restrictions"})]})]}),e.jsx(nt,{talentId:s.id,talentName:s.name,talentEmail:s.email,onRefetch:S}),e.jsx(at,{talentId:s.id,currentImages:s.onboarding_image_paths,adminMode:!0,onImagesUpdated:()=>{S==null||S(),P(!0),Ue(s).then(z).finally(()=>P(!1))}})]})]})})}function ct({talents:s,isLoading:D,onRefetch:y}){const[v,k]=i.useState(null),[g,I]=i.useState(!1),[S,O]=i.useState(!1),[T,B]=i.useState(null),[z,C]=i.useState(!1),[P,U]=i.useState(null),[q,$]=i.useState(null),[G,o]=i.useState(null),[n,x]=i.useState(null),[m,F]=i.useState(null),[N,K]=i.useState(!1),{toast:r}=Me(),d=ws(),[a,f]=i.useState(new Set),[L,l]=i.useState(!1),[V,J]=i.useState(!1),[Z,re]=i.useState(!1),[ve,ae]=i.useState(!1),[ye,Ne]=i.useState(null),be=s.length>0&&a.size===s.length,h=a.size>0&&a.size<s.length,b=()=>{f(be?new Set:new Set(s.map(t=>
31t.id)))},H=t=>{f(u=>{const c=new Set(u);return c.has(t)?c.delete(t):c.add(t),c})},Q=v&&s.find(t=>t.id===v)||null,se=t=>{k(t.id),I(!0)},ie=t=>{B(t),O(!0)},ls=async()=>{if(!m)return;const t=m.status!=="suspended";K(!0);try{const{error:u}=await p.from("talents").update({status:t?"suspended":"approved"}).eq("id",m.id);if(u)throw u;r({title:t?"Account suspended":"Account restored",description:t?"Removed from the public library and access disabled. No email was sent.":"Profile is live again and access restored. No email was sent."}),F(null),y()}catch(u){r({title:"Error",description:u.message||"Failed to update account",variant:"destructive"})}finally{K(!1)}},Oe=async t=>{var u,c;U(t.id);try{const{data:j,error:E}=await p.functions.invoke("analyze-talent-images",{body:{talentId:t.id,saveToDatabase:!0}});if(E){let A=E.message;try{const ee=await((c=(u=E.context)==null?void 0:u.json)==null?void 0:c.call(u));ee!=null&&ee.error&&(A=ee.error)}catch{}throw new Error(A||"Edge function returned an error")}if(j&&!j.success)throw new Error(j.error||"Analysis returned unsuccessful result");r({title:"Description Generated",description:`Visual description for ${t.name} has been created and saved.`}),y()}catch(j){console.error("Error generating description:",j),r({title:"Generation Failed",description:j.message||"Failed to generate visual description. Please try again.",variant:"destructive"})}finally{U(null)}},os=async t=>{$(t.id);try{await p.from("talents").update({sample_image_urls:[]}).eq("id",t.id);const{data:u,error:c}=await p.functions.invoke("generate-sample-images",{body:{talentId:t.id,promptIndex:0,totalPrompts:3}});if(c)throw c;r({title:"Sample Image Generation Started",description:`Generating 3 sample images for ${t.name}. They will appear progressively over ~3 minutes.`}),y()}catch(u){console.error("Error generating samples:",u),r({title:"Generation Failed",description:u.message||"Failed to generate sample images. Please try again.",variant:"destructive"})}finally{$(null)}},cs=async(t,u,c)=>{Ne(c);try{const{data:j,error:E}=await p.functions.invoke("generate-sample-images",{body:{talentId:t.id,promptIndex:u,replaceIndex:c}});if(E)throw E;r({title:"Image Regenerated",description:`Replaced ${c===0?"Headshot":c===1?"Lifestyle":"Creative"} image for ${t.name}.`}),y()}catch(j){console.error("Error regenerating single sample:",j),r({title:"Regeneration Failed",description:j.message||"Failed to regenerate sample image.",variant:"destructive"})}finally{Ne(null)}},ds=async t=>{o(t.id);try{const{data:u,error:c}=await p.functions.invoke("send-talent-account-email",{body:{talentId:t.id}});if(c)throw c;r({title:"Account Email Sent",description:`Password setup email sent to ${t.email}`})}catch(u){console.error("Error sending account email:",u),r({title:"Email Failed",description:u.message||"Failed to send account email. Please try again.",variant:"destructive"})}finally{o(null)}},ms=async()=>{if(T){C(!0);try{const{error:t}=await p.functions.invoke("delete-talent",{body:{talentId:T.id}});if(t)throw t;r({title:"Talent Deleted",description:`${T.name} has been removed from the roster.`}),O(!1),y()}catch(t){console.error("Error deleting talent:",t),r({title:"Delete Failed",description:t.message||"Failed to delete talent. Please try again.",variant:"destructive"})}finally{C(!1),B(null)}}},us=t=>{t.visual_description?se(t):Oe(t)},hs=async()=>{const t=s.filter(j=>a.has(j.id));if(t.length===0)return;re(!0);let u=0,c=0;for(let j=0;j<t.length;j++){const E=t[j];try{const{data:A,error:ee}=await p.functions.invoke("send-talent-account-email",{body:{talentId:E.id}});if(ee)throw ee;if(A!=null&&A.error)throw new Error(A.error);u++}catch(A){console.error(`Failed to send login email to ${E.name}:`,(A==null?void 0:A.message)||A),c++}j<t.length-1&&await new Promise(A=>setTimeout(A,500))}r({title:"Bulk Send Complete",description:`Sent ${u} login email${u!==1?"s":""}${c>0?`, ${c} failed`:""}.`,variant:c>0?"destructive":"default"}),re(!1),f(new Set)},xs=async()=>{const t=s.filter(j=>a.has(j.id));if(t.length===0)return;J(!0);let u=0,c=0;for(const j of t)try{const{error:E}=await p.functions.invoke("delete-talent",{body:{talentId:j.id}});if(E)throw E;u++}catch{c++}r({title:"Bulk Delete Complete",description:`Deleted ${u} talent${u!==1?"s":""}${c>0?`, ${c} failed`:""}.`,variant:c>0?"destructive":"default"}),J(!1),l(!1),f(new Set),y()},gs=async()=>{const t=s.filter(j=>a.has(j.id));if(t.length===0)return;ae(!0);let u=0,c=0;for(const j of t)try{const{error:E}=await p.functions.invoke("analyze-talent-images",{body:{talentId:j.id,saveToDatabase:!0}});if(E)throw E;u++}catch{c++}r({title:"Batch Fingerprint Complete",description:`Generated ${u} Identity Lock${u!==1?"s":""}${c>0?`, ${c} failed`:""}.`,variant:c>0?"destructive":"default"}),ae(!1),f(new Set),y()};return D?e.jsx("div",{className:"space-y-3",children:Array.from({length:5}).map((t,u)=>e.jsx($e,{className:"h-16 w-full"},u))}):s.length===0?e.jsx("div",{className:"flex flex-col items-center justify-center py-12 border-2 border-dashed border-border rounded-lg",children:e.jsx("p",{className:"text-muted-foreground",children:"No approved talents found"})}):e.jsxs(e.Fragment,{children:[a.size>0&&e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border bg-muted/50 px-4 py-3 mb-4",children:[e.jsxs("span",{className:"text-sm font-medium text-foreground",children:[a.size," selected"]}),e.jsx("div",{className:"flex-1"}),e.jsxs(w,{variant:"outline",size:"sm",onClick:gs,disabled:ve,children:[ve?e.jsx(M,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(_e,{className:"h-4 w-4 mr-1"}),"Fingerprint (",a.size,")"]}),e.jsxs(w,{variant:"outline",size:"sm",onClick:()=>{const t=s.filter(c=>a.has(c.id)),u=Rs(t.filter(c=>!!c.email).map(c=>({email:c.email,name:c.name,type:"talent"})));r({title:"Added to Email Blast",description:`${u} new recipient${u!==1?"s":""} staged. Opening Communications…`}),f(new Set),d("/admin/communications")},children:[e.jsx(Ls,{className:"h-4 w-4 mr-1"}),"Add to Email Blast (",a.size,")"]}),e.jsxs(w,{variant:"outline",size:"sm",onClick:hs,disabled:Z,children:[Z?e.jsx(M,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Ee,{className:"h-4 w-4 mr-1"}),"Send Logins (",a.size,")"]}),e.jsxs(w,{variant:"destructive",size:"sm",onClick:()=>l(!0),disabled:V,children:[e.jsx(Ke,{className:"h-4 w-4 mr-1"}),"Delete (",a.size,")"]})]}),e.jsx("div",{className:"border rounded-lg",children:e.jsxs(Ss,{children:[e.jsx(ks,{children:e.jsxs(qe,{children:[e.jsx(X,{className:"w-[40px]",children:e.jsx(Ge,{checked:be?!0:h?"indeterminate":!1,onCheckedChange:b,"aria-label":"Select all"})}),e.jsx(X,{children:"Name"}),e.jsx(X,{children:"Email"}),e.jsx(X,{children:"Location"}),e.jsx(X,{children:"Tier"}),e.jsx(X,{children:"Fingerprint"}),e.jsx(X,{children:"Castings"}),e.jsx(X,{children:"Generations"}),e.jsx(X,{children:"Credits left"}),e.jsx(X,{children:"Approved"}),e.jsx(X,{children:"Onboarding"}),e.jsx(X,{className:"text-right",children:"Actions"})]})}),e.jsx(Cs,{children:s.map(t=>{const u=!!t.visual_description,c=P===t.id;return e.jsxs(qe,{"data-state":a.has(t.id)?"selected":void 0,children:[e.jsx(W,{children:e.jsx(Ge,{checked:a.has(t.id),onCheckedChange:()=>H(t.id),"aria-label":`Select ${t.name}`})}),e.jsx(W,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:t.name}),t.status==="suspended"&&e.jsxs(_,{variant:"destructive",className:"text-[10px]",children:[e.jsx(Ve,{className:"h-3 w-3 mr-1"}),"Suspended"]})]})}),e.jsx(W,{children:t.email}),e.jsx(W,{children:t.location||"N/A"}),e.jsx(W,{children:t.is_founding_talent?e.jsxs(_,{className:"bg-primary",children:[e.jsx(Te,{className:"h-3 w-3 mr-1"}),"Founding"]}):e.jsxs(_,{variant:"outline",children:["Tier ",t.current_royalty_tier]})}),e.jsx(W,{children:e.jsx("button",{onClick:()=>
31us(t),disabled:c,className:"cursor-pointer disabled:cursor-wait",children:c?e.jsxs(_,{variant:"outline",className:"text-muted-foreground",children:[e.jsx(M,{className:"h-3 w-3 mr-1 animate-spin"}),"Generating..."]}):u?e.jsxs(_,{variant:"outline",className:"text-green-600 border-green-600 hover:bg-green-600/10 transition-colors",children:[e.jsx(He,{className:"h-3 w-3 mr-1"}),"View"]}):e.jsxs(_,{variant:"outline",className:"text-muted-foreground hover:text-foreground hover:border-foreground transition-colors",children:[e.jsx(Us,{className:"h-3 w-3 mr-1"}),"Generate"]})})}),e.jsx(W,{children:e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"font-medium",children:t.total_castings}),e.jsxs("div",{className:"text-muted-foreground",children:[t.current_month_castings," this month"]})]})}),e.jsx(W,{children:e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"font-medium",children:t.total_generations}),e.jsxs("div",{className:"text-muted-foreground",children:[t.current_month_generations," this month"]})]})}),e.jsx(W,{children:(()=>{const j=t.profile_generation_credits??0;return e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"font-medium",children:j}),e.jsxs("div",{className:"text-muted-foreground",children:["of ",5]})]})})()}),e.jsx(W,{children:t.approved_at?Re(new Date(t.approved_at),"MMM dd, yyyy"):"N/A"}),e.jsx(W,{children:(()=>{const j=!!t.identity_verified,E=!!t.stripe_connect_account_id,A=[{key:"biometric",label:"Biometric consent",at:t.biometric_consent_at},{key:"research",label:"Research opt-in",at:t.research_opt_in_at},{key:"terms",label:"Terms accepted",at:t.terms_accepted_at},{key:"downloaded",label:"Downloaded content ack",at:t.downloaded_content_ack_at}],ee=A.filter(Y=>!!Y.at).length,ps=ee===A.length,Be=!!t.onboarding_completed,fs=[{key:"identity",short:"ID",Icon:Bs,done:j,tooltip:j?"Identity verified":"Identity not verified"},{key:"payouts",short:"Pay",Icon:Hs,done:E,tooltip:E?"Payouts connected":"Payouts not connected"},{key:"consents",short:"Consent",Icon:Qs,done:ps,tooltip:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"font-medium",children:["Consents (",ee,"/",A.length,")"]}),A.map(Y=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[Y.at?e.jsx(He,{className:"h-3 w-3 text-green-600"}):e.jsx("span",{className:"h-3 w-3 inline-block"}),e.jsx("span",{children:Y.label})]},Y.key))]})},{key:"complete",short:"Done",Icon:Ie,done:Be,tooltip:Be?"Onboarding complete":"Onboarding not complete"}];return e.jsx(Ze,{delayDuration:150,children:e.jsx("div",{className:"flex items-center gap-1",children:fs.map(Y=>e.jsxs(es,{children:[e.jsx(ss,{asChild:!0,children:e.jsxs(_,{variant:"outline",className:Y.done?"text-green-600 border-green-600 gap-1":"text-muted-foreground gap-1",children:[e.jsx(Y.Icon,{className:"h-3 w-3"}),Y.short]})}),e.jsx(ts,{children:Y.tooltip})]},Y.key))})})})()}),e.jsx(W,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsxs(w,{variant:"outline",size:"sm",onClick:()=>ds(t),disabled:G===t.id,children:[G===t.id?e.jsx(M,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Ee,{className:"h-4 w-4 mr-1"}),"Send Login"]}),e.jsxs(w,{variant:"outline",size:"sm",onClick:()=>x(t),children:[e.jsx(qs,{className:"h-4 w-4 mr-1"}),"Gift"]}),e.jsxs(w,{variant:"outline",size:"sm",onClick:()=>se(t),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"View Profile"]}),e.jsx(w,{variant:"outline",size:"sm",onClick:()=>F(t),children:t.status==="suspended"?e.jsxs(e.Fragment,{children:[e.jsx(Ws,{className:"h-4 w-4 mr-1"}),"Restore"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ve,{className:"h-4 w-4 mr-1"}),"Suspend"]})}),e.jsxs(w,{variant:"destructive",size:"sm",onClick:()=>ie(t),children:[e.jsx(Ke,{className:"h-4 w-4 mr-1"}),"Delete"]})]})})]},t.id)})})]})}),e.jsx(ot,{talent:Q,open:g,onOpenChange:I,onGenerateDescription:Oe,isGeneratingDescription:P===(Q==null?void 0:Q.id),onGenerateSamples:os,isGeneratingSamples:q===(Q==null?void 0:Q.id),onRegenerateSingleSample:cs,regeneratingSampleIndex:ye,onRefetch:y}),e.jsx(me,{open:S,onOpenChange:O,children:e.jsxs(ue,{children:[e.jsxs(he,{children:[e.jsx(xe,{children:"Delete Talent"}),e.jsxs(ge,{children:["Are you sure you want to delete ",e.jsx("strong",{children:T==null?void 0:T.name})," from the roster? This will remove their profile and images from storage. Past generations they were involved in will remain intact.",e.jsx("br",{}),e.jsx("br",{}),e.jsx("strong",{className:"text-destructive",children:"This action cannot be undone."})]})]}),e.jsxs(pe,{children:[e.jsx(fe,{disabled:z,children:"Cancel"}),e.jsx(je,{onClick:ms,disabled:z,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:z?"Deleting...":"Delete Talent"})]})]})}),e.jsx(me,{open:L,onOpenChange:l,children:e.jsxs(ue,{children:[e.jsxs(he,{children:[e.jsxs(xe,{children:["Delete ",a.size," Talent",a.size!==1?"s":""]}),e.jsxs(ge,{children:["Are you sure you want to delete ",e.jsxs("strong",{children:[a.size," talent",a.size!==1?"s":""]})," from the roster? This will remove their profiles and images from storage. Past generations they were involved in will remain intact.",e.jsx("br",{}),e.jsx("br",{}),e.jsx("strong",{className:"text-destructive",children:"This action cannot be undone."})]})]}),e.jsxs(pe,{children:[e.jsx(fe,{disabled:V,children:"Cancel"}),e.jsx(je,{onClick:xs,disabled:V,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:V?e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"h-4 w-4 mr-1 animate-spin"}),"Deleting..."]}):`Delete ${a.size} Talent${a.size!==1?"s":""}`})]})]})}),e.jsx(me,{open:!!m,onOpenChange:t=>{t||F(null)},children:e.jsxs(ue,{children:[e.jsxs(he,{children:[e.jsx(xe,{children:(m==null?void 0:m.status)==="suspended"?"Restore Account":"Suspend Account"}),e.jsx(ge,{children:(m==null?void 0:m.status)==="suspended"?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:m==null?void 0:m.name})," will be listed in the public talent library again and regain access to their talent dashboard. No email will be sent."]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:m==null?void 0:m.name})," will be hidden from the public talent library, become uncastable, and lose access to their talent dashboard. Their records and past generations stay intact and you can restore them at any time. No email will be sent."]})})]}),e.jsxs(pe,{children:[e.jsx(fe,{disabled:N,children:"Cancel"}),e.jsx(je,{onClick:ls,disabled:N,className:(m==null?void 0:m.status)==="suspended"?void 0:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:N?e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"h-4 w-4 mr-1 animate-spin"}),"Saving..."]}):(m==null?void 0:m.status)==="suspended"?"Restore Account":"Suspend Account"})]})]})}),e.jsx(Gs,{open:!!n,onOpenChange:t=>{t||x(null)},targetType:"talent",targetId:(n==null?void 0:n.id)??null,targetName:(n==null?void 0:n.name)??null,onDone:y})]})}function ar(){const{talents:s,isLoading:D,refetch:y}=Ys(),[v,k]=i.useState("all"),[g,I]=i.useState("all"),[S,O]=i.useState(""),[T,B]=i.useState(!1),[z,C]=i.useState(""),[P,U]=i.useState(!1),[q,$]=i.useState(""),G=v==="all"?s:s.filter(r=>r.current_royalty_tier===Number(v)),o=g==="all"?G:G.filter(r=>{const d=Os(r);return g==="complete"?d:!d}),n=S.trim()?o.filter(r=>r.name.toLowerCase().includes(S.toLowerCase())||r.email.toLowerCase().includes(S.toLowerCase())):o,x={total:n.length,founding:n.filter(r=>r.is_founding_talent).length,activeThisMonth:n.filter(r=>r.current_month_generations>0).length,totalRoyalties:n.reduce((r,d)=>r+Number(d.total_royalties_earned),0)},m=s.filter(r=>!r.gender).length,F=async()=>{B(!0),C("Starting batch analysis...");let r=0,d=m;try{let a=0;for(;d>0;){C(`Processing batch... (${r} done, ~${d} remaining)`);const{data:f,error:L}=await p.functions.invoke("batch-analyze-demographics",{body:{batchSize:5}});if(L){console.error("Batch analyze error:",L),R.error(`Batch analysis failed: ${L.message}`);break}if(r+=f.succeeded||0,d=f.remaining||0,f.failed>0&&R.warning(`${f.failed}
31 talent(s) failed analysis in this batch`),(f.succeeded||0)===0?a++:a=0,C(`Processed ${r} talents. ${d} remaining...`),d===0||f.processed===0)break;if(a>=3){R.error(`Stopped: ${d} talent(s) have images that can't be analyzed (too large or missing).`);break}await new Promise(l=>setTimeout(l,1e3))}R.success(`Demographics backfill complete! ${r} talents updated.`),y()}catch(a){console.error("Batch analyze error:",a),R.error("Failed to run batch analysis")}finally{B(!1),C("")}},N=s.filter(r=>{var a,f;if((((a=r.onboarding_image_paths)==null?void 0:a.length)||0)===0)return!1;const d=(f=r.visual_description)==null?void 0:f.trim();return!!(!d||d.startsWith("{")||d.startsWith("[")||/"(gender|age|ethnicity|hair|eyes|skin|face)"/.test(d))}),K=async()=>{if(N.length===0){R.info("All talents already have prose descriptions");return}U(!0);let r=0,d=0,a=0;for(let f=0;f<N.length;f++){const L=N[f];$(`Reanalyzing ${L.name} (${f+1}/${N.length})...`);try{const{error:l}=await p.functions.invoke("analyze-talent-images",{body:{talentId:L.id,saveToDatabase:!0}});if(l)throw l;r++,a=0}catch(l){console.error(`Failed to reanalyze ${L.name}:`,l),d++,a++}if(a>=5){R.error(`Stopped after 5 consecutive failures. ${N.length-f-1} talents remaining.`);break}f<N.length-1&&await new Promise(l=>setTimeout(l,2e3))}R.success(`Reanalysis complete! ${r} updated${d>0?`, ${d} failed`:""}.`),U(!1),$(""),y()};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold tracking-tight text-foreground",children:"Talent Roster"}),e.jsx("p",{className:"text-muted-foreground",children:"View and manage approved talents"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[e.jsx("strong",{children:"Tier 0 (Founding):"})," Fixed royalties, not performance-based.",e.jsx("strong",{className:"ml-2",children:"Tiers 1-3:"})," Performance-based royalties after launch."]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[N.length>0&&e.jsxs(w,{variant:"outline",size:"sm",onClick:K,disabled:P||T,className:"gap-2",children:[P?e.jsx(M,{className:"h-4 w-4 animate-spin"}):e.jsx(Ce,{className:"h-4 w-4"}),P?q:`Reanalyze Missing Descriptions (${N.length})`]}),m>0&&e.jsxs(w,{variant:"outline",size:"sm",onClick:F,disabled:T||P,className:"gap-2",children:[T?e.jsx(M,{className:"h-4 w-4 animate-spin"}):e.jsx(Xs,{className:"h-4 w-4"}),T?z:`Backfill Demographics (${m})`]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-4",children:[e.jsxs(le,{children:[e.jsxs(oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ce,{className:"text-sm font-medium",children:"Total Talents"}),e.jsx(Ks,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(de,{children:[e.jsx("div",{className:"text-2xl font-bold",children:x.total}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Approved talents"})]})]}),e.jsxs(le,{children:[e.jsxs(oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ce,{className:"text-sm font-medium",children:"Founding Talents"}),e.jsx(Te,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(de,{children:[e.jsx("div",{className:"text-2xl font-bold",children:x.founding}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Special status"})]})]}),e.jsxs(le,{children:[e.jsxs(oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ce,{className:"text-sm font-medium",children:"Active This Month"}),e.jsx(as,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(de,{children:[e.jsx("div",{className:"text-2xl font-bold",children:x.activeThisMonth}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"With generations"})]})]}),e.jsxs(le,{children:[e.jsxs(oe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(ce,{className:"text-sm font-medium",children:"Total Royalties"}),e.jsx(is,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(de,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:["$",x.totalRoyalties.toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Paid to talents"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"relative w-[280px]",children:[e.jsx(Vs,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(Js,{placeholder:"Search by name or email...",value:S,onChange:r=>O(r.target.value),className:"pl-9"})]}),e.jsx("label",{htmlFor:"tier-filter",className:"text-sm font-medium text-foreground",children:"Filter by Tier:"}),e.jsxs(Qe,{value:v,onValueChange:r=>k(r),children:[e.jsx(Xe,{id:"tier-filter",className:"w-[240px]",children:e.jsx(We,{placeholder:"Select tier"})}),e.jsxs(Ye,{children:[e.jsx(te,{value:"all",children:"All Tiers"}),e.jsx(te,{value:"0",children:"Tier 0 - Founding (Fixed Royalties)"}),e.jsx(te,{value:"1",children:"Tier 1 - Starter (0-1K gens/month)"}),e.jsx(te,{value:"2",children:"Tier 2 - Rising (1K-5K gens/month)"}),e.jsx(te,{value:"3",children:"Tier 3 - Elite (5K+ gens/month)"})]})]}),e.jsx("label",{htmlFor:"onboarding-filter",className:"text-sm font-medium text-foreground",children:"Onboarding:"}),e.jsxs(Qe,{value:g,onValueChange:r=>I(r),children:[e.jsx(Xe,{id:"onboarding-filter",className:"w-[180px]",children:e.jsx(We,{})}),e.jsxs(Ye,{children:[e.jsx(te,{value:"all",children:"All"}),e.jsx(te,{value:"complete",children:"Complete"}),e.jsx(te,{value:"incomplete",children:"Incomplete"})]})]})]}),e.jsx(ct,{talents:n,isLoading:D,onRefetch:y})]})}export{ar 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.