PageSourceSearch

https://www.wequal.com/assets/AdminVideoIngestion-BTAgeP1u.js

js wequal.com collected 2026-10-06 11:08:57 UTC 67,908 bytes, 7 lines download raw bytes

1import{f as bs,r as l,s as u,aO as D,j as e,cc as Le,cd as Pe,d$ as ws,aj as L,ch as oe,bg as Ns,d as Ae,cr as Re,c as De,a9 as qe,a_ as Ce,a$ as ye,b0 as Se,b1 as Fe,b3 as de,b2 as I,c7 as as,v as H,aa as ns,aE as Ye,ce as Ue,cf as Oe,bI as Te,an as vs,cl as rs,ao as ks,ci as We,cI as Cs,a2 as He,dd as Ge,dc as is,f0 as ys,du as Ss,at as J,au as Z,av as ee,bh as Fs,b as Ts,b7 as $s,a3 as Xe,aK as Es,b6 as Ms,dv as Je,E as Ds,ap as As}from"./index-CGIDmj67.js";import{T as qs,a as Ls,b as Ie,c as se,d as Ps,e as X}from"./table-BBkeifDH.js";import{A as Rs,a as Is,b as Bs,c as Vs,d as zs,e as Us,f as Os,g as Ws}from"./alert-dialog-Dr1GlKwx.js";import{S as $e}from"./separator-CraldfF0.js";import{u as ls}from"./useIngestionLog-7yF9RYhY.js";import{P as Hs}from"./plus-BmiHZZTv.js";import{S as Ks}from"./scroll-area-DoM5Jluu.js";import{C as Qs}from"./ClipVerificationDialog-gowLjAm1.js";import{F as Ys}from"./fast-forward-BG1INOdq.js";import{C as Gs}from"./circle-check-big-ZQlu5rUe.js";import{A as Xs}from"./arrow-up-down-CkjkvpW-.js";import{A as Js,a as Zs}from"./arrow-up-tNTPR-di.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 et=bs("SpellCheck",[["path",{d:"m6 16 6-12 6 12",key:"1b4byz"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"m16 20 2 2 4-4",key:"13tcca"}]]);function Ze(t){const o=de(new Date(t.session_date),"dd MMM yy"),j=t.speaker_name||t.host_name||"Unknown",C=t.speaker_company||t.host_company,N=C?` (${C})`:"",d=t.session_time?` (${t.session_time.slice(0,5)} UTC)`:"";return`${j}${N} - ${o} - ${t.title}${d}`}function je(t){return t.toLowerCase().replace(/\.[^.]+$/,"").replace(/[^\w\s]/g," ").replace(/\s+/g," ").trim()}function st(t){const o=t.match(/^WQ\s+(RL|EX)[_ ](\d{6})[_ ](.+?)\s*\(([^)]+)\)[_ ]([^_]+)[_ ](.+)\.vtt$/i);return o?{program:o[1].toUpperCase(),date:o[2],title:o[3].trim(),region:o[4].trim(),speaker:o[5].trim(),company:o[6].trim()}:null}function es(t,o){const j=je(t),C=je(o);if(j===C)return 1;if(j.includes(C)||C.includes(j))return .9;const N=new Set(j.split(" ")),d=new Set(C.split(" ")),b=[...N].filter($=>d.has($)),g=new Set([...N,...d]);return b.length/g.size}function tt(t,o){const j=t.toLowerCase(),C=[o.speaker_name,o.host_name].filter(Boolean);for(const N of C){const d=N.toLowerCase();if(d===j)return!0;const b=j.split(/\s+/).filter(B=>B.length>2),g=d.split(/\s+/).filter(B=>B.length>2),$=b[b.length-1],W=g[g.length-1];if($&&W&&$===W)return!0}return!1}function Be(t,o){const j=je(t),C=[o.speaker_name,o.host_name].filter(Boolean);let N=0;for(const d of C){const b=d.toLowerCase().split(/\s+/).filter(W=>W.length>2);if(j.includes(d.toLowerCase())){N=Math.max(N,4);break}const g=b[b.length-1];g&&g.length>2&&j.includes(g)&&(N=Math.max(N,3));const $=b[0];$&&$.length>2&&j.includes($)&&(N=Math.max(N,1))}return N}function at(t,o){const j=t.toLowerCase();let C=0;const N=[o.speaker_name,o.host_name].filter(Boolean),d=[o.speaker_company,o.host_company].filter(Boolean),b=[...new Set(N.map($=>$.toLowerCase()))],g=[...new Set(d.map($=>$.toLowerCase()))];for(const $ of b){const W=$.split(/\s+/);j.includes($)?C+=3:W.forEach(B=>{B.length>2&&j.includes(B)&&(C+=1)})}for(const $ of g)j.includes($)&&(C+=2);return C}function ss(t){if(t.length<=1)return!1;const o=t.map(d=>d.recording_url).filter(Boolean),j=new Set(o);if(o.length>0&&j.size<o.length)return!0;const C=t.map(d=>je(d.speaker_name||d.host_name||"")).filter(d=>d.length>0),N=new Set(C);return C.length>1&&N.size===1}function ts(t){const o=t.chunk_count||0,j=t.transcript_status==="complete";return!j&&o===0?{stage:0,label:"0/4"}:j&&o===0?{stage:1,label:"1/4"}:{stage:2,label:`${o} chunks`}}const nt=({open:t,onOpenChange:o,onComplete:j})=>{const[C,N]=l.useState("upload"),[d,b]=l.useState([]),[g,$]=l.useState([]),[W,B]=l.useState(!1),[U,y]=l.useState([]),[z,ae]=l.useState(!1),pe=l.useCallback(async()=>{const{data:a}=await u.from("wequal_sessions").select("id, title, host_name, host_company, session_date, session_time, recording_url, transcript_status").order("host_name"),{data:v}=await u.from("session_transcript_chunks").select("session_id").not("session_id","is",null),m=new Map;if(v)for(const _ of v)m.set(_.session_id,(m.get(_.session_id)||0)+1);const E=(a||[]).map(_=>({..._,speaker_name:null,speaker_company:null,chunk_count:m.get(_.id)||0}
6)),{data:r}=await u.from("session_speakers").select("session_id, speaker_name, speaker_company").order("display_order",{ascending:!0}),h=new Map;if(r)for(const _ of r)h.has(_.session_id)||h.set(_.session_id,{speaker_name:_.speaker_name,speaker_company:_.speaker_company});for(const _ of E){const V=h.get(_.id);_.speaker_name=(V==null?void 0:V.speaker_name)||null,_.speaker_company=(V==null?void 0:V.speaker_company)||null}return E},[]),ne=l.useCallback(async a=>{var _,V;const v=a.filter(p=>/\.vtts?$/i.test(p.name));if(v.length===0){D.error("No .vtt files selected");return}const m=await pe();$(m);const E=new Map;m.forEach(p=>{const c=je(p.title);E.has(c)||E.set(c,[]),E.get(c).push(p)});const r=new Map;m.forEach(p=>{p.recording_url&&(r.has(p.recording_url)||r.set(p.recording_url,[]),r.get(p.recording_url).push(p))});const h=[];for(const p of v){const c=await p.text(),R=st(p.name);if(R){const F=m.map(S=>({session:S,titleScore:es(R.title,S.title),speakerMatch:tt(R.speaker,S)})),x=F.filter(S=>S.titleScore>=.4);if(x.length===0){const S=F.filter(re=>re.speakerMatch);S.length===1?h.push({fileName:p.name,vttText:c,matchedSession:S[0].session,candidates:S.map(re=>re.session),status:"auto",confidence:`Speaker match: "${R.speaker}" (title low)`}):h.push({fileName:p.name,vttText:c,matchedSession:null,candidates:m,status:"unmatched",confidence:`No title match for "${R.title}"`});continue}const T=x.filter(S=>S.speakerMatch);if(T.length===1){h.push({fileName:p.name,vttText:c,matchedSession:T[0].session,candidates:x.map(S=>S.session),status:"auto",confidence:`Title (${Math.round(T[0].titleScore*100)}%) + speaker "${R.speaker}"`});continue}if(T.length>1){T.sort((S,re)=>re.titleScore-S.titleScore),T[0].titleScore>T[1].titleScore?h.push({fileName:p.name,vttText:c,matchedSession:T[0].session,candidates:T.map(S=>S.session),status:"auto",confidence:`Best title (${Math.round(T[0].titleScore*100)}%) + speaker "${R.speaker}"`}):h.push({fileName:p.name,vttText:c,matchedSession:null,candidates:T.map(S=>S.session),status:"manual",confidence:`${T.length} sessions match title + speaker — please select`});continue}x.sort((S,re)=>re.titleScore-S.titleScore),x.length===1||x[0].titleScore>=.7?h.push({fileName:p.name,vttText:c,matchedSession:x[0].session,candidates:x.map(S=>S.session),status:"auto",confidence:`Title match (${Math.round(x[0].titleScore*100)}%) — speaker "${R.speaker}" not found in session data`}):h.push({fileName:p.name,vttText:c,matchedSession:null,candidates:x.map(S=>S.session),status:"manual",confidence:`${x.length} title candidates — speaker "${R.speaker}" not matched`});continue}const ue=je(p.name);let Q=0,ce="";for(const[F]of E){const x=es(ue,F);x>Q&&(Q=x,ce=F)}let A=null,K=0;for(const F of m){const x=Be(p.name,F);x>K&&(K=x,A=F)}if(Q<.5&&K===0){h.push({fileName:p.name,vttText:c,matchedSession:null,candidates:m,status:"unmatched",confidence:"No title or speaker match found"});continue}if(K>=3&&(Q<.5||Q<.7)){const F=E.get(je(A.title))||[],x=A.recording_url?r.get(A.recording_url)||[]:[],T=new Map;[...F,...x].forEach(P=>T.set(P.id,P));const S=[...T.values()];if(S.length>1&&ss(S)){h.push({fileName:p.name,vttText:c,matchedSession:null,candidates:S,status:"duplicate-review",confidence:`${S.length} duplicate sessions found — please select the correct one`,duplicateWarning:"Multiple sessions share the same title or recording URL. Please verify the correct session by checking date and speaker."});continue}const re=A.speaker_name||A.host_name;h.push({fileName:p.name,vttText:c,matchedSession:A,candidates:m.filter(P=>Be(p.name,P)>0),status:"auto",confidence:`Speaker match: "${re}" in filename`});continue}const M=E.get(ce)||[];if(M.length===1){const F=M[0].recording_url?r.get(M[0].recording_url)||[]:[];F.length>1?h.push({fileName:p.name,vttText:c,matchedSession:null,candidates:F,status:"duplicate-review",confidence:`${F.length} sessions share the same recording URL — please select the correct one`,duplicateWarning:"Multiple sessions share the same recording URL. Please verify the correct session."}):h.push({fileName:p.name,vttText:c,matchedSession:M[0],candidates:M,status:"auto",confidence:`Title match (${Math.round(Q*100)}%)`})}
6else if(ss(M))h.push({fileName:p.name,vttText:c,matchedSession:null,candidates:M,status:"duplicate-review",confidence:`${M.length} duplicate sessions found — please select the correct one`,duplicateWarning:`Multiple sessions share the same title${M.some(F=>F.recording_url)?" and/or recording URL":""}. Please verify the correct session by checking date and speaker.`});else{const F=M.map(x=>({session:x,score:Be(p.name,x)}));if(F.sort((x,T)=>T.score-x.score),F[0].score>=3&&F[0].score>(((_=F[1])==null?void 0:_.score)||0)){const x=F[0].session.speaker_name||F[0].session.host_name;h.push({fileName:p.name,vttText:c,matchedSession:F[0].session,candidates:M,status:"auto",confidence:`Title + speaker match: "${x}" in filename`})}else{const x=M.map(T=>({session:T,score:at(c,T)}));if(x.sort((T,S)=>S.score-T.score),x[0].score>0&&x[0].score>(((V=x[1])==null?void 0:V.score)||0)){const T=x[0].session.speaker_name||x[0].session.host_name;h.push({fileName:p.name,vttText:c,matchedSession:x[0].session,candidates:M,status:"content",confidence:`Content match: "${T}" mentioned (score ${x[0].score})`})}else h.push({fileName:p.name,vttText:c,matchedSession:null,candidates:M,status:"manual",confidence:`${M.length} sessions share this title - please select`})}}}b(h),N("review")},[pe]),_e=l.useCallback(a=>{a.target.files&&ne(Array.from(a.target.files))},[ne]),xe=l.useCallback(a=>{a.preventDefault(),ae(!1),a.dataTransfer.files&&ne(Array.from(a.dataTransfer.files))},[ne]),fe=l.useCallback((a,v)=>{b(m=>m.map((E,r)=>{if(r!==a)return E;const h=E.candidates.find(V=>V.id===v)||null,_=h?h.speaker_name||h.host_name:null;return{...E,matchedSession:h,status:h?"manual":"unmatched",confidence:h?`Manually assigned to ${_}`:E.confidence}}))},[]),ie=l.useMemo(()=>d.filter(a=>a.matchedSession).length,[d]),ge=l.useCallback(async(a,v,m)=>{m("Validating ingest...");const{data:E}=await u.from("wequal_sessions").select("transcript_status").eq("id",a).single();if(!E||E.transcript_status!=="complete")throw new Error("Ingest did not complete — transcript_status is not 'complete'");const{data:r}=await u.from("session_transcript_chunks").select("id").eq("session_id",a).limit(1);if(!r||r.length===0)throw new Error("Ingest produced no chunks — aborting pipeline");m("Classifying...");const{error:h}=await u.functions.invoke("classify-chunks",{body:{session_id:a}});if(h)throw new Error(`Classify failed: ${h.message}`);m("Stitching clips...");const{error:_}=await u.functions.invoke("stitch-clips",{body:{session_id:a}});if(_)throw new Error(`Stitch failed: ${_.message}`);m("Approving..."),await u.from("session_transcript_chunks").update({approval_status:"approved"}).eq("session_id",a).eq("is_searchable",!0),await u.from("session_clip_spans").update({approval_status:"approved"}).eq("session_id",a),await u.from("wequal_sessions").update({chunk_approval_status:"approved",clip_approval_status:"approved",clip_test_status:"pass"}).eq("id",a),m("Enabling engine...");const{error:V}=await u.from("wequal_sessions").update({engine_enabled:!0}).eq("id",a);if(V)throw new Error(`Enable failed: ${V.message}`)},[]),le=l.useCallback(async()=>{const a=d.filter(m=>m.matchedSession);if(a.length===0)return;B(!0),N("processing");const v=[];for(const m of a){const E=v.length;v.push({fileName:m.fileName,success:!1,stage:"Ingesting VTT..."}),y([...v]);try{const{error:r}=await u.functions.invoke("ingest-vtt",{body:{session_id:m.matchedSession.id,vtt_text:m.vttText,vtt_filename:m.fileName}});if(r)throw r;await ge(m.matchedSession.id,m.fileName,h=>{v[E]={...v[E],stage:h},y([...v])}),v[E]={fileName:m.fileName,success:!0,stage:"Done"}}catch(r){const h=r instanceof Error?r.message:String(r),_=v[E].stage||"Unknown";v[E]={fileName:m.fileName,success:!1,error:h,stage:`Failed at: ${_}`}}y([...v])}y(v),N("done"),B(!1)},[d,ge]),be=l.useCallback(()=>{N("upload"),b([]),y([]),o(!1),U.some(a=>a.success)&&j()},[o,j,U]);return e.jsx(Le,{open:t,onOpenChange:a=>!a&&be(),children:e.jsxs(Pe,{className:"max-w-4xl w-[95vw] max-h-[85vh] flex flex-col p-0 gap-0 bg-white border-[#CFCFCF] [&>button]:hidden",children:[e.jsxs("div",{className:"px-6 pt-6 pb-4 border-b border-[#CFCFCF]/50",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#111111]",children:"Bulk VTT Re-ingest"}),e.jsx("p",{className:"text-sm text-[#111111]/50 mt-1",children:"Upload VTT files to re-process sessions with the current chunking algorithm"})]}),C==="upload"&&e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-12 text-center transition-colors ${z?"border-[#F15A24] bg-[#F15A24]/5":"border-[#CFCFCF] hover:border-[#111111]/30"}`,onDragOver:a=>{a.preventDefault(),ae(!0)},onDragLeave:()=>ae(!1),onDrop:xe,children:[e.jsx(ws,{className:"w-8 h-8 text-[#111111]/30 mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-[#111111]/60 mb-4",children:"Drag and drop VTT files here, or click to browse"}),e.jsxs("label",{children:[e.jsx("input",{type:"file",multiple:!0,accept:".vtt,.vtts",onChange:_e,className:"hidden"}),e.jsx(L,{variant:"outline",className:"border-[#CFCFCF]",asChild:!0,children:e.jsx("span",{children:"Select VTT files"})})]})]})}),C==="review"&&e.jsxs("div",{className:"flex flex-col min-h-0 flex-1",children:[e.jsx("div",{className:"px-6 pt-4 pb-2",children:e.jsxs("p",{className:"text-sm text-[#111111]/60",children:[d.length," file",d.length!==1?"s":""," uploaded,"," ",ie," matched"]})}),e.jsx("div",{className:"px-6 space-y-2 overflow-y-auto flex-1 min-h-0 pb-4",children:d.map((a,v)=>{var m,E;return e.jsxs("div",{className:`border rounded-lg p-3 space-y-2 ${a.status==="duplicate-review"?"border-red-300 bg-red-50/40 border-l-4 border-l-red-400":a.matchedSession&&(a.matchedSession.chunk_count>0||a.matchedSession.transcript_status==="complete")?"border-amber-300 bg-amber-50/30 border-l-4 border-l-amber-400":a.matchedSession?"border-emerald-200 bg-emerald-50/30":a.status==="manual"?"border-amber-200 bg-amber-50/30":"border-red-200 bg-red-50/30"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-[#111111] truncate",children:a.fileName}),e.jsx("p",{className:"text-xs text-[#111111]/50 mt-0.5",children:a.confidence})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[a.status==="duplicate-review"?e.jsxs(oe,{variant:"outline",className:"text-xs bg-red-50 text-red-700 border-red-300",children:[e.jsx(Ns,{className:"w-3 h-3 mr-1"}),"Duplicates found"]}
6):a.status==="auto"||a.status==="content"?e.jsx(oe,{variant:"outline",className:"text-xs bg-emerald-50 text-emerald-700 border-emerald-200",children:a.status==="auto"?"Auto-matched":"Content-matched"}):a.status==="unmatched"?e.jsx(oe,{variant:"outline",className:"text-xs bg-red-50 text-red-700 border-red-200",children:"Unmatched"}):null,e.jsx("button",{onClick:()=>b(r=>r.filter((h,_)=>_!==v)),className:"p-1 rounded hover:bg-red-100 text-[#111111]/40 hover:text-red-600 transition-colors",title:"Remove this file",children:e.jsx(Ae,{className:"w-4 h-4"})})]})]}),a.status==="duplicate-review"&&a.duplicateWarning&&e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded bg-red-50 border border-red-200 text-red-800",children:[e.jsx(Re,{className:"w-4 h-4 shrink-0 mt-0.5"}),e.jsx("span",{className:"text-xs",children:a.duplicateWarning})]}),a.matchedSession&&(a.status==="auto"||a.status==="content")&&e.jsx("div",{className:"space-y-1",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[#111111]/70",children:[e.jsx(De,{className:"w-3.5 h-3.5 text-emerald-500 shrink-0"}),e.jsx("span",{children:Ze(a.matchedSession)}),a.matchedSession.recording_url&&e.jsx("a",{href:a.matchedSession.recording_url,target:"_blank",rel:"noopener noreferrer",className:"text-[#F15A24] hover:text-[#F15A24]/80 shrink-0",title:"Open YouTube video",children:e.jsx(qe,{className:"w-3 h-3"})})]})}),a.matchedSession&&(a.matchedSession.chunk_count>0||a.matchedSession.transcript_status==="complete")&&e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded bg-amber-50 border border-amber-200 text-amber-800",children:[e.jsx(Re,{className:"w-3.5 h-3.5 shrink-0"}),e.jsxs("span",{className:"text-xs flex-1",children:["This session already has ",a.matchedSession.chunk_count," chunks loaded. Re-ingesting will replace them."]}),e.jsx(L,{variant:"outline",size:"sm",className:"h-6 text-xs border-amber-300 text-amber-700 hover:bg-amber-100 px-2",onClick:()=>b(r=>r.filter((h,_)=>_!==v)),children:"Skip"})]}),(a.status==="duplicate-review"||a.status==="manual"||a.status==="unmatched")&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ce,{value:((m=a.matchedSession)==null?void 0:m.id)||"",onValueChange:r=>fe(v,r),children:[e.jsx(ye,{className:"h-8 text-xs border-[#CFCFCF]",children:e.jsx(Se,{placeholder:"Select session..."})}),e.jsx(Fe,{children:(a.status==="unmatched"?g:a.candidates).map(r=>{const h=ts(r),_=de(new Date(r.session_date),"dd MMM yy");return e.jsxs(I,{value:r.id,className:"text-xs",children:[e.jsx("span",{className:"font-medium",children:_})," — ",r.speaker_name||r.host_name||"Unknown"," — ",r.title,r.chunk_count>0?` ⚠ ${r.chunk_count} chunks`:"",h.stage>0?` [${h.label}]`:""]},r.id)})})]}),a.status==="duplicate-review"&&e.jsx("div",{className:"space-y-1 pl-1",children:a.candidates.map(r=>{const h=de(new Date(r.session_date),"dd MMM yy"),_=ts(r);return e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-[#111111]/60",children:[e.jsx("span",{className:"font-mono text-[9px] text-[#111111]/30",children:r.id.slice(0,8)}),e.jsx("span",{className:"font-medium",children:h}),e.jsx("span",{children:r.speaker_name||r.host_name||"—"}),r.chunk_count>0&&e.jsxs(oe,{variant:"outline",className:"text-[9px] h-4 bg-amber-50 text-amber-700 border-amber-200 px-1",children:[r.chunk_count," chunks"]}),_.stage>0&&e.jsx(oe,{variant:"outline",className:"text-[9px] h-4 px-1",children:_.label}),r.recording_url&&e.jsx("a",{href:r.recording_url,target:"_blank",rel:"noopener noreferrer",className:"text-[#F15A24] hover:text-[#F15A24]/80",children:e.jsx(qe,{className:"w-2.5 h-2.5"})})]},r.id)})}),(a.status==="manual"||a.status==="unmatched")&&e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:(a.status==="unmatched"?g:a.candidates).filter(r=>r.recording_url).map(r=>e.jsxs("a",{href:r.recording_url,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-[#F15A24] hover:text-[#F15A24]/80 flex items-center gap-0.5",children:[e.jsx(qe,{className:"w-2.5 h-2.5"}),r.speaker_name||r.host_name||"Unknown"]},r.id))})]}),(a.status==="auto"||a.status==="content")&&a.candidates.length>1&&e.jsxs("details",{className:"text-xs",children:[e.jsx("summary",{className:"text-[#111111]/40 cursor-pointer hover:text-[#111111]/60",children:"Change assignment"}),e.jsxs(Ce,{value:((E=a.matchedSession)==null?void 0:E.id)||"",onValueChange:r=>fe(v,r),children:[e.jsx(ye,{className:"h-8 text-xs border-[#CFCFCF] mt-1",children:e.jsx(Se,{})}),e.jsx(Fe,{children:a.candidates.map(r=>
6e.jsxs(I,{value:r.id,className:"text-xs",children:[Ze(r),r.recording_url?" [YT]":""]},r.id))})]})]})]},v)})}),e.jsxs("div",{className:"px-6 py-4 border-t border-[#CFCFCF]/50 flex items-center justify-between shrink-0",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:()=>{N("upload"),b([])},className:"border-[#CFCFCF]",children:"Back"}),e.jsxs(L,{size:"sm",onClick:le,disabled:ie===0,className:"bg-[#111111] text-white hover:bg-[#111111]/90",children:[e.jsx(as,{className:"w-3.5 h-3.5 mr-1.5"}),"Re-ingest ",ie," session",ie!==1?"s":""]})]})]}),C==="processing"&&e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(H,{className:"w-5 h-5 animate-spin text-[#111111]/50"}),e.jsxs("p",{className:"text-sm text-[#111111]/70",children:["Processing ",U.filter(a=>{var v;return a.stage==="Done"||((v=a.stage)==null?void 0:v.startsWith("Failed"))}).length," of ",d.filter(a=>a.matchedSession).length," sessions..."]})]}),e.jsx("div",{className:"space-y-1 max-h-[50vh] overflow-y-auto",children:U.map((a,v)=>{var m;return e.jsxs("div",{className:"flex items-center gap-2 text-xs py-1",children:[a.stage==="Done"?e.jsx(De,{className:"w-3.5 h-3.5 text-emerald-500 shrink-0"}):(m=a.stage)!=null&&m.startsWith("Failed")?e.jsx(Ae,{className:"w-3.5 h-3.5 text-red-500 shrink-0"}):e.jsx(H,{className:"w-3.5 h-3.5 animate-spin text-amber-500 shrink-0"}),e.jsx("span",{className:"text-[#111111]/70 truncate",children:a.fileName}),e.jsx("span",{className:"text-[#111111]/40 shrink-0",children:a.stage}),a.error&&e.jsxs("span",{className:"text-red-500 truncate ml-1",children:["- ",a.error]})]},v)})})]}),C==="done"&&e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[U.every(a=>a.success)?e.jsx(De,{className:"w-6 h-6 text-emerald-500"}):e.jsx(Re,{className:"w-6 h-6 text-amber-500"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-[#111111]",children:[U.filter(a=>a.success).length," of ",U.length," sessions re-ingested"]}),U.some(a=>!a.success)&&e.jsxs("p",{className:"text-xs text-red-500 mt-0.5",children:[U.filter(a=>!a.success).length," failed"]})]})]}),e.jsx("div",{className:"space-y-1 max-h-[40vh] overflow-y-auto",children:U.map((a,v)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs py-1",children:[a.success?e.jsx(De,{className:"w-3.5 h-3.5 text-emerald-500 shrink-0 mt-0.5"}):e.jsx(Ae,{className:"w-3.5 h-3.5 text-red-500 shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-[#111111]/70",children:a.fileName}),a.stage&&a.stage!=="Done"&&e.jsx("span",{className:"text-[#111111]/40 ml-2",children:a.stage}),a.error&&e.jsx("p",{className:"text-red-500 mt-0.5 break-words",children:a.error})]})]},v))}),e.jsx("div",{className:"flex justify-end",children:e.jsx(L,{onClick:be,className:"bg-[#111111] text-white hover:bg-[#111111]/90",children:"Done"})})]})]})})},Ve={not_started:"bg-[#F4F4F4] text-[#111111]/50",in_progress:"bg-amber-50 text-amber-700 border-amber-200",complete:"bg-emerald-50 text-emerald-700 border-emerald-200",error:"bg-red-50 text-red-700 border-red-200",loaded_error:"bg-red-50 text-red-700 border-red-200",none:"bg-[#F4F4F4] text-[#111111]/50",suggested:"bg-blue-50 text-blue-700 border-blue-200",approved:"bg-emerald-50 text-emerald-700 border-emerald-200",pending:"bg-amber-50 text-amber-700 border-amber-200",partial:"bg-blue-50 text-blue-700 border-blue-200",processing:"bg-amber-50 text-amber-700 border-amber-200",transcribed:"bg-blue-50 text-blue-700 border-blue-200",classified:"bg-blue-50 text-blue-700 border-blue-200"},ze={not_started:"Not started",in_progress:"In progress",complete:"Complete",error:"Error",loaded_error:"Loaded-Error",none:"None",suggested:"Suggested",approved:"Approved",pending:"Pending",partial:"Partial",processing:"Processing...",transcribed:"Transcribed",classified:"Classified"};function rt(t,o){return o?"processing":t.transcript_status==="error"?"error":t.transcript_status==="in_progress"?"in_progress":t.transcript_status!=="complete"?"not_started":(t.searchable_chunk_count??0)<1?"transcribed":(t.clip_count??0)<1?"classified":"complete"}const it=({session:t,open:o,onOpenChange:j,onRefresh:C,onTitleClick:N})=>{var p;const d=l.useRef(null),[b,g]=l.useState(!1),$=ns(),W=ls(),[B,U]=l.useState([]),[y,z]=l.useState(!1),[ae,pe]=l.useState(!1),[ne,_e]=l.useState(""),[xe,fe]=l.useState(""),[ie,ge]=l.useState("");l.useEffect(()=>{t!=null&&t.id&&o&&le(t.id)},[t==null?void 0:t.id,o]);const le=async c=>{z(!0);try{const{data:R,error:ue}=await u.from("session_speakers").select("*").eq("session_id",c).order("display_order");if(ue)throw ue;U(R||[])}catch{}finally{z(!1)}},be=async()=>
6{if(!(!t||!ne.trim())){pe(!0);try{const{error:c}=await u.from("session_speakers").insert({session_id:t.id,speaker_name:ne.trim(),speaker_title:xe.trim()||null,speaker_company:ie.trim()||null,display_order:B.length+1});if(c)throw c;_e(""),fe(""),ge(""),await le(t.id),D.success("Speaker added")}catch(c){D.error(c.message)}finally{pe(!1)}}},a=async c=>{if(!t)return;const{error:R}=await u.from("session_speakers").delete().eq("id",c);R?D.error(R.message):await le(t.id)};if(!t)return null;const v=t.content_start_sec!=null?`${Math.floor(t.content_start_sec/60)}:${String(t.content_start_sec%60).padStart(2,"0")}`:"—",m=rt(t,b),E=async()=>{if(t.transcript_status!=="complete"||!["approved","partial"].includes(t.chunk_approval_status)||(t.searchable_chunk_count??0)<1)return;const{error:c}=await u.from("wequal_sessions").update({engine_enabled:!t.engine_enabled}).eq("id",t.id);c?D.error(c.message):C()},r=async()=>{confirm("Clear transcript and all chunks for this session?")&&(await u.from("session_clip_spans").delete().eq("session_id",t.id),await u.from("session_transcript_chunks").delete().eq("session_id",t.id),await u.from("v2_chunks").delete().eq("session_id",t.id),await u.from("v2_clips").delete().eq("session_id",t.id),await u.from("wequal_sessions").update({transcript_status:"not_started",transcript_updated_at:null,transcript_word_count:null,chunk_count:null,tags:null,tags_status:"none",engine_enabled:!1,last_error:null,content_start_sec:null,intro_detection_confidence:null,intro_detection_method:null,searchable_chunk_count:0,clip_count:0,low_confidence_count:0,chunk_approval_status:"pending",clip_approval_status:"pending",clip_test_status:null}).eq("id",t.id),C(),j(!1))},h=async c=>{var Q;const R=(Q=c.target.files)==null?void 0:Q[0];if(!R)return;if(d.current&&(d.current.value=""),!R.name.match(/\.vtts?$/i)){D.error("Please select a .vtt or .vtts file");return}if(!((t.transcript_status==="complete"||t.transcript_status==="error")&&!confirm("This will replace the existing transcript and re-process. Continue?"))){D.info("Ingesting VTT, classifying chunks, stitching clips — this may take up to 5 minutes.",{duration:5e3,closeButton:!0}),g(!0);try{const ce=await R.text(),{data:A,error:K}=await u.functions.invoke("ingest-vtt",{body:{session_id:t.id,vtt_text:ce}});if(K)throw K;if(A!=null&&A.error)throw new Error(`Ingest failed: ${A.error}`);const{data:M,error:F}=await u.functions.invoke("classify-chunks",{body:{session_id:t.id}});if(F)throw F;if(M!=null&&M.error)throw new Error(`Classification failed: ${M.error}`);const{data:x,error:T}=await u.functions.invoke("stitch-clips",{body:{session_id:t.id}});if(T)throw T;if(x!=null&&x.error)throw new Error(`Stitching failed: ${x.error}`);D.success(`Pipeline complete: ${A.chunks} chunks, ${M.classified} classified, ${x.clips} clips`),W("Pipeline complete",{sessionId:t.id,sessionTitle:t.title,detail:`${A.chunks} chunks, ${M.classified} classified, ${x.clips} clips`})}catch(ce){D.error(`Pipeline error: ${ce.message||"Unknown error"}`),W("Pipeline error",{sessionId:t.id,sessionTitle:t.title,detail:ce.message})}finally{g(!1),C()}}},_=t.transcript_status!=="complete"||!["approved","partial"].includes(t.chunk_approval_status)||(t.searchable_chunk_count??0)<1,V=b?"Processing...":t.transcript_status==="complete"?"Re-process VTT":"Upload & Process VTT";return e.jsx(e.Fragment,{children:e.jsx(Le,{open:o,onOpenChange:j,children:e.jsx(Pe,{className:"max-w-2xl w-full h-[calc(100vh-40px)] p-0 overflow-hidden rounded-lg border border-[#CFCFCF] bg-white",children:e.jsxs("div",{className:"overflow-y-auto h-full p-6 sm:p-8",children:[e.jsx("div",{className:"flex justify-end mb-2",children:e.jsx("button",{onClick:()=>j(!1),className:"w-9 h-9 rounded-full bg-white border border-[#CFCFCF] flex items-center justify-center shadow-sm hover:bg-[#F4F4F4] transition-colors","aria-label":"Close",children:e.jsx(Ye,{className:"w-4 h-4 text-[#111111]"})})}),e.jsx(Ue,{className:"pb-4",children:e.jsx(Oe,{className:"text-[#111111] text-xl font-bold pr-6 leading-tight",children:t.title})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wider text-[#111111]/40",children:"Session"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Host"}),e.jsx("p",{className:"text-[#111111] font-medium",children:t.host_name||"—"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Job Title"}),e.jsx("p",{className:"text-[#111111] font-medium",children:t.host_role||"—"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Company"}),e.jsx("p",{className:"text-[#111111] font-medium",children:t.host_company||"—"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Date"}),e.jsx("p",{className:"text-[#111111]",children:de(new Date(t.session_date),"dd MMM yyyy")})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Type"}),e.jsx("p",{className:"text-[#111111] capitalize",children:t.session_type.replace("_"," ")})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Duration"}),e.jsx("p",{className:"text-[#111111]",children:t.duration_minutes?`${t.duration_minutes} min`:"—"})]})]}),t.recording_url&&e.jsxs("button",{onClick:()=>{N?(j(!1),N(t)):window.open(t.recording_url,"_blank")},className:"inline-flex items-center gap-1.5 text-sm text-[#F15A24] hover:underline cursor-pointer",children:[e.jsx(qe,{className:"w-3.5 h-3.5"})," Open on YouTube"]})]}),e.jsx($e,{className:"bg-[#CFCFCF]"}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wider text-[#111111]/40",children:"Pipeline Status"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{className:"col-span-2",children:[e.jsx("p",{className:"text-[#111111]/50",children:"Pipeline"}),e.jsxs(oe,{variant:"outline",className:`mt-1 text-xs ${Ve[m]||""}`,children:[b&&e.jsx(H,{className:"w-3 h-3 animate-spin mr-1"}),ze[m]||m]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Transcript"}),e.jsx(oe,{variant:"outline",className:`mt-1 text-xs ${Ve[t.transcript_status]||""}`,children:ze[t.transcript_status]||t.transcript_status})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Total Chunks"}),e.jsx("p",{className:"text-[#111111]",children:t.chunk_count??"—"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Content Start"}),e.jsxs("p",{className:"text-[#111111] font-mono",children:[v,t.intro_detection_method&&e.jsxs("span",{className:"ml-1 text-xs text-[#111111]/40",children:["(",t.intro_detection_method,")"]})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Searchable / Clips"}),e.jsxs("p",{className:"text-[#111111]",children:[t.searchable_chunk_count??0," chunks / ",t.clip_count??0," clips"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Chunk Approval"}),e.jsxs("button",{type:"button",onClick:()=>{j(!1),$("?tab=chunk-analytics")},className:"group text-left",children:[e.jsx(oe,{variant:"outline",className:`mt-1 text-xs cursor-pointer transition-all group-hover:ring-2 group-hover:ring-[#F15A24]/20 ${Ve[t.chunk_approval_status]||""}`,children:ze[t.chunk_approval_status]||t.chunk_approval_status}),["pending","partial"].includes(t.chunk_approval_status)&&e.jsx("p",{className:"text-[10px] text-[#111111]/40 mt-1",children:"Click to review chunks"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Low Confidence"}),e.jsx("p",{className:`text-[#111111] ${(t.low_confidence_count??0)>0?"text-amber-600 font-medium":""}`,children:t.low_confidence_count??0})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Words"}),e.jsx("p",{className:"text-[#111111]",children:((p=t.transcript_word_count)==null?void 0:p.toLocaleStr
6ing())??"—"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111]/50",children:"Updated"}),e.jsx("p",{className:"text-[#111111]",children:t.transcript_updated_at?de(new Date(t.transcript_updated_at),"dd MMM yyyy HH:mm"):"—"})]})]}),t.last_error&&e.jsxs("div",{className:"bg-red-50 border border-red-200 p-3 text-sm text-red-700 rounded",children:[e.jsx("p",{className:"font-medium mb-1",children:"Last error"}),e.jsx("p",{className:"text-xs",children:t.last_error})]})]}),e.jsx($e,{className:"bg-[#CFCFCF]"}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wider text-[#111111]/40",children:"Speakers"}),y?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(H,{className:"w-3 h-3 animate-spin"})," Loading..."]}):e.jsxs(e.Fragment,{children:[B.length>0&&e.jsx("div",{className:"space-y-2",children:B.map(c=>e.jsxs("div",{className:"flex items-center justify-between bg-[#F4F4F4] p-2 rounded text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[#111111] font-medium",children:c.speaker_name}),e.jsx("p",{className:"text-[#111111]/50 text-xs",children:[c.speaker_title,c.speaker_company].filter(Boolean).join(" · ")||"No details"})]}),e.jsx("button",{onClick:()=>a(c.id),className:"text-[#111111]/30 hover:text-red-500 transition-colors p-1",children:e.jsx(Ye,{className:"w-3.5 h-3.5"})})]},c.id))}),e.jsxs("div",{className:"space-y-2 border border-dashed border-[#CFCFCF] rounded p-3",children:[e.jsx(Te,{placeholder:"Speaker name",value:ne,onChange:c=>_e(c.target.value),className:"h-8 text-sm"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(Te,{placeholder:"Role (optional)",value:xe,onChange:c=>fe(c.target.value),className:"h-8 text-sm"}),e.jsx(Te,{placeholder:"Company (optional)",value:ie,onChange:c=>ge(c.target.value),className:"h-8 text-sm"})]}),e.jsxs(L,{variant:"outline",size:"sm",onClick:be,disabled:!ne.trim()||ae,className:"w-full gap-1 text-xs",children:[ae?e.jsx(H,{className:"w-3 h-3 animate-spin"}):e.jsx(vs,{className:"w-3 h-3"}),"Add Speaker"]})]})]})]}),e.jsx($e,{className:"bg-[#CFCFCF]"}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wider text-[#111111]/40",children:"Engine"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-[#111111] font-medium",children:"Include in Decision Support"}),e.jsx("p",{className:"text-xs text-[#111111]/50",children:_?"Requires complete transcript and approved/partial chunk approval":"Toggle to include or exclude from Decision Support"})]}),e.jsx(rs,{checked:t.engine_enabled,disabled:_,onCheckedChange:E,className:"data-[state=checked]:bg-emerald-500"})]})]}),e.jsx($e,{className:"bg-[#CFCFCF]"}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-medium uppercase tracking-wider text-[#111111]/40",children:"Actions"}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("input",{ref:d,type:"file",accept:".vtt,.vtts",className:"hidden",onChange:h}),e.jsxs(L,{variant:"outline",size:"sm",onClick:()=>{var c;return(c=d.current)==null?void 0:c.click()},disabled:b,className:"w-full border-[#CFCFCF] text-[#111111]/70 justify-start gap-2",children:[b?e.jsx(H,{className:"w-4 h-4 animate-spin"}):e.jsx(ks,{className:"w-4 h-4"}),V]}),e.jsxs(L,{variant:"outline",size:"sm",onClick:r,disabled:t.transcript_status==="not_started",className:"w-full border-red-200 text-red-600 hover:bg-red-50 justify-start gap-2",children:[e.jsx(We,{className:"w-4 h-4"})," Clear Transcript"]})]})]})]})]})})})})},lt=()=>{const[t,o]=l.useState(!1),[j,C]=l.useState(""),[N,d]=l.useState(""),b=Cs(),{data:g,isLoading:$}=He({queryKey:["transcript-term-fixes"],queryFn:async()=>{const{data:y,error:z}=await u.from("transcript_term_fixes").select("*").order("find_pattern",{ascending:!0});if(z)throw z;return y||[]},enabled:t}),W=Ge({mutationFn:async({find_pattern:y,replace_with:z})=>{const{error:ae}=await u.from("transcript_term_fixes").insert({find_pattern:y,replace_with:z});if(ae)throw ae},onSuccess:()=>{b.invalidateQueries({queryKey:["transcript-term-fixes"]}),C(""),d(""),D.success("Word fix added")},onError:y=>D.error(y.message)}),B=Ge({mutationFn:async y=>{const{error:z}=await u.from("transcript_term_fixes").delete().eq("id",y);if(z)throw z},onSuccess:()=>{b.invalidateQueries({queryKey:["transcript-term-fixes"]}),D.success("Word fix removed")},onError:y=>D.error(y.message)}),U=()=>{const y=j.trim(),z=N.trim();if(!y||!z){D.error("Both fields are required");return}W.mutate({find_pattern:y,replace_with:z})};return e.jsxs(Le,{open:t,onOpenChange:o,children:[e.jsx(is,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"border-[#CFCFCF] text-[#111111]/70 gap-2",children:[e.jsx(et,{className:"w-4 h-4"}),"Word Fix"]})}),e.jsxs(Pe,{className:"sm:max-w-md bg-white border-[#CFCFCF]",children:[e.jsxs(Ue,{children:[e.jsx(Oe,{className:"text-[#111111] text-lg",children:"Word Fixes"}),e.jsx("p",{className:"text-sm text-[#111111]/50",children:"Terms automatically corrected during transcription"})]}),e.jsxs("div",{className:"flex gap-2 items-end",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-xs text-[#111111]/50",children:"Find"}),e.jsx(Te,{placeholder:"e.g. we qual",value:j,onChange:y=>C(y.target.value),className:"border-[#CFCFCF] text-sm h-9"})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("label",{className:"text-xs text-[#111111]/50",children:"Replace with"}),e.jsx(Te,{placeholder:"e.g. WeQual",value:N,onChange:y=>
6d(y.target.value),className:"border-[#CFCFCF] text-sm h-9",onKeyDown:y=>y.key==="Enter"&&U()})]}),e.jsx(L,{size:"sm",onClick:U,disabled:W.isPending,className:"bg-[#111111] text-white hover:bg-[#111111]/90 h-9 px-3",children:W.isPending?e.jsx(H,{className:"w-4 h-4 animate-spin"}):e.jsx(Hs,{className:"w-4 h-4"})})]}),e.jsx($e,{className:"bg-[#CFCFCF]"}),e.jsx("div",{className:"max-h-[300px] overflow-y-auto space-y-1",children:$?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(H,{className:"w-5 h-5 animate-spin text-[#111111]/40"})}):g&&g.length>0?g.map(y=>e.jsxs("div",{className:"flex items-center justify-between py-2 px-2 hover:bg-[#F4F4F4] rounded group",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm min-w-0",children:[e.jsx("span",{className:"text-[#111111]/60 truncate",children:y.find_pattern}),e.jsx("span",{className:"text-[#111111]/30",children:"→"}),e.jsx("span",{className:"text-[#111111] font-medium truncate",children:y.replace_with})]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>B.mutate(y.id),disabled:B.isPending,className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 text-red-500 hover:text-red-600 hover:bg-red-50",children:e.jsx(We,{className:"w-3.5 h-3.5"})})]},y.id)):e.jsx("p",{className:"text-sm text-[#111111]/40 text-center py-6",children:"No word fixes configured"})})]})]})},ct=()=>{const[t,o]=l.useState(!1),{data:j,isLoading:C}=He({queryKey:["ingestion-activity-log"],queryFn:async()=>{const{data:d,error:b}=await u.from("ingestion_activity_log").select("id, action, detail, session_id, session_title, created_at").order("created_at",{ascending:!1}).limit(200);if(b)throw b;return d||[]},enabled:t,refetchInterval:t?1e4:!1}),N=(j||[]).reduce((d,b)=>{const g=de(new Date(b.created_at),"dd MMM yyyy");return d[g]||(d[g]=[]),d[g].push(b),d},{});return e.jsxs(Le,{open:t,onOpenChange:o,children:[e.jsx(is,{asChild:!0,children:e.jsxs(L,{variant:"outline",size:"sm",className:"border-[#CFCFCF] text-[#111111]/70 gap-2",children:[e.jsx(ys,{className:"w-4 h-4"}),"Activity Log"]})}),e.jsxs(Pe,{className:"sm:max-w-lg bg-white border-[#CFCFCF] max-h-[80vh] flex flex-col",children:[e.jsxs(Ue,{children:[e.jsx(Oe,{className:"text-[#111111] text-lg",children:"Ingestion Activity Log"}),e.jsx("p",{className:"text-sm text-[#111111]/50",children:"Timestamped history of actions on this page"})]}),e.jsx(Ks,{className:"flex-1 -mx-6 px-6",style:{maxHeight:"60vh"},children:C?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(H,{className:"w-5 h-5 animate-spin text-[#111111]/40"})}):Object.keys(N).length===0?e.jsx("p",{className:"text-sm text-[#111111]/40 text-center py-12",children:"No activity recorded yet"}):e.jsx("div",{className:"space-y-6",children:Object.entries(N).map(([d,b])=>e.jsxs("div",{children:[e.jsx("h3",{className:"text-xs font-semibold text-[#111111]/40 uppercase tracking-wider mb-2 sticky top-0 bg-white py-1",children:d}),e.jsx("div",{className:"space-y-1",children:b.map(g=>e.jsxs("div",{className:"flex gap-3 py-2 px-2 hover:bg-[#F4F4F4] rounded text-sm",children:[e.jsx("span",{className:"text-[#111111]/40 tabular-nums whitespace-nowrap",children:de(new Date(g.created_at),"HH:mm")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"font-medium text-[#111111]",children:g.action}),g.session_title&&g.session_id?e.jsxs("a",{href:g.session_id.startsWith("http")?g.session_id:`#session-${g.session_id}`,className:"text-primary hover:underline ml-1 text-sm",onClick:$=>$.stopPropagation(),title:g.session_id,children:["— ",g.session_title]}):g.session_title?e.jsxs("span",{className:"text-[#111111]/50 ml-1",children:["— ",g.session_title]}):null,g.detail&&e.jsx("p",{className:"text-[#111111]/40 text-xs mt-0.5 break-words",children:g.detail})]})]},g.id))})]},d))})})]})]})},ot={not_started:"bg-[#F4F4F4] text-[#111111]/50",in_progress:"bg-amber-50 text-amber-700 border-amber-200",complete:"bg-emerald-50 text-emerald-700 border-emerald-200",error:"bg-red-50 text-red-700 border-red-200",loaded_error:"bg-red-50 text-red-700 border-red-200",none:"bg-[#F4F4F4] text-[#111111]/50",suggested:"bg-blue-50 text-blue-700 border-blue-200",approved:"bg-emerald-50 text-emerald-700 border-emerald-200",pending:"bg-amber-50 text-amber-700 border-amber-200",partial:"bg-blue-50 text-blue-700 border-blue-200"},dt={not_started:"Not started",in_progress:"In progress",complete:"Complete",error:"Error",loaded_error:"Loaded-Error",none:"None",suggested:"Suggested",approved:"Approved",pending:"Pending",partial:"Partial"},ke=[{num:0,label:"No VTT",color:"bg-gray-100 text-gray-500 border-gray-200",tooltip:"No transcript uploaded yet"}
6,{num:1,label:"Transcribed",color:"bg-amber-100 text-amber-700 border-amber-300",tooltip:"VTT uploaded — next: create chunks"},{num:2,label:"Chunks",color:"bg-amber-50 text-amber-600 border-amber-200",tooltip:"Chunks created — next: test a chunk"},{num:3,label:"Tested",color:"bg-teal-50 text-teal-700 border-teal-300",tooltip:"Chunk test passed — next: classify & stitch"},{num:4,label:"Clips",color:"bg-lime-50 text-lime-700 border-lime-300",tooltip:"Clips created — next: enable engine"},{num:5,label:"Engine",color:"bg-emerald-50 text-emerald-700 border-emerald-300",tooltip:"Included in Decision Support"}];function te(t){return t.engine_enabled?ke[5]:["approved","partial"].includes(t.chunk_approval_status)?ke[4]:t.clip_test_status==="pass"?ke[3]:(t.chunk_count??0)>0?ke[2]:t.transcript_status==="complete"?ke[1]:ke[0]}const ut={1:"Create chunks",2:"Test chunk",3:"Classify & stitch",4:"Enable engine"},kt=()=>{var Qe;const t=ns(),o=ls(),[j,C]=l.useState(""),[N,d]=l.useState("all"),[b,g]=l.useState("all"),[$,W]=l.useState("all"),[B,U]=l.useState("all"),[y,z]=l.useState(null),[ae,pe]=l.useState(!1),[ne,_e]=l.useState(!1),[xe,fe]=l.useState(!1),[ie,ge]=l.useState(""),[le,be]=l.useState("session_date"),[a,v]=l.useState("desc"),[m,E]=l.useState(null),[r,h]=l.useState(!1),[_,V]=l.useState(null),[p,c]=l.useState(null),[R,ue]=l.useState(!1),[Q,ce]=l.useState(null),[A,K]=l.useState(new Set),[M,F]=l.useState(!1),[x,T]=l.useState(""),S=s=>{const n={id:s.id,title:s.title,description:null,host_name:s.host_name,host_role:s.host_role,host_company:s.host_company,host_avatar_url:null,session_date:s.session_date,session_time:null,duration_minutes:s.duration_minutes||0,session_type:s.session_type,region:null,image_url:null,recording_url:s.recording_url,program_type_id:null,is_recorded:!!s.recording_url,is_public:!1,wp_event_id:null,utc_start:null,timezone_slots:null};E(n),h(!0)},re=async()=>{var s;try{const{data:n}=await u.from("profiles").select("id").eq("user_id",((s=(await u.auth.getUser()).data.user)==null?void 0:s.id)||"").single();await u.functions.invoke("snapshot-ingestion-process",{body:{created_by:(n==null?void 0:n.id)||null}})}catch(n){console.warn("Snapshot check failed (non-blocking):",n)}o("Opened Bulk Re-ingest"),_e(!0)},{data:P,isLoading:Ee,refetch:Y}=He({queryKey:["admin-video-ingestion"],queryFn:async()=>{const{data:s,error:n}=await u.from("wequal_sessions").select("id, title, host_name, host_company, host_role, session_date, session_type, duration_minutes, recording_url, transcript_status, tags_status, engine_enabled, transcript_updated_at, transcript_word_count, chunk_count, tags, ingestion_notes, last_error, content_start_sec, searchable_chunk_count, clip_count, low_confidence_count, chunk_approval_status, clip_approval_status, intro_detection_method, clip_test_status").not("recording_url","is",null).order("session_date",{ascending:!1});if(n)throw n;const i=s||[];if(i.length>0){const k=i.map(q=>q.id),{data:w}=await u.from("session_speakers").select("session_id, speaker_name").in("session_id",k).order("display_order",{ascending:!0});if(w){const q=new Map;for(const f of w)q.has(f.session_id)||q.set(f.session_id,f.speaker_name);for(const f of i)f.speaker_name=q.get(f.id)||null}}return i}}),we=l.useCallback(async s=>{const{data:n,error:i}=await u.from("wequal_sessions").select("vtt_raw_text").eq("id",s.id).single();if(i)throw i;if(!(n!=null&&n.vtt_raw_text))throw new Error("No VTT text stored for this session — upload a VTT first");const{error:k}=await u.functions.invoke("ingest-vtt",{body:{session_id:s.id,vtt_text:n.vtt_raw_text}});if(k)throw k;o("Ingested VTT → chunks",{sessionId:s.id,sessionTitle:s.title})},[]),Ne=l.useCallback(async s=>{const{error:n}=await u.functions.invoke("classify-chunks",{body:{session_id:s.id}});if(n)throw n;const{error:i}=await u.functions.invoke("stitch-clips",{body:{session_id:s.id}});if(i)throw i;await u.from("session_transcript_chunks").update({approval_status:"approved"}).eq("session_id",s.id).eq("is_searchable",!0),await u.from("session_clip_spans").update({approval_status:"approved"}).eq("session_id",s.id),await u.from("wequal_sessions").update({chunk_approval_status:"approved",clip_approval_status:"approved"}).eq("id",s.id),o("Classified & stitched",{sessionId:s.id,sessionTitle:s.title})},[]),ve=l.useCallback(async s=>{const{error:n}=await u.from("wequal_sessions").update({engine_enabled:!0}).eq("id",s.id);if(n)throw n;o("Enabled engine",{sessionId:s.id,sessionTitle:s.title})},[]),cs=l.useCallback(async s=>{var i,k,w;const n=te(s);ce(s.id);try{switch(n.num){case 1:await we(s),D.success(`Chunks created: ${(i=s.title)==null?void 0:i.slice(0,50)}`);break;case 2:V(s.id);break;case 3:await Ne(s),D.success(`Classified & stitched: ${(k=s.title)==null?void 0:k.slice(0,50)}`);break;case 4:await ve(s),D.success(`Engine enabled: ${(w=s.title)==null?void 0:w.slice(0,50)}`);break;default:return}Y()}catch(q){console.error(`Next step failed for ${s.title}:`,q),D.error(`Failed: ${q.message||String(q)}`)}finally{ce(null)}},[we,Ne,ve,Y]),Me=l.useCallback(async s=>{const n=te(s);n.num===1&&await we(s),n.num<=2&&await u.from("wequal_sessions").update({clip_test_status:"pass"}).eq("id",s.id),n.num<=3&&await Ne(s),n.num<=4&&await ve(s),o("Force to engine",{sessionId:s.id,sessionTitle:s.title})},[we,Ne,ve]),os=l.useCallback(async()=>{var q;if(!P||A.size===0)return;const s=P.filter(f=>A.has(f.id)),n=s.filter(f=>{const O=te(f);return O.num>=1&&O.num<=4&&O.num!==2}),i=s.filter(f=>te(f).num===2);if(n.length===0&&i.length===0){D.info("No selected sessions have a next step");return}F(!0);let k=0,w=0;for(const f of n)try{T(`${k+1}/${n.length}: ${(q=f.title)==null?void 0:q.slice(0,40)}...`);const O=te(f);O.num===1?await we(f):O.num===3?await Ne(f):O.num===4&&await ve(f),k++}catch(O){w++,console.error(`Batch next step failed for ${f.title}:`,O)}F(!1),T(""),K(new Set),D.success(`Advanced ${k} session${k!==1?"s":""}${w?`, ${w} failed`:""}${i.length?`. ${i.length} at "Chunks" stage need manual chunk testing.`:""}`),Y()},[P,A,we,Ne,ve,Y]),ds=l.useCallback(async()=>{var k;if(!P||A.size===0)return;const s=P.filter(w=>A.has(w.id)&&te(w).num>=1&&te(w).num<=4);if(s.length===0){D.info("No selected sessions can be forced to engine");return}F(!0);let n=0,i=0;for(const w of s)try{T(`Force ${n+1}/${s.length}: ${(k=w.title)==null?void 0:k.slice(0,40)}...`),await Me(w),n++}catch(q){i++,console.error(`Force failed for ${w.title}:`,q)}F(!1),T(""),K(new Set),D.success(`Forced ${n} session${n!==1?"s":""} to engine${i?`, ${i} failed`:""}`),Y()},[P,A,Me,Y]),us=l.useCallback(async()=>{var k;if(!P)return;const s=P.filter(w=>w.transcript_status==="complete"&&!w.engine_enabled&&(w.chunk_count??0)>0);if(s.length===0){D.info("No pending sessions to process");return}fe(!0);let n=0,i=0;for(const w of s)try{ge(`Processing ${n+1}/${s.length}: ${(k=w.title)==null?void 0:k.slice(0,40)}...`),await Me(w),n++}catch(q){i++,console.error(`Failed to process ${w.title}:`,q),o("Bulk process failed",{sessionId:w.id,sessionTitle:w.title,detail
6:String(q)})}fe(!1),ge(""),D.success(`Processed ${n} sessions${i?`, ${i} failed`:""}`),Y()},[P,Me,Y]),G=l.useMemo(()=>{if(!P)return[];const s=P.filter(n=>{var k,w,q,f;const i=j.toLowerCase();if(i&&!(((k=n.title)==null?void 0:k.toLowerCase().includes(i))||((w=n.speaker_name)==null?void 0:w.toLowerCase().includes(i))||((q=n.host_name)==null?void 0:q.toLowerCase().includes(i))||((f=n.host_company)==null?void 0:f.toLowerCase().includes(i)))||N!=="all"&&n.session_type!==N||b!=="all"&&n.transcript_status!==b||$!=="all"&&String(te(n).num)!==$)return!1;if(B!=="all"){const O=B==="yes";if(n.engine_enabled!==O)return!1}return!0});return s.sort((n,i)=>{const k=a==="asc"?1:-1;switch(le){case"title":return k*(n.title||"").localeCompare(i.title||"");case"host_name":return k*(n.speaker_name||n.host_name||"").localeCompare(i.speaker_name||i.host_name||"");case"session_date":return k*(n.session_date||"").localeCompare(i.session_date||"");case"transcript_status":return k*(n.transcript_status||"").localeCompare(i.transcript_status||"");case"content_start_sec":return k*((n.content_start_sec??-1)-(i.content_start_sec??-1));case"searchable_chunk_count":return k*((n.searchable_chunk_count??0)-(i.searchable_chunk_count??0));case"clip_count":return k*((n.clip_count??0)-(i.clip_count??0));case"stage":return k*(te(n).num-te(i).num);case"engine_enabled":return k*(Number(n.engine_enabled)-Number(i.engine_enabled));default:return 0}}),s},[P,j,N,b,$,B,le,a]),he=s=>{le===s?v(n=>n==="asc"?"desc":"asc"):(be(s),v(s==="title"||s==="host_name"?"asc":"desc"))},me=({column:s})=>le!==s?e.jsx(Xs,{className:"w-3 h-3 ml-1 inline opacity-40"}):a==="asc"?e.jsx(Js,{className:"w-3 h-3 ml-1 inline"}):e.jsx(Zs,{className:"w-3 h-3 ml-1 inline"}),hs=s=>{z(s),pe(!0)},ms=async s=>{if(s.transcript_status!=="complete"||s.chunk_approval_status==="pending"||(s.searchable_chunk_count??0)<1)return;const n=!s.engine_enabled,{error:i}=await u.from("wequal_sessions").update({engine_enabled:n}).eq("id",s.id);i?D.error(i.message):(o(n?"Enabled engine":"Disabled engine",{sessionId:s.id,sessionTitle:s.title}),Y())},ps=async()=>{if(p){ue(!0);try{const[s,n,i,k]=await Promise.all([u.from("session_transcript_chunks").delete().eq("session_id",p),u.from("session_clip_spans").delete().eq("session_id",p),u.from("v2_chunks").delete().eq("session_id",p),u.from("v2_clips").delete().eq("session_id",p)]),w=s.error||n.error||i.error||k.error;if(w)throw new Error(w.message);const{error:q}=await u.from("wequal_sessions").update({transcript_status:"not_started",engine_enabled:!1,clip_test_status:null,chunk_count:0,searchable_chunk_count:0,clip_count:0,low_confidence_count:0,chunk_approval_status:"pending",clip_approval_status:"pending",content_start_sec:null,intro_detection_confidence:null,intro_detection_method:null,embedding_status:"not_started",embedding_updated_at:null,transcript_updated_at:null,transcript_word_count:null,tags:null,tags_status:"none",last_error:null,vtt_raw_text:null,vtt_filename:null}).eq("id",p);if(q)throw q;const f=P==null?void 0:P.find(O=>O.id===p);o("Reset session pipeline",{sessionId:p,sessionTitle:f==null?void 0:f.title}),D.success("Session reset — ready for re-ingestion"),ue(!1),c(null),await Y()}catch(s){D.error(s.message||"Failed to reset session"),ue(!1),c(null)}}},xs=()=>{if(!G.length)return;const s=["Title","Speaker","Company","Date","Type","Stage","Transcript","Content Start (s)","Searchable Chunks","Clips","Low Confidence","Engine"],n=G.map(f=>{const O=te(f);return[`"${(f.title||"").replace(/"/g,'""')}"`,`"${(f.speaker_name||f.host_name||"").replace(/"/g,'""')}"`,`"${(f.host_company||"").replace(/"/g,'""')}"`,de(new Date(f.session_date),"yyyy-MM-dd"),f.session_type.replace("_"," "),`${O.num}/5 ${O.label}`,f.transcript_status,f.content_start_sec??"",f.searchable_chunk_count??0,f.clip_count??0,f.low_confidence_count??0,f.engine_enabled?"Yes":"No"]}),i=[s.join(","),...n.map(f=>f.join(","))].join(`
7`),k=new Blob([i],{type:"text/csv"}),w=URL.createObjectURL(k),q=document.createElement("a");q.href=w,q.download=`video-ingestion-${de(new Date,"yyyy-MM-dd")}.csv`,q.click(),URL.revokeObjectURL(w),D.success(`Downloaded ${G.length} sessions`)},fs=s=>s.transcript_status!=="complete"||!["approved","partial"].includes(s.chunk_approval_status)||(s.searchable_chunk_count??0)<1;l.useMemo(()=>new Set(G.map(s=>s.id)),[G]);const Ke=G.length>0&&G.every(s=>A.has(s.id)),gs=A.size>0,_s=()=>{K(Ke?new Set:new Set(G.map(s=>s.id)))},js=s=>{K(n=>{const i=new Set(n);return i.has(s)?i.delete(s):i.add(s),i})};return e.jsx(Ss,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-end mt-5",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsxs(L,{variant:"outline",onClick:re,className:"border-[#CFCFCF] gap-2 text-[#111111]/70 hover:text-[#111111]",children:[e.jsx(as,{className:"w-4 h-4"}),"Bulk Re-ingest"]})}),e.jsx(ee,{side:"bottom",children:"Upload VTT files, create AI summaries, match to sessions"})]}),e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsx("span",{children:e.jsx(lt,{})})}),e.jsx(ee,{side:"bottom",children:"Fix recurring transcription errors"})]}),e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsxs(L,{variant:"outline",onClick:us,disabled:xe||Ee,className:"border-[#CFCFCF] gap-2 text-[#111111]/70 hover:text-[#111111]",children:[xe?e.jsx(H,{className:"w-4 h-4 animate-spin"}):e.jsx(Fs,{className:"w-4 h-4"}),"Force All to Engine"]})}),e.jsx(ee,{side:"bottom",children:"Force all pending sessions (with chunks) through full pipeline to engine"})]}),e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsxs(L,{variant:"outline",onClick:()=>t("/member-portal/admin?tab=chunk-analytics"),className:"border-[#CFCFCF] gap-2 text-[#111111]/70 hover:text-[#111111]",children:[e.jsx(Ts,{className:"w-4 h-4"}),"Chunk Review"]})}),e.jsx(ee,{side:"bottom",children:"Review and approve classified transcript chunks"})]}),e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsx("span",{children:e.jsx(ct,{})})}),e.jsx(ee,{side:"bottom",children:"View recent ingestion activity"})]}),e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsxs(L,{variant:"outline",onClick:()=>t("/member-portal/admin?tab=ingestion-docs"),className:"border-[#CFCFCF] gap-2 text-[#111111]/70 hover:text-[#111111]",children:[e.jsx($s,{className:"w-4 h-4"}),"Document"]})}),e.jsx(ee,{side:"bottom",children:"Pipeline documentation and reference"})]})]}),xe&&ie&&e.jsx("p",{className:"text-xs text-[#111111]/50 mt-2",children:ie})]}),gs&&e.jsxs("div",{className:"bg-[#111111] text-white px-4 py-3 rounded-xl flex items-center justify-between sticky top-0 z-20 shadow-lg",children:[e.jsxs("span",{className:"text-sm font-medium",children:[A.size," session",A.size!==1?"s":""," selected"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[M&&x&&e.jsx("span",{className:"text-xs text-white/60 mr-2",children:x}),e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsxs(L,{size:"sm",variant:"outline",onClick:os,disabled:M,className:"bg-white/10 border-white/20 text-white hover:bg-white/20 gap-2",children:[M?e.jsx(H,{className:"w-4 h-4 animate-spin"}):e.jsx(Xe,{className:"w-4 h-4"}),"Next Step"]})}),e.jsx(ee,{children:"Advance each selected session to its next pipeline stage"})]}),e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsxs(L,{size:"sm",variant:"outline",onClick:ds,disabled:M,className:"bg-white/10 border-white/20 text-white hover:bg-white/20 gap-2",children:[M?e.jsx(H,{className:"w-4 h-4 animate-spin"}):e.jsx(Ys,{className:"w-4 h-4"}),"Force to Engine"]})}),e.jsx(ee,{children:"Skip manual review — run full pipeline for selected sessions"})]}),e.jsx(L,{size:"sm",variant:"ghost",onClick:()=>K(new Set),className:"text-white/60 hover:text-white hover:bg-white/10",children:"Clear"})]})]}),e.jsxs("div",{className:"bg-white border border-[#CFCFCF] p-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Es,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[#111111]/40"}),e.jsx(Te,{placeholder:"Search title, host, company...",value:j,onChange:s=>C(s.target.value),className:"pl-10 border-[#CFCFCF]"})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs(Ce,{value:N,onValueChange:d,children:[e.jsx(ye,{className:"w-[160px] border-[#CFCFCF]",children:e.jsx(Se,{placeholder:"Session type"})}),e.jsxs(Fe,{children:[e.jsx(I,{value:"all",children:"All types"}),e.jsx(I,{value:"executives",children:"Executives"}),e.jsx(I,{value:"rising_leaders",children:"Rising Leaders"}),e.jsx(I,{value:"community",children:"Community"})]})]}),e.jsxs(Ce,{value:b,onValueChange:g,children:[e.jsx(ye,{className:"w-[180px] border-[#CFCFCF]",children:e.jsx(Se,{placeholder:"Transcript status"})}),e.jsxs(Fe,{children:[e.jsx(I,{value:"all",children:"All transcript"}),e.jsx(I,{value:"not_started",children:"Not started"}),e.jsx(I,{value:"in_progress",children:"In progress"}),e.jsx(I,{value:"complete",children:"Complete"}),e.jsx(I,{value:"error",children:"Error"}),e.jsx(I,{value:"loaded_error",children:"Loaded-Error"})]})]}),e.jsxs(Ce,{value:$,onValueChange:W,children:[e.jsx(ye,{className:"w-[180px] border-[#CFCFCF]",children:e.jsx(Se,{placeholder:"Stage"})}),e.jsxs(Fe,{children:[e.jsx(I,{value:"all",children:"All stages"}),e.jsx(I,{value:"0",children:"0/5 No VTT"}),e.jsx(I,{value:"1",children:"1/5 Transcribed"}),e.jsx(I,{value:"2",children:"2/5 Chunks"}),e.jsx(I,{value:"3",children:"3/5 Approved"}),e.jsx(I,{value:"4",children:"4/5 Tested"}),e.jsx(I,{value:"5",children:"5/5 Engine"})]})]}),e.jsxs(Ce,{value:B,onValueChange:U,children:[e.jsx(ye,{className:"w-[160px] border-[#CFCFCF]",children:e.jsx(Se,{placeholder:"Engine"})}),e.jsxs(Fe,{children:[e.jsx(I,{value:"all",children:"All engine"}),e.jsx(I,{value:"yes",children:"Enabled"}),e.jsx(I,{value:"no",children:"Disabled"})]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-[#111111]/50",children:Ee?"Loading...":`${G.length} session${G.length!==1?"s":""} with recordings`}),e.jsxs(L,{variant:"outline",size:"sm",onClick:xs,disabled:Ee||G.length===0,className:"border-[#CFCFCF] gap-2 text-[#111111]/70 hover:text-[#111111]",children:[e.jsx(Ms,{className:"w-4 h-4"}),"Download CSV"]})]}),Ee?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(H,{className:"w-6 h-6 animate-spin text-[#111111]/40"})}):e.jsx("div",{className:"bg-white border border-[#CFCFCF] overflow-hidden",children:e.jsxs(qs,{children:[e.jsx(Ls,{children:e.jsxs(Ie,{className:"border-b border-[#CFCFCF]",children:[e.jsx(se,{className:"w-[40px] text-center",children:e.jsx(Je,{checked:Ke,onCheckedChange:_s,"aria-label":"Select all"})}),e.jsxs(se,{className:"text-[#111111]/60 text-xs font-medium uppercase tracking-wider cursor-pointer select-none",onClick:()=>he("title"),children:["Title",e.jsx(me,{column:"title"})]}),e.jsxs(se,{className:"text-[#111111]/60 text-xs font-medium uppercase tracking-wider cursor-pointer select-none",onClick:()=>he("host_name"),children:["Speaker",e.jsx(me,{column:"host_name"})]}),e.jsxs(se,{className:"text-[#111111]/60 text-xs font-medium uppercase tracking-wider hidden md:table-cell cursor-pointer select-none",onClick:()=>he("session_date"),children:["Date",e.jsx(me,{column:"session_date"})]}),e.jsxs(se,{className:"text-[#111111]/60 text-xs font-medium uppercase tracking-wider cursor-pointer select-none",onClick:()=>he("transcript_status"),children:["Transcript",e.jsx(me,{column:"transcript_status"})]}),e.jsxs(se,{className:"text-[#111111]/60 text-xs font-medium uppercase tracking-wider hidden lg:table-cell cursor-pointer select-none",onClick:()=>
7he("content_start_sec"),children:["Content Start",e.jsx(me,{column:"content_start_sec"})]}),e.jsxs(se,{className:"text-[#111111]/60 text-xs font-medium uppercase tracking-wider hidden lg:table-cell cursor-pointer select-none",onClick:()=>he("searchable_chunk_count"),children:["Chunks",e.jsx(me,{column:"searchable_chunk_count"})]}),e.jsxs(se,{className:"text-[#111111]/60 text-xs font-medium uppercase tracking-wider hidden lg:table-cell cursor-pointer select-none",onClick:()=>he("clip_count"),children:["Clips",e.jsx(me,{column:"clip_count"})]}),e.jsxs(se,{className:"text-[#111111]/60 text-xs font-medium uppercase tracking-wider hidden md:table-cell cursor-pointer select-none",onClick:()=>he("stage"),children:["Stage",e.jsx(me,{column:"stage"})]}),e.jsx(se,{className:"text-[#111111]/60 text-xs font-medium uppercase tracking-wider hidden md:table-cell",children:"Test"}),e.jsxs(se,{className:"text-[#111111]/60 text-xs font-medium uppercase tracking-wider hidden md:table-cell cursor-pointer select-none",onClick:()=>he("engine_enabled"),children:["Engine",e.jsx(me,{column:"engine_enabled"})]}),e.jsx(se,{className:"text-[#111111]/60 text-xs font-medium uppercase tracking-wider text-right",children:"Actions"})]})}),e.jsx(Ps,{children:G.length===0?e.jsx(Ie,{children:e.jsx(X,{colSpan:12,className:"text-center text-[#111111]/40 py-12",children:"No sessions match your filters"})}):G.map(s=>{const n=s.content_start_sec!=null?`${Math.floor(s.content_start_sec/60)}:${String(s.content_start_sec%60).padStart(2,"0")}`:"—",i=te(s),k=ut[i.num],w=Q===s.id;return e.jsxs(Ie,{className:`border-b border-[#CFCFCF]/50 hover:bg-[#F4F4F4]/50 ${A.has(s.id)?"bg-blue-50/50":""}`,children:[e.jsx(X,{className:"text-center",children:e.jsx(Je,{checked:A.has(s.id),onCheckedChange:()=>js(s.id),"aria-label":`Select ${s.title}`})}),e.jsx(X,{className:"font-medium max-w-[200px] truncate",children:e.jsx("button",{className:"text-left text-[#111111] hover:text-community underline-offset-2 hover:underline cursor-pointer truncate w-full",onClick:()=>S(s),title:"Open session detail",children:s.title})}),e.jsx(X,{className:"text-[#111111]/70 max-w-[120px] truncate",children:s.speaker_name||s.host_name||"—"}),e.jsx(X,{className:"text-[#111111]/70 hidden md:table-cell whitespace-nowrap",children:de(new Date(s.session_date),"dd MMM yy")}),e.jsx(X,{children:e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsx("span",{children:e.jsx(oe,{variant:"outline",className:`text-xs ${ot[s.transcript_status]||""}`,children:dt[s.transcript_status]||s.transcript_status})})}),s.transcript_status==="loaded_error"&&e.jsx(ee,{children:"Transcript doesn't match video"})]})}),e.jsxs(X,{className:"hidden lg:table-cell text-sm text-[#111111]/70 font-mono",children:[n,s.intro_detection_method==="ai_detected"&&e.jsx("span",{className:"ml-1 text-[10px] text-emerald-600",title:"AI detected",children:"AI"})]}),e.jsxs(X,{className:"hidden lg:table-cell text-sm",children:[e.jsx("span",{className:"text-[#111111]",children:s.searchable_chunk_count??0}),e.jsxs("span",{className:"text-[#111111]/40",children:["/",s.chunk_count??0]}),(s.low_confidence_count??0)>0&&e.jsxs("span",{className:"ml-1 text-amber-600 text-xs",title:"Low confidence chunks",children:["⚠",s.low_confidence_count]})]}),e.jsx(X,{className:"hidden lg:table-cell text-sm text-[#111111]/70",children:s.clip_count??0}),e.jsx(X,{className:"hidden md:table-cell",children:e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsx("span",{children:e.jsxs(oe,{variant:"outline",className:`text-xs font-medium ${i.color}`,children:[i.num,"/5 ",i.label]})})}),e.jsx(ee,{children:i.tooltip})]})}),e.jsx(X,{className:"hidden md:table-cell",children:i.num<2?e.jsx("span",{className:"text-muted-foreground",children:"—"}):s.clip_test_status==="pass"?e.jsx(Gs,{className:"w-4 h-4 text-emerald-600"}):s.clip_test_status==="fail"?e.jsx(Ae,{className:"w-4 h-4 text-red-500"}):e.jsx(L,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>V(s.id),children:"Test"})}),e.jsx(X,{className:"hidden md:table-cell",children:e.jsx(rs,{checked:s.engine_enabled,disabled:fs(s),onCheckedChange:()=>ms(s),className:"data-[state=checked]:bg-emerald-500"})}),e.jsxs(X,{className:"text-right flex items-center gap-1 justify-end",children:[k&&e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>cs(s),disabled:w||Q!==null&&Q!==s.id||M,className:"text-emerald-600 hover:text-emerald-700 h-8 w-8 p-0",children:w?e.jsx(H,{className:"w-4 h-4 animate-spin"}):e.jsx(Xe,{className:"w-4 h-4"})})}),e.jsx(ee,{children:k})]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>hs(s),className:"text-[#111111]/60 hover:text-[#111111] h-8 w-8 p-0",title:"View details",children:e.jsx(Ds,{className:"w-4 h-4"})}),s.transcript_status!=="not_started"&&e.jsxs(J,{children:[e.jsx(Z,{asChild:!0,children:e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>c(s.id),className:"text-destructive/40 hover:text-destructive h-8 w-8 p-0",children:e.jsx(We,{className:"w-4 h-4"})})}),e.jsx(ee,{children:"Reset session — remove all pipeline data"})]})]})]},s.id)})})]})}),e.jsx(it,{session:y,open:ae,onOpenChange:pe,onTitleClick:S,onRefresh:async()=>{const{data:s}=await Y();if(y&&s){const n=s.find(i=>i.id===y.id);n&&z(n)}}}),e.jsx(nt,{open:ne,onOpenChange:_e,onComplete:()=>Y()}),e.jsx(As,{session:m,isOpen:r,onClose:()=>h(!1),onRegister:()=>{},isRegistering:!1,cohortType:(m==null?void 0:m.session_type)||"rising_leaders"}),_&&e.jsx(Qs,{sessionId:_,open:!!_,onOpenChange:s=>{s||V(null)},recordingUrl:((Qe=P==null?void 0:P.find(s=>
7s.id===_))==null?void 0:Qe.recording_url)??null,onResult:()=>{V(null),Y()},pipeline:"v1"}),e.jsx(Rs,{open:!!p,onOpenChange:s=>{s||c(null)},children:e.jsxs(Is,{children:[e.jsxs(Bs,{children:[e.jsx(Vs,{children:"Reset Session Pipeline"}),e.jsx(zs,{children:'This will permanently delete all chunks, clips, embeddings, test results, and engine status for this session. The session record itself will be kept but reset to "Not started". You will need to re-ingest the VTT to rebuild.'})]}),e.jsxs(Us,{children:[e.jsx(Os,{disabled:R,children:"Cancel"}),e.jsxs(Ws,{onClick:ps,disabled:R,className:"bg-red-600 hover:bg-red-700 text-white",children:[R?e.jsx(H,{className:"w-4 h-4 animate-spin mr-1"}):null,"Reset Session"]})]})]})})]})})};export{kt 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.