PageSourceSearch

https://artofthinking.ai/assets/HostExperiencePage-DoNKGeHK.js

js artofthinking.ai collected 2026-10-05 15:27:51 UTC 184,053 bytes, 36 lines download raw bytes

1import{r as n,j as e,c as u,a as i,g as ws,h as Et,i as Se,k as Gs,l as ze,b as je,C as Dt,d as Mt,m as $t,e as Lt,n as Ft,u as Ot,o as _t,L as q}from"./index-BuOO3G1w.js";import{T as De}from"./TopNav-C6B6VZE6.js";import{L as Ks,f as Wt,P as Bt}from"./ParticipationAudienceSettings-CEVdoF-L.js";import{U as Ut,C as Vt}from"./CadenceReadings-PteuLMfw.js";import{A as Jt,W as Ht,a as Qt}from"./AnswersSlideDeck-BqF8hnT8.js";import{A as zt}from"./AlignYourAiDoors-C3WFI3nn.js";import{f as Gt,a as Kt,b as qt,s as Yt,D as qs,u as Xt,c as ve,d as Ys,e as Zt,g as Ge,t as Xs,h as ks,i as Zs,j as ea}from"./sessionApi-CMmQr_Ff.js";import{V as sa}from"./VoiceAnswer-MzYzI4rk.js";import{T as ta}from"./TopicWordsEditor-eQr4eTd0.js";import{S as aa}from"./SuggestedTermsRow-ma70OCGo.js";import{c as ra}from"./programmeApi-C7vc37IK.js";import{C as na,p as la}from"./ContinuationPaymentPanel-CsvHqSPm.js";import{h as ia,i as oa}from"./studyApi-H9G0AnP2.js";import{f as vs}from"./api-C4ifs5Ra.js";import{I as da}from"./InviteParticipantsSection-DGt0Vj4m.js";import{P as ca}from"./ParticipateFirstSection-BWgtsf8M.js";import{d as ma,S as xa,a as ua}from"./StudyDaySummaryView-Bv4A1dNu.js";import"./homeChrome-8HFC7eDx.js";import"./useAnalyticsQueries-7V7pGSCG.js";import"./ParticipantFeedbackButtons-D_Vt0bXy.js";import"./voiceApi-Oys8VyGR.js";import"./SessionQRCode-BlQ9hDtj.js";import"./AboutThisRoundCard-BQRaz0MM.js";import"./SmallestGroupSelect-DuQYyZxy.js";import"./EntryPathSteps-Cywd99lM.js";import"./polarScalesConfig-BVC614g4.js";import"./index-CgQrzHZb.js";import"./SessionClusterFlow-DejjRbvI.js";import"./StudyClusterFlowSankey-CSTeaSAp.js";import"./ChalkboardLabel-DJN6LRan.js";import"./ChalkboardHeading-CBj6vSIZ.js";import"./ChalkboardCard-D84CjrRp.js";import"./aiModelLogos-hudIQ5Y0.js";const Ye="What do you think you are talking about when you talk about [topic]?",et=()=>({title:"",description:"",totalDays:40,expectedParticipantCount:0,frequency:"DAILY",startDate:"",wordList:[],wordRepeatPattern:null,openTime:"08:00",closeTime:"18:00",publishTime:"21:00",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,responseWindowHours:10,canonicalPrompt:Ye,participantInstructions:"",aiInstructions:"",enableAiParticipants:!1,enableBenchmarkModels:!1,includeBenchmarksInAnalysis:!1,aiPanelId:null,acceptedResponseLanguages:["en"],insightLanguages:["en"],primaryLanguage:"en",autoPublishDailySynthesis:!0,autoTriggerLongitudinal:!1,publishToYouTube:!0,enableVideoGeneration:!0,visibility:"PARTICIPANT",allowOpenJoin:!1,arcReflectionEnabled:!1,arcReflectionRhythm:"weekly",arcReflectionIntervalDays:7,schedulingMode:"calendar",cycleDurationMinutes:1440,cycleCloseBeforePublishMinutes:15,reminderEnabled:!1,reminderOffsetMinutes:120,reminderRepeatIntervalMinutes:null,reminderMaxCount:1}),st=["Europe/Helsinki","Europe/London","Europe/Paris","Europe/Berlin","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","Asia/Tokyo","Asia/Singapore","Australia/Sydney","UTC"],pa=[{value:"DAILY",label:"Daily",description:"One prompt per day"},{value:"WEEKLY",label:"Weekly",description:"One prompt per week"},{value:"MONTHLY",label:"Monthly",description:"One prompt per month"}],ha=s=>[{value:"weekly",label:"Weekly",description:`Every 7 ${s}`,icon:"📅"},{value:"monthly",label:"Monthly",description:`Every 30 ${s}`,icon:"🗓️"},{value:"end_only",label:"At Study End",description:`Final ${s==="cycles"?"cycle":"day"} only`,icon:"🏁"},{value:"custom",label:"Custom",description:"Set your own interval",icon:"⚙️"}],ba=({state:s,onStateChange:a,isLoading:d=!1,isEditMode:c=!1,availablePanels:h=[]})=>{const[N,P]=n.useState(""),[j,b]=n.useState("simple");n.useEffect(()=>{s.wordList.length>0&&!N&&P(s.wordList.join(`
2`))},[s.wordList]);const T=n.useCallback(t=>t.split(`
3`).map(f=>f.trim()).filter(f=>f.length>0),[]),R=n.useCallback(t=>{P(t);const f=T(t),x={wordList:f};s.schedulingMode==="cycle"&&f.length>0&&(x.totalDays=f.length),a(x)},[a,T,s.schedulingMode]),m=n.useMemo(()=>{const t=s.wordList,f=s.totalDays;if(t.length===0)return{uniqueWords:0,wordRepeats:0,wordsPerCycle:0};const x=t.length,E=Math.ceil(f/x),y=t.length<f?Math.floor(f/t.length):1;return{uniqueWords:t.length,wordRepeats:y,wordsPerCycle:x,cycles:E}},[s.wordList,s.totalDays]),l=n.useMemo(()=>
3{if(!s.arcReflectionEnabled||s.totalDays<2)return[];const t=s.arcReflectionRhythm,f=[];if(t==="end_only")f.push(s.totalDays);else{const x=t==="weekly"?7:t==="monthly"?30:s.arcReflectionIntervalDays;if(x>0){for(let E=x;E<=s.totalDays;E+=x)f.push(E);(f.length===0||f[f.length-1]!==s.totalDays)&&f.push(s.totalDays)}}return f},[s.arcReflectionEnabled,s.arcReflectionRhythm,s.arcReflectionIntervalDays,s.totalDays]);n.useCallback(()=>{const t=s.wordList;if(t.length===0||t.length>=s.totalDays){a({wordRepeatPattern:null});return}const f={};for(let x=0;x<s.totalDays;x++){const E=t[x%t.length];f[E]||(f[E]=[]),f[E].push(x)}a({wordRepeatPattern:f})},[s.wordList,s.totalDays,a]);const C=n.useMemo(()=>{const t=[];return s.title.trim()||t.push("Study title is required"),s.wordList.length===0&&t.push("At least one word is required"),s.totalDays<1&&t.push("Total days must be at least 1"),s.totalDays>365&&t.push("Total days cannot exceed 365"),t},[s]);return C.length,e.jsxs("section",{className:u("rounded-2xl border p-6 sm:p-8 shadow-xl shadow-emerald-500/10",i.dark.borderSubtle,i.dark.surface),children:[e.jsx("div",{className:u("mb-8 border-b pb-6",i.dark.borderSubtle),children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-2xl",children:"📊"}),e.jsxs("div",{children:[e.jsx("h2",{className:u("text-2xl font-bold font-serif",i.dark.textPrimary),children:c?"Edit Study Configuration":"Configure Your Study"}),e.jsx("p",{className:u("mt-1 text-sm",i.dark.textMuted),children:"Set up a longitudinal self-research study with daily word prompts."})]})]})}),e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"rounded-xl border border-emerald-900/40 bg-emerald-600/5 p-4",children:[e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wide text-emerald-700 mb-2 font-serif",children:"Self-Research Daily Format"}),e.jsxs("p",{className:"text-xs text-slate-700 leading-relaxed",children:["Participants respond to one word prompt per day over a defined period. The same words can repeat to enable longitudinal comparison of how perspectives evolve over time. ",e.jsx("strong",{children:"No diagnosis, no scores, no optimization feedback"})," — purely observational, participant-sovereign data collection."]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:u("text-lg font-semibold font-serif flex items-center gap-2",i.dark.textPrimary),children:[e.jsx("span",{children:"📝"})," Basic Information"]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"study-title",className:"block text-sm font-semibold uppercase tracking-wide text-slate-700",children:["Study Title ",e.jsx("span",{className:"text-rose-700",children:"*"})]}),e.jsx("input",{id:"study-title",type:"text",value:s.title,onChange:t=>a({title:t.target.value}),disabled:d,placeholder:"e.g., States Over Traits: ADHD Field Study",className:u("mt-2 w-full rounded-lg border bg-white px-4 py-3 placeholder-stone-400 focus:border-emerald-600 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary)})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"study-description",className:"block text-sm font-semibold uppercase tracking-wide text-slate-700",children:"Description"}),e.jsx("textarea",{id:"study-description",value:s.description,onChange:t=>a({description:t.target.value}),disabled:d,placeholder:"What is this study about? What should participants know before joining?",rows:3,className:u("mt-2 w-full rounded-lg border bg-white px-4 py-3 placeholder-stone-400 focus:border-emerald-600 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary)})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:u("text-lg font-semibold font-serif flex items-center gap-2",i.dark.textPrimary),children:[e.jsx("span",{children:"💬"})," Word List ",e.jsx("span",{className:"text-rose-700",children:"*"})]}),e.jsx("p",{className:u("text-sm",i.dark.textMuted),children:"Enter the topic words for your study, one per line. Words will cycle through the study days. If you have fewer words than days, words will repeat."}),e.jsxs("div",{className:u("rounded-lg border bg-white p-4",i.dark.borderSubtle),children:[e.jsx("label",{htmlFor:"word-input",className:u("block text-xs font-medium mb-2",i.dark.textMuted),children:"Topic Words (one per line)"}),e.jsx("textarea",{id:"word-input",value:N,onChange:t=>R(t.target.value),disabled:d||c,placeholder:`Attention
4Energy
5Motivation
6Focus
7Rest
8Creativity
9Overwhelm
10Calm`,rows:8,className:u("w-full rounded-lg border bg-white px-4 py-3 font-mono text-sm placeholder-stone-400 focus:border-emerald-600 focus:outline-none disabled:opacity-50",i.dark.borderSubtle,i.dark.textPrimary)}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[s.wordList.slice(0,20).map((t,f)=>e.jsx("span",{className:u("inline-flex items-center rounded-lg px-3 py-1 text-xs text-slate-900",i.dark.surface),children:t},`${t}-${f}`)),s.wordList.length>20&&e.jsxs("span",{className:u("inline-flex items-center rounded-lg px-3 py-1 text-xs",i.dark.surface,i.dark.textMuted),children:["+",s.wordList.length-20," more"]})]})]}),s.wordList.length>0&&e.jsxs("div",{className:"rounded-lg border border-emerald-900/40 bg-emerald-600/5 p-4",children:[e.jsx("h4",{className:"text-sm font-semibold text-emerald-700 mb-2 font-serif",children:"Study Preview"}),e.jsxs("div",{className:`grid gap-4 text-center ${s.schedulingMode==="cycle"?"grid-cols-2":"grid-cols-2 sm:grid-cols-4"}`,children:[e.jsxs("div",{children:[e.jsx("p",{className:u("text-2xl font-bold",i.dark.textPrimary),children:s.schedulingMode==="cycle"?s.wordList.length:s.totalDays}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Total Days"})]}),e.jsxs("div",{children:[e.jsx("p",{className:u("text-2xl font-bold",i.dark.textPrimary),children:m.uniqueWords}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Unique Words"})]}),s.schedulingMode==="calendar"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("p",{className:u("text-2xl font-bold",i.dark.textPrimary),children:[m.wordRepeats,"×"]}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Words Repeat"})]}),e.jsxs("div",{children:[e.jsx("p",{className:u("text-2xl font-bold",i.dark.textPrimary),children:m.cycles||1}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Cycles"})]})]})]}),s.schedulingMode==="calendar"&&m.wordRepeats>1&&e.jsx("p",{className:"mt-3 text-xs text-emerald-700",children:"✨ Words will repeat, enabling longitudinal comparison of how perspectives evolve."})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:u("text-lg font-semibold font-serif flex items-center gap-2",i.dark.textPrimary),children:[e.jsx("span",{children:"⏰"})," Scheduling"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>a({schedulingMode:"calendar"}),disabled:d||c,className:`px-4 py-2 rounded-lg text-sm font-medium transition disabled:opacity-50 ${s.schedulingMode==="calendar"?"bg-emerald-600 text-white":"bg-stone-100 text-slate-700 hover:bg-stone-200"}`,children:"Calendar"}),e.jsx("button",{type:"button",onClick:()=>{const t={schedulingMode:"cycle"};s.wordList.length>0&&(t.totalDays=s.wordList.length),a(t)},disabled:d||c,className:`px-4 py-2 rounded-lg text-sm font-medium transition disabled:opacity-50 ${s.schedulingMode==="cycle"?"bg-emerald-600 text-white":"bg-stone-100 text-slate-700 hover:bg-stone-200"}`,children:"Cycle"})]}),s.schedulingMode==="cycle"?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:u("text-sm",i.dark.textMuted),children:["Each word opens automatically when the previous one's results are published. Study length = number of words (",s.wordList.length||"—",")."]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"cycle-duration",className:"block text-xs font-medium text-slate-700 mb-1",children:"Cycle Duration (hours)"}),e.jsx("input",{id:"cycle-duration",type:"number",min:"1",max:"168",step:"1",value:Math.round(s.cycleDurationMinutes/60),onChange:t=>a({cycleDurationMinutes:Math.max(60,(parseInt(t.target.value)||24)*60)}),disabled:d||c,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none disabled:opacity-50",i.dark.borderSubtle,i.dark.textPrimary)}
10),e.jsx("p",{className:u("mt-1 text-xs",i.dark.textFaint),children:"Min 1h (analysis needs time). Default: 24h."})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"cycle-buffer",className:"block text-xs font-medium text-slate-700 mb-1",children:"Close Before Publish (min)"}),e.jsx("input",{id:"cycle-buffer",type:"number",min:"5",max:"60",value:s.cycleCloseBeforePublishMinutes,onChange:t=>a({cycleCloseBeforePublishMinutes:parseInt(t.target.value)||15}),disabled:d||c,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none disabled:opacity-50",i.dark.borderSubtle,i.dark.textPrimary)}),e.jsx("p",{className:u("mt-1 text-xs",i.dark.textFaint),children:"Responses close this many minutes before publish."})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"timezone-cycle",className:"block text-xs font-medium text-slate-700 mb-1",children:"Timezone"}),e.jsx("select",{id:"timezone-cycle",value:s.timezone,onChange:t=>a({timezone:t.target.value}),disabled:d,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary),children:st.map(t=>e.jsx("option",{value:t,children:t},t))})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:u("text-sm",i.dark.textMuted),children:"Fixed daily schedule with set open, close, and publish times."}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"total-days",className:"block text-xs font-medium text-slate-700 mb-1",children:["Total Days ",e.jsx("span",{className:"text-rose-700",children:"*"})]}),e.jsx("input",{id:"total-days",type:"number",min:"1",max:"365",value:s.totalDays,onChange:t=>a({totalDays:parseInt(t.target.value)||40}),disabled:d||c,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none disabled:opacity-50",i.dark.borderSubtle,i.dark.textPrimary)}),e.jsx("p",{className:u("mt-1 text-xs",i.dark.textFaint),children:c?"Cannot change after creation":"Typical: 30-40 days"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"expected-participants",className:"block text-xs font-medium text-slate-700 mb-1",children:"Expected participants"}),e.jsx("input",{id:"expected-participants",type:"number",min:"0",value:s.expectedParticipantCount||"",onChange:t=>a({expectedParticipantCount:parseInt(t.target.value)||0}),disabled:d,placeholder:"e.g. 12",className:"w-full rounded-lg border border-stone-300 bg-white px-3 py-2 text-slate-900 focus:border-emerald-600 focus:outline-none disabled:opacity-50"}),e.jsx("p",{className:"mt-1 text-xs text-stone-500",children:"Reserves credits at activation (1 credit / participant per 30-day period). Leave blank to skip."})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"start-date",className:"block text-xs font-medium text-slate-700 mb-1",children:"Start Date"}),e.jsx("input",{id:"start-date",type:"date",value:s.startDate,onChange:t=>a({startDate:t.target.value}),disabled:d||c,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none disabled:opacity-50",i.dark.borderSubtle,i.dark.textPrimary)}),e.jsx("p",{className:u("mt-1 text-xs",i.dark.textFaint),children:c?"Cannot change after creation":"Leave empty to start manually"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-slate-700 mb-2",children:"Prompt Frequency"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:pa.map(t=>e.jsx("button",{type:"button",onClick:()=>a({frequency:t.value}),disabled:d||c,className:`px-4 py-2 rounded-lg text-sm font-medium transition disabled:opacity-50 ${s.frequency===t.value?"bg-emerald-600 text-white":"bg-stone-100 text-slate-700 hover:bg-stone-200"}`,children:t.label},t.value))})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"open-time",className:"block text-xs font-medium text-slate-700 mb-1",children:"Opens At"}),e.jsx("input",{id:"open-time",type:"time",value:s.openTime,onChange:t=>a({openTime:t.target.value}),disabled:d,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary)})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"close-time",className:"block text-xs font-medium text-slate-700 mb-1",children:"Closes At"}),e.jsx("input",{id:"close-time",type:"time",value:s.closeTime,onChange:t=>a({closeTime:t.target.value}),disabled:d,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary)})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"publish-time",className:"block text-xs font-medium text-slate-700 mb-1",children:"Publishes At"}),e.jsx("input",{id:"publish-time",type:"time",value:s.publishTime,onChange:t=>a({publishTime:t.target.value}),disabled:d,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary)})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"timezone-cal",className:"block text-xs font-medium text-slate-700 mb-1",children:"Timezone"}),e.jsx("select",{id:"timezone-cal",value:s.timezone,onChange:t=>a({timezone:t.target.value}),disabled:d,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary),children:st.map(t=>e.jsx("option",{value:t,children:t},t))})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:u("text-lg font-semibold font-serif flex items-center gap-2",i.dark.textPrimary),children:[e.jsx("span",{children:"🔔"})," Reminders"]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:s.reminderEnabled,onChange:t=>a({reminderEnabled:t.target.checked}
10),disabled:d,className:u("h-4 w-4 rounded bg-white text-emerald-500 focus:ring-emerald-500",i.dark.borderSubtle)}),e.jsx("span",{className:"text-sm text-slate-700",children:"Send reminders to non-respondents"})]}),s.reminderEnabled&&e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3 pl-7",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"reminder-offset",className:"block text-xs font-medium text-slate-700 mb-1",children:"First Reminder After (hours)"}),e.jsx("input",{id:"reminder-offset",type:"number",min:"0.5",max:"24",step:"0.5",value:s.reminderOffsetMinutes/60,onChange:t=>a({reminderOffsetMinutes:Math.max(30,(parseFloat(t.target.value)||2)*60)}),disabled:d,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary)})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"reminder-repeat",className:"block text-xs font-medium text-slate-700 mb-1",children:"Repeat Every (hours)"}),e.jsx("input",{id:"reminder-repeat",type:"number",min:"0",max:"24",step:"0.5",value:s.reminderRepeatIntervalMinutes?s.reminderRepeatIntervalMinutes/60:"",onChange:t=>{const f=parseFloat(t.target.value);a({reminderRepeatIntervalMinutes:f>0?f*60:null})},placeholder:"None",disabled:d,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none placeholder-slate-600",i.dark.borderSubtle,i.dark.textPrimary)}),e.jsx("p",{className:u("mt-1 text-xs",i.dark.textFaint),children:"Leave empty for single reminder"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"reminder-max",className:"block text-xs font-medium text-slate-700 mb-1",children:"Max Reminders"}),e.jsxs("select",{id:"reminder-max",value:s.reminderMaxCount,onChange:t=>a({reminderMaxCount:parseInt(t.target.value)||1}),disabled:d,className:u("w-full rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary),children:[e.jsx("option",{value:"1",children:"1"}),e.jsx("option",{value:"2",children:"2"}),e.jsx("option",{value:"3",children:"3"})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:u("text-lg font-semibold font-serif flex items-center gap-2",i.dark.textPrimary),children:[e.jsx("span",{children:"📋"})," Participant Instructions"]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"participant-instructions",className:"block text-sm font-semibold uppercase tracking-wide text-slate-700",children:"Instructions shown to participants"}),e.jsx("textarea",{id:"participant-instructions",value:s.participantInstructions,onChange:t=>a({participantInstructions:t.target.value}),disabled:d,placeholder:"Welcome to this self-research study! Each day you'll receive a word prompt. Respond with whatever comes to mind—there are no right or wrong answers. Your reflections are private and used only for collective analysis.",rows:4,className:u("mt-2 w-full rounded-lg border bg-white px-4 py-3 placeholder-stone-400 focus:border-emerald-600 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary)})]})]}),e.jsxs("div",{className:u("rounded-lg border p-4 space-y-4",i.dark.borderSubtle,i.dark.surface),children:[e.jsxs("h3",{className:u("text-lg font-semibold font-serif flex items-center gap-2",i.dark.textPrimary),children:[e.jsx("span",{children:"🤖"})," Custom AI Instructions"]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"enable-ai-participants",className:"block text-sm font-semibold uppercase tracking-wide text-slate-700",children:"AI Model Participants"}),e.jsx("p",{className:u("mt-1 text-xs",i.dark.textMuted),children:"When enabled, AI language models automatically respond to each question when the day closes. Their responses are analyzed alongside human responses."})]}),e.jsx("button",{id:"enable-ai-participants",type:"button",role:"switch","aria-checked":s.enableAiParticipants,onClick:()=>a({enableAiParticipants:!s.enableAiParticipants}),disabled:d,className:`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 focus:ring-offset-white ${s.enableAiParticipants?"bg-emerald-500":"bg-stone-300"} disabled:opacity-50`,children:e.jsx("span",{className:`pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${s.enableAiParticipants?"translate-x-5":"translate-x-0"}`})})]}),s.enableAiParticipants&&h.length>0&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"ai-panel",className:"block text-sm font-semibold uppercase tracking-wide text-slate-700 mb-1",children:"AI Panel"}),e.jsx("p",{className:u("text-xs mb-2",i.dark.textMuted),children:"Which group of AI models participates."}),e.jsxs("select",{id:"ai-panel",value:s.aiPanelId||"",onChange:t=>a({aiPanelId:t.target.value||null}),className:u("w-full border rounded-lg px-3 py-2 text-sm text-slate-900 focus:outline-none focus:ring-1 focus:ring-emerald-500",i.dark.surface,i.dark.borderSubtle),children:[e.jsx("option",{value:"",children:"All active models (no panel)"}),h.map(t=>e.jsxs("option",{value:t.id,children:[t.name," (",t.modelCount," models)",t.isDefault?" — default":""]},t.id))]})]}),s.enableAiParticipants&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"enable-benchmark-models",className:"block text-sm font-semibold uppercase tracking-wide text-slate-700",children:"Enable Benchmark Models"}),e.jsx("p",{className:u("mt-1 text-xs",i.dark.textMuted),children:"Run additional benchmark generations (blank condition + benchmark-only models) alongside session AI participants."})]}),e.jsx("button",{id:"enable-benchmark-models",type:"button",role:"switch","aria-checked":s.enableBenchmarkModels,onClick:()=>a({enableBenchmarkModels:!s.enableBenchmarkModels,...s.enableBenchmarkModels?{includeBenchmarksInAnalysis:!1}:{}}),disabled:d,className:`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 focus:ring-offset-white ${s.enableBenchmarkModels?"bg-emerald-500":"bg-stone-300"} disabled:opacity-50`,children:e.jsx("span",{className:`pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${s.enableBenchmarkModels?"translate-x-5":"translate-x-0"}`})})]}),s.enableAiParticipants&&s.enableBenchmarkModels&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"include-benchmarks-in-analysis",className:"block text-sm font-semibold uppercase tracking-wide text-slate-700",children:"Include Benchmarks in Analysis"}),e.jsx("p",{className:u("mt-1 text-xs",i.dark.textMuted),children:"Include benchmark model results in session analysis (clustering, synthesis). By default, benchmarks are stored separately."})]}),e.jsx("button",{id:"include-benchmarks-in-analysis",type:"button",role:"switch","aria-checked":s.includeBenchmarksInAnalysis,onClick:()=>a({includeBenchmarksInAnalysis:!s.includeBenchmarksInAnalysis}),disabled:d,className:`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 focus:ring-offset-white ${s.includeBenchmarksInAnalysis?"bg-emerald-500":"bg-stone-300"} disabled:opacity-50`,children:e.jsx("span",{className:`pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${s.includeBenchmarksInAnalysis?"translate-x-5":"translate-x-0"}`})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"ai-instructions",className:"block text-sm font-semibold uppercase tracking-wide text-slate-700",children:"Guidance for AI analysis"}),e.jsx("p",{className:u("mt-1 text-xs",i.dark.textMuted),children:"These instructions guide AI when generating synthesis reports and summaries. They are NOT shown to participants."}),e.jsx("textarea",{id:"ai-instructions",value:s.aiInstructions,onChange:t=>a({aiInstructions:t.target.value}),disabled:d,placeholder:"e.g., Focus on emotional patterns, Listen for cultural differences, Emphasize psychological safety themes...",rows:4,className:u("mt-2 w-full rounded-lg border bg-white px-4 py-3 placeholder-stone-400 focus:border-emerald-600 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary)})]})]}),e.jsxs("div",{className:u("rounded-lg border p-4 space-y-4",i.dark.borderSubtle,i.dark.surface),children:[e.jsxs("h3",{className:u("text-sm font-semibold uppercase tracking-wide font-serif flex items-center gap-2",i.dark.textPrimary),children:[e.jsx("span",{children:"🌐"})," Language Settings"]}),e.jsx(Ks,{label:"Response Languages",description:"Languages participants can use for their voice responses",selectedLanguages:s.acceptedResponseLanguages,onChange:t=>a({acceptedResponseLanguages:t}),disabled:d,filterByCapability:"stt"}),e.jsx(Ks,{label:"Insight Languages",description:"Languages to generate analysis and insights in",selectedLanguages:s.insightLanguages,onChange:t=>a({insightLanguages:t}),disabled:d,filterByCapability:"analysis"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:u("text-lg font-semibold font-serif flex items-center gap-2",i.dark.textPrimary),children:[e.jsx("span",{children:"🔐"})," Access & Visibility"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold uppercase tracking-wide text-slate-700 mb-2",children:"Who Can Join"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:u("flex cursor-pointer items-center gap-3 rounded-lg border bg-white p-3 hover:border-emerald-600/60",i.dark.borderSubtle),children:[e.jsx("input",{type:"radio",name:"allowOpenJoin",checked:!s.allowOpenJoin,onChange:()=>a({allowOpenJoin:!1}),disabled:d}),e.jsxs("div",{children:[e.jsx("p",{className:u("font-medium",i.dark.textPrimary),children:"Invite Only"}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Only people you explicitly invite can join"})]})]}),e.jsxs("label",{className:u("flex cursor-pointer items-center gap-3 rounded-lg border bg-white p-3 hover:border-emerald-600/60",i.dark.borderSubtle),children:[e.jsx("input",{type:"radio",name:"allowOpenJoin",checked:s.allowOpenJoin,onChange:()=>a({allowOpenJoin:!0}),disabled:d}),e.jsxs("div",{children:[e.jsx("p",{className:u("font-medium",i.dark.textPrimary),children:"Open Join"}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Anyone with the study link can join"})]})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold uppercase tracking-wide text-slate-700 mb-2",children:"Results Visibility"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:u("flex cursor-pointer items-center gap-3 rounded-lg border bg-white p-3 hover:border-emerald-600/60",i.dark.borderSubtle),children:[e.jsx("input",{type:"radio",name:"visibility",value:"PARTICIPANT",checked:s.visibility==="PARTICIPANT",onChange:()=>a({visibility:"PARTICIPANT"}),disabled:d}),e.jsxs("div",{children:[e.jsx("p",{className:u("font-medium",i.dark.textPrimary),children:"Participants Only"}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Only study participants can see daily synthesis"})]})]}),e.jsxs("label",{className:u("flex cursor-pointer items-center gap-3 rounded-lg border bg-white p-3 hover:border-emerald-600/60",i.dark.borderSubtle),children:[e.jsx("input",{type:"radio",name:"visibility",value:"PUBLIC",checked:s.visibility==="PUBLIC",onChange:()=>a({visibility:"PUBLIC"}),disabled:d}),e.jsxs("div",{children:[e.jsx("p",{className:u("font-medium",i.dark.textPrimary),children:"Public"}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Anyone can view the study's published results"})]})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:u("text-lg font-semibold font-serif flex items-center gap-2",i.dark.textPrimary),children:[e.jsx("span",{children:"🤖"})," Automation"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:u("flex cursor-pointer items-center gap-3 rounded-lg border bg-white p-4 hover:border-emerald-600/60",i.dark.borderSubtle),children:[e.jsx("input",{type:"checkbox",checked:s.autoPublishDailySynthesis,onChange:t=>a({autoPublishDailySynthesis:t.target.checked}),disabled:d,className:"h-4 w-4"}),e.jsxs("div",{children:[e.jsx("p",{className:u("font-medium",i.dark.textPrimary),children:"Auto-publish Daily Synthesis"}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Automatically publish synthesis when anal
10ysis completes"})]})]}),e.jsxs("label",{className:u("flex cursor-pointer items-center gap-3 rounded-lg border bg-white p-4 hover:border-emerald-600/60",i.dark.borderSubtle),children:[e.jsx("input",{type:"checkbox",checked:s.autoTriggerLongitudinal,onChange:t=>a({autoTriggerLongitudinal:t.target.checked}),disabled:d,className:"h-4 w-4"}),e.jsxs("div",{children:[e.jsx("p",{className:u("font-medium",i.dark.textPrimary),children:"Auto-trigger Longitudinal Analysis"}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Automatically run comparison when a word appears for the second+ time"})]})]}),e.jsxs("label",{className:u("flex cursor-pointer items-center gap-3 rounded-lg border bg-white p-4 hover:border-emerald-600/60",i.dark.borderSubtle),children:[e.jsx("input",{type:"checkbox",checked:s.enableVideoGeneration,onChange:t=>a({enableVideoGeneration:t.target.checked}),disabled:d,className:"h-4 w-4"}),e.jsxs("div",{children:[e.jsx("p",{className:u("font-medium",i.dark.textPrimary),children:"Auto-generate Video Episodes"}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Automatically generate a video episode when results are published"})]})]}),e.jsxs("label",{className:u("flex cursor-pointer items-center gap-3 rounded-lg border bg-white p-4 hover:border-emerald-600/60",i.dark.borderSubtle),children:[e.jsx("input",{type:"checkbox",checked:s.publishToYouTube,onChange:t=>a({publishToYouTube:t.target.checked}),disabled:d,className:"h-4 w-4"}),e.jsxs("div",{children:[e.jsx("p",{className:u("font-medium",i.dark.textPrimary),children:"Auto-publish Videos to YouTube"}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Automatically upload generated videos to YouTube when results are published"})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h3",{className:u("text-lg font-semibold font-serif flex items-center gap-2",i.dark.textPrimary),children:[e.jsx("span",{children:"🔄"})," Arc Reflections"]}),e.jsx("p",{className:u("text-sm",i.dark.textMuted),children:"Arc Reflections are retrospective checkpoints inserted into the study schedule. They provide cumulative analysis of group patterns, trends, and evolution — no voice recording, just insights looking back at everything so far."}),e.jsxs("label",{className:u("flex cursor-pointer items-center gap-3 rounded-lg border bg-white p-4 hover:border-emerald-600/40 transition-colors",i.dark.borderSubtle),children:[e.jsx("input",{type:"checkbox",checked:s.arcReflectionEnabled,onChange:t=>a({arcReflectionEnabled:t.target.checked}),disabled:d||c,className:"h-4 w-4 accent-emerald-500"}),e.jsxs("div",{children:[e.jsx("p",{className:u("font-medium",i.dark.textPrimary),children:"Enable Arc Reflections"}),e.jsx("p",{className:u("text-xs",i.dark.textMuted),children:"Insert retrospective analysis days into the study schedule"})]})]}),s.arcReflectionEnabled&&e.jsxs("div",{className:"space-y-4 rounded-lg border border-emerald-900/30 bg-emerald-950/10 p-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold uppercase tracking-wide text-emerald-700 mb-3",children:"Rhythm"}),e.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:ha(s.schedulingMode==="cycle"?"cycles":"days").map(t=>e.jsxs("button",{type:"button",onClick:()=>a({arcReflectionRhythm:t.value}),disabled:d||c,className:`flex flex-col items-center gap-1 rounded-lg border p-3 text-center transition disabled:opacity-50 ${s.arcReflectionRhythm===t.value?"border-emerald-500 bg-emerald-600/5 text-white":"border-stone-300 bg-white text-slate-700 hover:border-emerald-600/60"}`,children:[e.jsx("span",{className:"text-lg",children:t.icon}),e.jsx("span",{className:"text-sm font-medium",children:t.label}),e.jsx("span",{className:u("text-[10px]",i.dark.textMuted),children:t.description})]},t.value))})]}),s.arcReflectionRhythm==="custom"&&e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"arc-interval",className:"block text-xs font-medium text-slate-700 mb-1",children:["Interval (",s.schedulingMode==="cycle"?"cycles":"days",")"]}),e.jsx("input",{id:"arc-interval",type:"number",min:"2",max:s.totalDays,value:s.arcReflectionIntervalDays,onChange:t=>a({arcReflectionIntervalDays:Math.max(2,parseInt(t.target.value)||7)}),disabled:d||c,className:u("w-32 rounded-lg border bg-white px-3 py-2 focus:border-emerald-600 focus:outline-none disabled:opacity-50",i.dark.borderSubtle,i.dark.textPrimary)}
10),e.jsxs("p",{className:u("mt-1 text-xs",i.dark.textFaint),children:["Minimum 2 ",s.schedulingMode==="cycle"?"cycles":"days"," between arc reflections"]})]}),l.length>0&&e.jsxs("div",{className:"rounded-lg border border-emerald-900/40 bg-emerald-600/5 p-3",children:[e.jsxs("h4",{className:"text-xs font-semibold text-emerald-700 mb-2 font-serif",children:["Preview: ",l.length," arc reflection",l.length!==1?"s":""]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:l.map(t=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-lg border border-emerald-700/40 bg-emerald-600/5 px-2.5 py-0.5 text-xs text-emerald-800",children:["🔄 ",s.schedulingMode==="cycle"?"Cycle":"Day"," ",t]},t))}),e.jsxs("p",{className:u("mt-2 text-[10px]",i.dark.textMuted),children:["Arc reflections are generated on these ",s.schedulingMode==="cycle"?"cycles":"days"," alongside normal reflections."]})]})]})]}),C.length>0&&e.jsxs("div",{className:"rounded-lg border border-rose-900 bg-rose-50 p-4",children:[e.jsx("h4",{className:"text-sm font-semibold text-rose-700 mb-2 font-serif",children:"Please fix the following:"}),e.jsx("ul",{className:"text-xs text-rose-700 space-y-1",children:C.map((t,f)=>e.jsxs("li",{children:["• ",t]},f))})]}),e.jsxs("div",{className:"rounded-lg border border-amber-900/40 bg-amber-950/20 p-4",children:[e.jsx("h4",{className:"text-sm font-semibold text-amber-800 mb-2 font-serif",children:"🛡️ Ethical Guardrails"}),e.jsx("p",{className:"text-xs text-slate-700 leading-relaxed",children:"This format enforces strict observational principles:"}),e.jsxs("ul",{className:u("mt-2 text-xs space-y-1",i.dark.textMuted),children:[e.jsx("li",{children:"• No diagnosis or treatment recommendations"}),e.jsx("li",{children:"• No optimization or improvement feedback"}),e.jsx("li",{children:"• No behavioral nudging or identity reinforcement"}),e.jsx("li",{children:"• Dropout is valid data (not failure)"}),e.jsx("li",{children:"• Participants maintain sovereignty over their experience"})]})]})]})]})};function ga({sessionId:s}){const[a,d]=n.useState(!1),[c,h]=n.useState(null),[N,P]=n.useState(!1),[j,b]=n.useState(null),T=async()=>{d(!0),h(null),P(!1);try{b(await Gt(s))}catch(R){if(R?.response?.status===409)P(!0);else{const l=R?.response?.data?.message??(R instanceof Error?R.message:"Failed to read the baseline");h(l)}}finally{d(!1)}};return n.useEffect(()=>{T()},[s]),e.jsxs("div",{className:`mt-6 ${ws}`,children:[!j&&e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-serif text-lg text-emerald-900 dark:text-emerald-100",children:"Your questions, answered"}
10),e.jsx("p",{className:"mt-1 text-sm text-stone-600 dark:text-slate-400",children:"The questions this exercise was set up to explore, answered from the results, plus a read of how aligned the group currently is and what's worth bringing to your next meeting."})]}),!N&&e.jsx("button",{onClick:T,disabled:a,className:`shrink-0 ${Et}`,children:a?"Reading…":"Read the brief"})]}),N&&e.jsx("p",{className:"mt-3 text-sm text-stone-500 dark:text-slate-500",children:"Available once the session analysis has been generated."}),c&&e.jsx("div",{className:"mt-3 rounded-md border border-amber-600/40 dark:border-amber-700 bg-amber-500/10 dark:bg-amber-900/20 px-4 py-2 text-sm text-amber-800 dark:text-amber-200",children:c}),j&&e.jsxs("div",{className:"mt-4",children:[e.jsx(Jt,{rec:j}),e.jsx("div",{className:"mt-4 border-t border-stone-200 dark:border-slate-800 pt-2",children:e.jsx(Ut,{sessionId:s,targetId:s,insightType:"resultsReading",itemLabel:"Your questions, answered"})})]})]})}function tt({sessionId:s,adjustedSetup:a}){const[d,c]=n.useState(!1),[h,N]=n.useState("meeting"),[P,j]=n.useState(""),[b,T]=n.useState(""),[R,m]=n.useState(""),[l,C]=n.useState(!1),[t,f]=n.useState(null),[x,E]=n.useState(null),[y,U]=n.useState(null),[I,w]=n.useState(!1),L=h==="now"||P!=="",v=async()=>{C(!0),f(null),E(null);try{const g=await ra(h==="now"?{sessionId:s,startNow:!0,postClosesAt:b?new Date(b).toISOString():null,eventLabel:R.trim()||void 0,adjustedSetup:a}:{sessionId:s,eventDate:new Date(P).toISOString(),eventLabel:R.trim()||void 0,adjustedSetup:a});U(g)}catch(g){const D=la(g);if(D)E(D);else{const B=g?.response?.data?.message??(g instanceof Error?g.message:"Failed to schedule the next exercise");f(B)}}finally{C(!1)}};return y?e.jsxs("div",{className:"mt-6 rounded-lg border border-emerald-700/50 bg-emerald-950/20 p-5",children:[e.jsx("h3",{className:"font-serif text-lg text-emerald-900 dark:text-emerald-100",children:y.postClosesAt===null&&new Date(y.postOpensAt).getTime()<=Date.now()?"Follow-up open now":"Next exercise scheduled"}),e.jsxs("p",{className:"mt-2 text-sm text-slate-300",children:[new Date(y.postOpensAt).getTime()<=Date.now()?"This session is closed to new responses and is now the baseline.":"This session is now the baseline."," ",new Date(y.postOpensAt).getTime()<=Date.now()?y.postClosesAt===null?e.jsx(e.Fragment,{children:"The follow-up is open now and stays open until you close it; then you'll see what moved."}):e.jsxs(e.Fragment,{children:["The follow-up is open now and closes"," ",new Date(y.postClosesAt).toLocaleDateString(),"; then you'll see what moved."]}):e.jsxs(e.Fragment,{children:["The follow-up exercise opens ",new Date(y.postOpensAt).toLocaleDateString(),y.postClosesAt&&e.jsxs(e.Fragment,{children:[" and closes ",new Date(y.postClosesAt).toLocaleDateString()]}),". After it runs, you'll see what moved."]})]}),e.jsxs("p",{className:"mt-2 text-sm text-slate-400",children:[y.participantsCarried>0?`${y.participantsCarried} ${y.participantsCarried===1?"person":"people"} carried over to the follow-up.`:"No participants with an email to carry over yet.",y.invitesSent>0&&` ${y.invitesSent} ${y.invitesSent===1?"invite":"invites"} sent just now.`,y.participantsWithoutEmail>0&&` ${y.participantsWithoutEmail} participant${y.participantsWithoutEmail===1?"":"s"} had no email; add them on the programme page.`]}),e.jsx("a",{href:`/host/programmes/${y.programmeId}`,className:"mt-3 inline-block text-sm text-emerald-700 dark:text-emerald-300 underline hover:text-emerald-800 dark:hover:text-emerald-200",children:"View the programme →"})]}):e.jsxs("div",{className:`mt-6 ${ws}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-serif text-lg text-emerald-900 dark:text-emerald-100",children:"Want to see if this moves?"}),e.jsx("p",{className:"mt-1 text-sm text-slate-400",children:"Run the same exercise again: now, or around your next meeting or workshop. This session becomes the baseline, and the follow-up shows how the group's thinking shifted."})]}),!d&&e.jsx("button",{onClick:()=>c(!0),className:`shrink-0 ${Se}`,children:"Schedule next exercise"})]}),d&&e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("span",{className:"mb-2 block text-sm font-medium text-slate-300",children:"When should the follow-up run?"}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs("button",{type:"button",onClick:()=>{N("meeting"),w(!1)},className:`flex-1 rounded-lg border px-4 py-2 text-left text-sm ${h==="meeting"?"border-emerald-500 bg-emerald-50 dark:bg-emerald-950/30 text-emerald-900 dark:text-emerald-100":"border-slate-700 bg-slate-800/40 text-slate-300 hover:border-slate-500"}`,children:[e.jsx("span",{className:"block font-medium",children:"Around a future meeting"}),e.jsx("span",{className:"mt-0.5 block text-xs text-slate-400",children:"Runs just after your workshop"})]}),e.jsxs("button",{type:"button",onClick:()=>N("now"),className:`flex-1 rounded-lg border px-4 py-2 text-left text-sm ${h==="now"?"border-emerald-500 bg-emerald-50 dark:bg-emerald-950/30 text-emerald-900 dark:text-emerald-100":"border-slate-700 bg-slate-800/40 text-slate-300 hover:border-slate-500"}`,children:[e.jsx("span",{className:"block font-medium",children:"Start now"}),e.jsx("span",{className:"mt-0.5 block text-xs text-slate-400",children:"Opens immediately, invites go out now"})]})]})]}),h==="meeting"?e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-slate-300",children:"When is the meeting or workshop this builds toward?"}),e.jsxs("p",{className:"mb-2 text-xs text-slate-500",children:["This is your real-world event, not when the exercise runs. The follow-up is scheduled",e.jsx("strong",{className:"text-slate-400",children:" after"}
10)," it (opens the day after, closes two days after) so it measures what the meeting moved."]}),e.jsx("input",{type:"date",value:P,onChange:g=>j(g.target.value),className:"rounded-lg border border-slate-700 bg-slate-800/50 px-4 py-2 text-slate-100 focus:border-emerald-500 focus:outline-none"})]}):e.jsxs("div",{children:[e.jsxs("label",{className:"mb-1 block text-sm font-medium text-slate-300",children:["Close the follow-up on ",e.jsx("span",{className:"text-slate-500",children:"(optional)"})]}),e.jsx("p",{className:"mb-2 text-xs text-slate-500",children:"The follow-up opens immediately and carried-over participants are invited now. Leave this empty to keep it open until you close it by hand, or pick a date to close it automatically."}),e.jsx("input",{type:"date",value:b,onChange:g=>T(g.target.value),className:"rounded-lg border border-slate-700 bg-slate-800/50 px-4 py-2 text-slate-100 focus:border-emerald-500 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"mb-1 block text-sm font-medium text-slate-300",children:["What is it? ",e.jsx("span",{className:"text-slate-500",children:"(optional)"})]}),e.jsx("input",{type:"text",value:R,onChange:g=>m(g.target.value),maxLength:120,placeholder:"e.g. Q3 strategy day",className:"w-full rounded-lg border border-slate-700 bg-slate-800/50 px-4 py-2 text-slate-100 placeholder-slate-500 focus:border-emerald-500 focus:outline-none"})]}),t&&e.jsx("div",{className:"rounded-md border border-rose-500/40 bg-rose-950/30 px-4 py-2 text-sm text-rose-200",children:t}),x&&e.jsx(na,{options:x}),I&&h==="now"?e.jsxs("div",{className:"rounded-lg border border-amber-600/50 bg-amber-950/20 p-4",children:[e.jsxs("p",{className:"text-sm text-amber-100",children:["Starting now ",e.jsx("strong",{children:"closes the current exercise"}),"; no new responses will be accepted, and it becomes the baseline. Invites to the follow-up go out immediately."]}),e.jsxs("div",{className:"mt-3 flex gap-3",children:[e.jsx("button",{onClick:()=>w(!1),disabled:l,className:Gs,children:"Back"}),e.jsx("button",{onClick:v,disabled:l,className:Se,children:l?"Starting…":"Close current & start follow-up"})]})]}):e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>c(!1),disabled:l,className:Gs,children:"Cancel"}),e.jsx("button",{onClick:()=>h==="now"?w(!0):void v(),disabled:l||!L,className:Se,children:l?"Scheduling…":h==="now"?"Start now":"Schedule"})]})]})]})}function fa({sessionId:s,openRequested:a=0}){const[d,c]=n.useState("IDLE"),[h,N]=n.useState(null),[P,j]=n.useState([]),[b,T]=n.useState(null),[R,m]=n.useState(null),[l,C]=n.useState(!1),[t,f]=n.useState(!1),x=h?[h.opening_question,...h.followup_questions]:[];n.useEffect(()=>{a>0&&d==="IDLE"&&!h&&!t&&y()},[a]);const E=P[0]?.trim().length>0,y=async()=>{m(null),C(!1),c("LOADING_QUESTIONS");try{const I=await Kt(s);N(I),j([I.opening_question,...I.followup_questions].map(()=>"")),c("CONVO")}catch(I){if(I?.response?.status===409){C(!0),c("IDLE");return}m(I?.response?.data?.message??(I instanceof Error?I.message:"Failed to open the conversation")),c("IDLE")}},U=async()=>{if(h){m(null),c("DRAFTING");try{const I=x.map((L,v)=>({question:L,answer:(P[v]??"").trim()})).filter(L=>L.answer.length>0),w=await qt(s,I);T(w),c("REVIEW")}catch(I){m(I?.response?.data?.message??(I instanceof Error?I.message:"Failed to draft the follow-up plan")),c("CONVO")}}};if(t)return e.jsxs("div",{children:[e.jsx(tt,{sessionId:s}),e.jsx("button",{type:"button",onClick:()=>f(!1),className:`mt-2 ${ze}`,children:"← Back to talking about the results first"})]});if(d==="SCHEDULE"&&b){const I={title:b.title,description:b.description||void 0,customAiInstructions:b.custom_ai_instructions||void 0,topicWords:b.recommended_words.map(w=>w.trim()).filter(Boolean),topicKinds:b.recommended_kinds,keyQuestions:b.key_questions.map(w=>w.trim()).filter(Boolean)};return e.jsxs("div",{children:[e.jsxs("div",{className:"mt-6 rounded-lg border border-emerald-700/40 bg-emerald-950/10 px-5 py-3 text-sm text-slate-700",children:["The follow-up runs with the adjusted plan: ",e.jsx("span",{className:"text-emerald-800 dark:text-emerald-200",children:b.title})," ·"," ",I.topicWords.join(", "),e.jsx("button",{type:"button",onClick:()=>c("REVIEW"),className:`ml-3 ${ze}`,children:"← Edit the plan"})]}),e.jsx(tt,{sessionId:s,adjustedSetup:I})]})}return e.jsxs("div",{className:`mt-6 ${ws}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-serif text-lg text-emerald-900 dark:text-emerald-100",children:"Wanna talk about the results?"}),e.jsx("p",{className:"mt-1 text-sm text-stone-600",children:"Say 
10what these results changed for you; the AI shapes the follow-up exercise from the findings and your take, instead of blindly repeating the first one."})]}),d==="IDLE"&&e.jsx("button",{onClick:y,className:`shrink-0 ${Se}`,children:"Let's talk"})]}),l&&e.jsx("p",{className:"mt-3 text-sm text-stone-500",children:"Available once the session analysis has been generated."}),R&&e.jsx("div",{className:"mt-3 rounded-md border border-rose-300 bg-rose-50 px-4 py-2 text-sm text-rose-700",children:R}),d==="LOADING_QUESTIONS"&&e.jsx("div",{className:"mt-4 flex min-h-[96px] items-center rounded-lg border border-stone-200 bg-white px-4",children:e.jsx("p",{className:"animate-pulse text-sm text-stone-600",children:"Reading the results…"})}),(d==="CONVO"||d==="DRAFTING")&&h&&e.jsxs("div",{className:"mt-4 space-y-5",children:[x.map((I,w)=>e.jsxs("div",{children:[e.jsxs("label",{className:"mb-2 block text-sm font-medium text-slate-700",children:[I,w>0&&e.jsx("span",{className:"ml-2 text-xs font-normal text-stone-500",children:"(optional)"})]}),e.jsx("textarea",{value:P[w]??"",onChange:L=>j(v=>v.map((g,D)=>D===w?L.target.value:g)),rows:w===0?4:2,placeholder:w===0?"Type freely, or speak it.":void 0,className:"w-full rounded-lg border border-stone-300 bg-white px-4 py-3 text-slate-900 placeholder-stone-400 focus:border-emerald-600 focus:outline-none focus:ring-1 focus:ring-emerald-500"}),e.jsx("div",{className:"mt-1.5 flex justify-end",children:e.jsx(sa,{onTranscript:L=>j(v=>v.map((g,D)=>D===w?g.trim()?`${g} ${L}`:L:g))})})]},I)),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:U,disabled:!E||d==="DRAFTING",className:Se,children:d==="DRAFTING"?"Drafting the follow-up…":"Draft the follow-up"}),e.jsx("button",{type:"button",onClick:()=>f(!0),className:ze,children:"Skip and schedule the same exercise as-is"})]})]}),d==="REVIEW"&&b&&e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-emerald-700/40 bg-emerald-950/10 p-4 text-sm text-slate-700",children:b.adjustment_summary}),(b.word_changes.dropped.length>0||b.word_changes.added.length>0)&&e.jsxs("div",{className:"space-y-1 text-sm",children:[b.word_changes.dropped.map(I=>e.jsxs("p",{className:"text-stone-600",children:[e.jsx("span",{className:"text-rose-300/90 line-through",children:I.word}),": ",I.reason]},`d-${I.word}`)),b.word_changes.added.map(I=>e.jsxs("p",{className:"text-stone-600",children:[e.jsxs("span",{className:"text-emerald-700 dark:text-emerald-300",children:["+ ",I.word]}),": ",I.reason]},`a-${I.word}`))]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-slate-700",children:"Title"}),e.jsx("input",{type:"text",value:b.title,maxLength:60,onChange:I=>T({...b,title:I.target.value}),className:"w-full rounded-lg border border-stone-300 bg-white px-4 py-3 text-slate-900 focus:border-emerald-600 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-slate-700",children:"Description"}),e.jsx("textarea",{value:b.description,rows:2,onChange:I=>T({...b,description:I.target.value}),className:"w-full rounded-lg border border-stone-300 bg-white px-4 py-3 text-slate-900 focus:border-emerald-600 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-slate-700",children:"AI instructions"}),e.jsx("textarea",{value:b.custom_ai_instructions,rows:3,onChange:I=>T({...b,custom_ai_instructions:I.target.value}),className:"w-full rounded-lg border border-stone-300 bg-white px-4 py-3 text-slate-900 focus:border-emerald-600 focus:outline-none"})]}),e.jsx(ta,{label:"Topic words for the follow-up",words:b.recommended_words,kinds:b.recommended_kinds??[],onChange:(I,w)=>T({...b,recommended_words:I,recommended_kinds:w}),maxWords:6}),e.jsx(aa,{suggestions:b.suggested_words,currentWords:b.recommended_words,onAdd:I=>T({...b,recommended_words:[...b.recommended_words,I],recommended_kinds:[...b.recommended_words.map((w,L)=>b.recommended_kinds?.[L]??"general"),"general"]})}),e.jsxs("div",{children:[e.jsxs("label",{className:"mb-1 block text-sm font-medium text-slate-700",children:["Key questions ",e.jsx("span",{className:"text-stone-500",children:"(one per line)"})]}),e.jsx("p",{className:"mb-2 text-xs text-stone-500",children:"What should the follow-up answer? Each gets a direct answer in 'Your questions, answered'."}),e.jsx("textarea",{value:b.key_questions.join(`
11`),rows:4,onChange:I=>T({...b,key_questions:I.target.value.split(`
12`)}),className:"w-full rounded-lg border border-stone-300 bg-white px-4 py-3 text-slate-900 focus:border-emerald-600 focus:outline-none"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>c("SCHEDULE"),disabled:b.recommended_words.filter(I=>I.trim()).length===0,className:Se,children:"Looks right, schedule it"}),e.jsx("button",{type:"button",onClick:()=>c("CONVO"),className:ze,children:"← Back to the conversation"})]})]})]})}const at={ready:"bg-emerald-400",attention:"bg-amber-400",locked:"bg-stone-300 dark:bg-slate-600"};function rt({items:s,activeId:a,onSelect:d}){return e.jsxs(e.Fragment,{children:[e.jsx("nav",{className:"hidden md:flex sticky top-0 h-screen w-56 shrink-0 flex-col gap-1 border-r border-stone-200 dark:border-slate-800/70 bg-white/90 dark:bg-slate-950/80 p-3 pt-4 overflow-y-auto",children:s.map(c=>{const h=c.id===a,N=c.locked;return e.jsxs("div",{children:[c.separator&&e.jsx("div",{className:"my-2 border-t border-stone-200 dark:border-slate-800/60"}),e.jsxs("button",{type:"button",onClick:()=>!N&&d(c.id),disabled:N,className:`w-full flex items-start gap-3 rounded-lg px-3 py-2.5 text-left transition ${h?"bg-stone-100 dar
12k:bg-slate-800/80 text-slate-900 dark:text-white":N?"text-stone-500 dark:text-slate-600 cursor-not-allowed":"text-stone-600 dark:text-slate-400 hover:bg-stone-100 dark:hover:bg-stone-100 hover:text-slate-900 dark:hover:text-slate-900"}`,children:[e.jsx("span",{className:"text-base leading-none mt-0.5",children:c.icon}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:c.label}),e.jsx("span",{className:`h-2 w-2 shrink-0 rounded-full ${at[c.status]}`})]}),c.statusText&&e.jsx("p",{className:`mt-0.5 text-[11px] truncate ${N?"text-stone-600 dark:text-slate-700":"text-stone-500 dark:text-slate-500"}`,children:c.statusText})]})]})]},c.id)})}),e.jsx("div",{className:"md:hidden sticky top-0 z-10 flex gap-2 overflow-x-auto border-b border-stone-200 dark:border-slate-800/70 bg-stone-50/90 dark:bg-slate-950/90 px-3 py-2 backdrop-blur scrollbar-hide",children:s.map(c=>{const h=c.id===a,N=c.locked;return e.jsxs("button",{type:"button",onClick:()=>!N&&d(c.id),disabled:N,className:`flex shrink-0 items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-medium transition ${h?"bg-stone-300 dark:bg-slate-700 text-slate-900 dark:text-white":N?"text-stone-500 dark:text-slate-600 cursor-not-allowed":"text-stone-600 dar
12k:text-slate-400 hover:text-slate-900 dark:hover:text-slate-900"}`,children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${at[c.status]}`}),e.jsx("span",{children:c.label})]},c.id)})})]})}const nt=({title:s,description:a,aiInstructions:d,formatPurpose:c,formatSystemPrompt:h,isLoading:N=!1,onChange:P})=>e.jsx("section",{className:"rounded-2xl border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-900/60 p-6 shadow-xl",children:e.jsxs("div",{className:"space-y-6",children:[c&&e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-700 bg-white/85 dark:bg-slate-900/40 p-4",children:[e.jsx("h3",{className:"mb-2 text-sm font-semibold text-slate-800 dark:text-slate-200",children:"Format Purpose"}),e.jsx("p",{className:"text-xs leading-relaxed text-stone-700 dark:text-slate-300",children:c}),h&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"mt-3 mb-2 text-xs font-semibold uppercase tracking-wide text-stone-600 dark:text-slate-400",children:"AI Guidance"}),e.jsx("p",{className:"text-xs italic leading-relaxed text-stone-600 dar
12k:text-slate-400",children:h})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"session-title",className:"block text-sm font-semibold uppercase tracking-wide text-stone-700 dark:text-slate-300",children:"Session Title"}),e.jsx("input",{id:"session-title",type:"text",value:s,onChange:j=>P({title:j.target.value}),disabled:N,placeholder:"e.g., Weekly Retrospective",className:"mt-3 w-full rounded-lg border border-stone-200 dark:border-slate-700 bg-white dark:bg-slate-950/60 px-4 py-2 text-slate-900 dark:text-slate-100 placeholder-stone-400 dark:placeholder-slate-500 focus:border-emerald-600 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"session-description",className:"block text-sm font-semibold uppercase tracking-wide text-stone-700 dark:text-slate-300",children:["Description"," ",e.jsx("span",{className:"font-normal text-stone-500 dark:text-slate-500",children:"(optional)"})]}),e.jsx("textarea",{id:"session-description",value:a,onChange:j=>P({description:j.target.value}),disabled:N,placeholder:"What's this session about?",rows:3,className:"mt-3 w-full rounded-lg border border-stone-200 dark:border-slate-700 bg-white dark:bg-slate-950/60 px-4 py-2 text-slate-900 dark:text-slate-100 placeholder-stone-400 dark:placeholder-slate-500 focus:border-emerald-600 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"ai-instructions",className:"block text-sm font-semibold uppercase tracking-wide text-stone-700 dark:text-slate-300",children:["Custom AI Instructions"," ",e.jsx("span",{className:"font-normal text-stone-500 dark:text-slate-500",children:"(optional)"})]}),e.jsx("textarea",{id:"ai-instructions",value:d,onChange:j=>P({aiInstructions:j.target.value}),disabled:N,placeholder:"e.g., Focus on innovation barriers, Listen for cultural patterns, Emphasize psychological safety themes...",rows:3,className:"mt-3 w-full rounded-lg border border-stone-200 dark:border-slate-700 bg-white dark:bg-slate-950/60 px-4 py-2 text-slate-900 dark:text-slate-100 placeholder-stone-400 dark:placeholder-slate-500 focus:border-emerald-600 focus:outline-none"}
12),e.jsx("p",{className:"mt-1 text-xs text-stone-600 dark:text-slate-400",children:"Provide specific guidance for AI analysis. These instructions will be used when generating per-response feedback, synthesis reports, and summaries."})]})]})}),Me=s=>s.trim().endsWith("™"),ya=({questions:s,onQuestionsChange:a,isLoading:d=!1,canonicalPromptTemplate:c=Ye})=>{const h=n.useMemo(()=>{const m=c.trim()||Ye,l=m.indexOf("[topic]");if(l===-1)return{prefix:m,suffix:""};const C=m.slice(0,l).trimEnd(),t=m.slice(l+7).trimStart();return{prefix:C,suffix:t}},[c]),N=n.useCallback((m,l)=>{const C=s.map(t=>t.id===m?{...t,topicWord:l}:t);a(C)},[s,a]),P=n.useCallback(m=>{const l=s.findIndex(t=>t.id===m);if(l<=0)return;const C=[...s];[C[l],C[l-1]]=[C[l-1],C[l]],C.forEach((t,f)=>{t.orderIndex=f}),a(C)},[s,a]),j=n.useCallback(m=>{const l=s.findIndex(t=>t.id===m);if(l>=s.length-1)return;const C=[...s];[C[l],C[l+1]]=[C[l+1],C[l]],C.forEach((t,f)=>{t.orderIndex=f}),a(C)},[s,a]),b=n.useCallback(m=>{const l=s.filter(C=>C.id!==m);l.forEach((C,t)=>{C.orderIndex=t}),a(l)},[s,a]),T=n.useCallback(m=>{const l=s.map(C=>{if(C.id!==m)return C;const t=C.topicWord.trim();return{...C,topicWord:Me(t)?t.slice(0,-1).trim():t&&`${t}™`}});a(l)},[s,a]),R=n.useCallback(()=>{const m={id:`question-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,topicWord:"",orderIndex:s.length};a([...s,m])},[s,a]);return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("label",{className:"block text-sm font-semibold uppercase tracking-wide text-slate-300",children:["Questions (",s.length,")"]})}),s.length===0?e.jsx("div",{className:u("rounded-lg border bg-slate-950/60 p-6 text-center",i.dark.borderSubtle),children:e.jsx("p",{className:u("text-sm",i.dark.textMuted),children:"No questions yet. Add one to get started."})}):e.jsx("div",{className:"space-y-3",children:s.map((m,l)=>e.jsx("div",{className:u("rounded-lg border bg-slate-950/60 p-4 hover:border-slate-600",i.dark.borderSubtle),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-start gap-3",children:e.jsxs("div",{className:"flex-1",children:[e.jsxs("p",{className:u("text-xs uppercase tracking-wide mb-2",i.dark.textFaint),children:["Question ",l+1," of ",s.length]}),e.jsxs("div",{className:u("text-sm",i.dark.textPrimary),children:[e.jsx("span",{children:h.prefix}),e.jsx("span",{className:"font-mono font-semibold text-emerald-300 mx-1",children:m.topicWord||"___________"}),e.jsx("span",{children:h.suffix})]})]})}),e.jsxs("div",{children:[e.jsx("label",{className:u("block text-xs font-medium uppercase tracking-wide mb-2",i.dark.textMuted),children:"Topic Word"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:m.topicWord,onChange:C=>N(m.id,C.target.value),disabled:d,placeholder:"e.g., leadership, innovation, change",className:u("w-full rounded-lg border bg-slate-900/60 px-3 py-2 text-sm placeholder-slate-500 focus:border-emerald-500 focus:outline-none",i.dark.borderSubtle,i.dark.textPrimary)}),e.jsx("button",{type:"button",onClick:()=>T(m.id),disabled:d||!m.topicWord.trim(),title:Me(m.topicWord)?"Marked as a brand or named entity. Click to unmark.":"Mark as a brand or named entity (shown with ™)","aria-pressed":Me(m.topicWord),className:u("shrink-0 rounded-lg border px-3 py-2 text-sm font-semibold transition disabled:cursor-not-allowed disabled:opacity-50",Me(m.topicWord)?"border-emerald-500 bg-emerald-600/20 text-emerald-300":u("text-slate-400 hover:border-slate-500 hover:text-slate-200",i.dark.borderSubtle,i.dark.surface)),children:"™"})]}),e.jsx("p",{className:u("mt-1 text-xs",i.dark.textFaint),children:Me(m.topicWord)?"Brand or named entity: participants see the word with a ™ marker.":"A brand or product name? Mark it with ™ so the AI reads it as a named entity."})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:()=>P(m.id),disabled:d||l===0,title:"Move up",className:u("rounded-lg border px-3 py-1 text-xs font-medium text-slate-300 transition hover:border-slate-500 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50",i.dark.borderSubtle,i.dark.surface),children:"↑"}),e.jsx("button",{type:"button",onClick:()=>j(m.id),disabled:d||l===s.length-1,title:"Move down",className:u("rounded-lg border px-3 py-1 text-xs font-medium text-slate-300 transition hover:border-slate-500 hover:text-slate-100 disabled:cursor-not-allowed disabled:opacity-50",i.dark.borderSubtle,i.dark.surface),children:"↓"}),e.jsx("button",{type:"button",onClick:()=>b(m.id),disabled:d,title:"Delete question",className:"rounded-lg border border-rose-700/50 bg-rose-950/40 px-3 py-1 text-xs font-medium text-rose-300 transition hover:border-rose-600 hover:bg-rose-950/60",children:"Delete"})]})]})},m.id))}),e.jsx("button",{type:"button",onClick:R,disabled:d,className:u("w-full rounded-lg border border-dashed bg-slate-950/40 px-4 py-3 text-sm font-medium text-slate-300 transition hover:border-emerald-500 hover:bg-slate-950/60 hover:text-emerald-300 disabled:cursor-not-allowed disabled:opacity-50",i.dark.borderSubtle),children:"+ Add Question"})]})},lt=s=>s.split(`
13`).map((a,d)=>({id:`q-${d}-${Math.random().toString(36).slice(2,9)}`,topicWord:a.trim(),orderIndex:d})).filter(a=>a.topicWord.length>
130),ka=s=>s.map(a=>a.topicWord).join(`
14`),it=({questionInput:s,isTopicListFormat:a,canonicalPromptTemplate:d,isLoading:c=!1,readOnly:h=!1,onChange:N,onCreateSession:P,createButtonDisabled:j,createButtonLoading:b,createError:T,onSaveTopics:R,saveDirty:m=!1,saveLoading:l=!1,saveError:C=null,savedRecently:t=!1})=>{const[f,x]=n.useState([]),E=n.useRef("");n.useEffect(()=>{a&&!f.length&&s?(E.current=s,x(lt(s))):a||x([])},[a]),n.useEffect(()=>{a&&s&&E.current!==s&&(E.current=s,x(lt(s)))},[s,a]);const y=w=>{E.current=w,N(w)},U=w=>{x(w);const L=ka(w);E.current=L,N(L)},I=n.useMemo(()=>s.split(`
15`).filter(w=>w.trim()).length,[s]);return e.jsxs("section",{className:"rounded-2xl border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-900/60 p-6 shadow-xl",children:[e.jsxs("h3",{className:"mb-4 text-sm font-semibold uppercase tracking-wide text-stone-700 dark:text-slate-300",children:["Session Topics (",I,")"]}),h&&e.jsxs("div",{className:"mb-4 flex items-center gap-2 rounded-lg border border-stone-200 dark:border-slate-700 bg-stone-100 dark:bg-slate-800/40 px-4 py-2.5",children:[e.jsx("span",{className:"text-sm",children:"🔒"}
15),e.jsx("p",{className:"text-xs text-stone-600 dark:text-slate-400",children:"Topics are locked while the session is live."})]}),a?e.jsx(ya,{questions:f,onQuestionsChange:U,isLoading:c||h,canonicalPromptTemplate:d}):e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 flex items-center justify-between",children:e.jsx("span",{className:"text-xs text-stone-500 dark:text-slate-500",children:"One question per line"})}),e.jsx("textarea",{id:"session-topics-input",value:s,onChange:w=>y(w.target.value),disabled:c||h,placeholder:`What stood out?
16What would you change?
17What's next?`,rows:6,className:"w-full rounded-lg border border-stone-200 dark:border-slate-700 bg-white dark:bg-slate-950/60 px-4 py-2 font-mono text-sm text-slate-900 dark:text-slate-100 placeholder-stone-400 dark:placeholder-slate-500 focus:border-emerald-500 focus:outline-none disabled:opacity-60"})]}),R&&!h&&e.jsxs("div",{className:"mt-6 space-y-3 border-t border-stone-200 dark:border-slate-800/50 pt-6",children:[C&&e.jsx("div",{className:"rounded-lg border border-rose-900 bg-rose-950/30 p-3 text-sm text-rose-400",children:C}),m&&!l&&e.jsx("p",{className:"text-xs text-amber-400",children:"Unsaved changes. Participants still see the previous topics until you save."}),e.jsx("button",{type:"button",onClick:R,disabled:l||!m,className:"min-h-[44px] w-full rounded-lg bg-emerald-600 px-6 py-3 text-base font-medium text-white transition hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-stone-300 dark:disabled:bg-slate-700 disabled:text-stone-600 dar
17k:text-slate-400",children:l?"Saving…":m?"Save topics":t?"Topics saved ✓":"Save topics"})]}),P&&I>0&&!h&&e.jsxs("div",{className:"mt-6 space-y-3 border-t border-stone-200 dark:border-slate-800/50 pt-6",children:[T&&e.jsx("div",{className:"rounded-lg border border-rose-900 bg-rose-950/30 p-3 text-sm text-rose-400",children:T}),e.jsx("button",{type:"button",onClick:P,disabled:j||b,className:"min-h-[44px] w-full rounded-lg bg-emerald-600 px-6 py-3 text-base font-medium text-white transition hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-stone-300 dark:disabled:bg-slate-700 disabled:text-stone-600 dark:text-slate-400",children:b?"Creating...":"Create Session & Invite Participants"})]})]})},va={en:"English",fi:"Finnish",es:"Spanish",de:"German",fr:"French",sv:"Swedish",nl:"Dutch",it:"Italian",pt:"Portuguese",pl:"Polish",ja:"Japanese",ko:"Korean",zh:"Chinese",ar:"Arabic",ru:"Russian",hi:"Hindi"},ja=({languageCode:s,confidence:a,size:d="sm",showConfidence:c=!1})=>{const[h,N]=n.useState(null);if(n.useEffect(()=>{s&&Wt(s).then(N).catch(()=>{N(null)})},[s]),!s)return null;const P=h?.name||va[s]||s.toUpperCase(),j=h?.nativeName,b=j&&j!==P?`${P} (${j})${c&&a?` - ${Math.round(a*100)}% confidence`:""}`:`${P}${c&&a?` - ${Math.round(a*100)}% confidence`:""}`,T=d==="sm"?"px-1.5 py-0.5 text-[10px]":"px-2 py-1 text-xs";return e.jsxs("span",{title:b,className:`inline-flex items-center gap-1 ${T} rounded bg-slate-700/50 text-slate-300 font-mono uppercase`,children:[e.jsx("span",{className:"opacity-60",children:"🌐"}),s,c&&a&&e.jsxs("span",{className:"text-slate-400 font-normal",children:[Math.round(a*100),"%"]})]})},Na=({sessionId:s})=>{const[a,d]=n.useState([]),[c,h]=n.useState(!0),[N,P]=n.useState(!1),[j,b]=n.useState(null),[T,R]=n.useState("all"),[m,l]=n.useState(null),[C,t]=n.useState(null);n.useEffect(()=>{f()},[s]);const f=async v=>{try{v?.silent??!1?P(!0):h(!0),b(null);const D=await je.get(`/api/sessions/${s}/per-response-insights/host`);d(D.data)}catch(g){console.error("Failed to load responses:",g),b(g instanceof Error?g.message:"Failed to load responses")}finally{h(!1),P(!1)}},x=async(v,g)=>{try{l(v),await Yt({responseId:v,decision:g,notes:`Host ${g==="ACCEPTED"?"accepted":"rejected"} via relevance review`}),await f({silent:!0})}catch(D){console.error("Failed to submit decision:",D),alert("Failed to update response status. Please try again.")}finally{l(null)}},E=async v=>{try{t(v),await je.post(`/api/sessions/${s}/responses/${v}/retry-analysis`),await f({silent:!0})}catch(g){console.error("Failed to retry analysis:",g),alert("Failed to retry analysis. Please try again.")}finally{t(null)}},U=a.filter(v=>{switch(T){case"flagged":return v.feedbackDecision==="REJECTED"||v.feedbackDecision==="ACCEPTED"?!1:v.relevanceCheck&&(!v.relevanceCheck.relevant||v.relevanceCheck.confidence<.7);case"off-topic":return v.feedbackDecision==="REJECTED";case"relevant":return v.feedbackDecision==="ACCEPTED"?!0:v.feedbackDecision==="REJECTED"?!1:v.relevanceCheck?.relevant&&v.relevanceCheck.confidence>=.7;default:return!0}}).reduce((v,g)=>{const D=v.find(B=>B.questionId===g.questionId);return D?D.responses.push(g):v.push({questionId:g.questionId,questionText:g.questionText,orderIndex:g.orderIndex,responses:[g]}),v},[]);U.sort((v,g)=>v.orderIndex-g.orderIndex);const I=v=>{if(v.feedbackDecision==="ACCEPTED")return{icon:"✅",label:"Accepted",color:"text-green-400",iconColor:""};if(v.feedbackDecision==="REJECTED")return{icon:"❌",label:"Rejected",color:"text-red-400",iconColor:""};const g=v.relevanceCheck,D=!!(g&&(!g.relevant||g.confidence<.7));return T==="flagged"&&D?{icon:"●",label:"Flagged for review",color:"text-orange-400",iconColor:"text-orange-400"}:g?D?{icon:"●",label:"Flagged for review",color:"text-orange-400",iconColor:"text-orange-400"}:g.confidence>=.8?{icon:"🟢",label:"Relevant",color:"text-green-400",iconColor:""}:g.confidence>=.5?{icon:"🟡",label:"Likely Relevant",color:"text-yellow-400",iconColor:""}:{icon:"●",label:"Flagged for review",color:"text-orange-400",iconColor:"text-orange-400"}:{icon:"⚪",label:"Not checked",color:"text-stone-500 dark:text-slate-500",iconColor:""}},w={total:a.length,analyzed:a.filter(v=>!!v.analysis).length,flagged:a.filter(v=>v.feedbackDecision==="REJECTED"||v.feedbackDecision==="ACCEPTED"?!1:v.relevanceCheck&&(!v.relevanceCheck.relevant||v.relevanceCheck.confidence<.7)).length,relevant:a.filter(v=>v.feedbackDecision==="ACCEPTED"?!0:v.feedbackDecision==="REJECTED"?!1:v.relevanceCheck?.relevant&&v.relevanceCheck.confidence>=.7).length,offTopic:a.filter(v=>v.feedbackDecision==="REJECTED").length},L=w.total-w.offTopic;return c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"text-stone-600 dar
17k:text-slate-400",children:"Loading responses..."})}):j?e.jsxs("div",{className:"rounded-lg bg-red-900/20 border border-red-600 p-4",children:[e.jsx("p",{className:"text-red-400",children:j}),e.jsx("button",{onClick:()=>f(),className:"mt-2 text-sm text-red-300 hover:text-red-200 underline",children:"Try again"})]}):e.jsxs("div",{className:"space-y-4",children:[(w.offTopic>0||w.flagged>0)&&e.jsxs("div",{className:"bg-emerald-900/20 border border-emerald-700 rounded-lg p-3 flex items-start gap-3",children:[e.jsx("div",{className:"text-emerald-400 text-xl mt-0.5",children:"ℹ️"}),e.jsxs("div",{className:"flex-1 text-sm text-stone-700 dark:text-slate-300",children:[e.jsxs("p",{className:"text-emerald-700 dark:text-emerald-300 font-medium",children:["Session Analysis filtering active: ",L," of ",w.total," responses will be used"]}),e.jsxs("p",{className:"mt-1 text-stone-600 dark:text-slate-400",children:["When you generate insights & summary, only responses you have not rejected are included.",w.offTopic>0&&` ${w.offTopic} rejected response${w.offTopic!==1?"s are":" is"} excluded.`,w.flagged>0&&` ${w.flagged} flagged for review response${w.flagged!==1?"s are":" is"} included unless you reject them.`]})]})]}),e.jsxs("div",{className:"grid grid-cols-5 gap-3",children:[e.jsxs("div",{className:"bg-stone-100 dark:bg-slate-800/50 rounded-lg p-3 border border-stone-200 dark:border-slate-700",children:[e.jsx("div",{className:"text-2xl font-bold text-slate-800 dark:text-slate-200",children:w.total}
17),e.jsx("div",{className:"text-xs text-stone-600 dark:text-slate-400",children:"Total Responses"})]}),e.jsxs("div",{className:`rounded-lg p-3 border ${w.analyzed===w.total,"bg-emerald-900/20 border-emerald-700"}`,children:[e.jsxs("div",{className:`text-2xl font-bold ${w.analyzed===w.total,"text-emerald-400"}`,children:[w.analyzed,"/",w.total]}),e.jsx("div",{className:"text-xs text-stone-600 dark:text-slate-400",children:w.analyzed===w.total?"✅ All Analyzed":"⏳ Analyzed"})]}),e.jsxs("div",{className:"bg-emerald-900/20 rounded-lg p-3 border border-emerald-700",children:[e.jsx("div",{className:"text-2xl font-bold text-emerald-400",children:w.relevant}),e.jsx("div",{className:"text-xs text-stone-600 dark:text-slate-400",children:"Relevant"})]}),e.jsxs("div",{className:"bg-amber-900/20 rounded-lg p-3 border border-amber-700",children:[e.jsx("div",{className:"text-2xl font-bold text-amber-400",children:w.flagged}),e.jsx("div",{className:"text-xs text-stone-600 dark:text-slate-400",children:"Flagged for Review"})]}),e.jsxs("div",{className:"bg-red-900/20 rounded-lg p-3 border border-red-700",children:[e.jsx("div",{className:"text-2xl font-bold text-red-400",children:w.offTopic}
17),e.jsx("div",{className:"text-xs text-stone-600 dark:text-slate-400",children:"Rejected"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 items-center justify-between rounded-lg p-4 border border-stone-200 bg-white dark:bg-slate-800/30 dark:border-slate-700",children:[e.jsxs("div",{className:"flex gap-3 items-center flex-wrap",children:[e.jsx("label",{className:"text-xs text-stone-600 dark:text-slate-400 font-medium",children:"Filter:"}),e.jsxs("select",{value:T,onChange:v=>R(v.target.value),className:"rounded-md border border-stone-300 dark:border-slate-600 bg-white dark:bg-slate-900 px-3 py-1.5 text-sm text-slate-800 dark:text-slate-200 focus:border-emerald-500 focus:ring-2 focus:ring-emerald-500/20",children:[e.jsxs("option",{value:"all",children:["All (",a.length,")"]}),e.jsxs("option",{value:"flagged",children:["Flagged for Review (",w.flagged,")"]}),e.jsx("option",{value:"off-topic",children:"Rejected Only"}),e.jsxs("option",{value:"relevant",children:["Relevant Only (",w.relevant,")"]})]})]}),e.jsx("button",{onClick:()=>f({silent:!0}),className:"rounded-md border border-emerald-600/60 px-3 py-1.5 text-sm font-medium text-emerald-700 transition hover:bg-emerald-600/10 dark:text-emerald-200 dark:hover:bg-emerald-900/30",children:N?"Refreshing…":"Refresh"})]}),e.jsx("div",{className:"space-y-6",children:U.length===0?e.jsx("div",{className:"text-center py-8 text-stone-600 dar
17k:text-slate-400",children:"No responses match the current filter."}):U.map(v=>e.jsxs("div",{className:"bg-white/70 dark:bg-slate-900/30 rounded-lg border border-stone-200 dark:border-slate-700 p-6",children:[e.jsxs("div",{className:"mb-4 pb-4 border-b border-stone-200 dark:border-slate-700",children:[e.jsxs("div",{className:"text-xs text-stone-500 dark:text-slate-500 font-medium mb-1",children:["Question ",v.orderIndex+1]}),e.jsx("div",{className:"text-lg text-slate-800 dark:text-slate-200 font-medium",children:v.questionText}),e.jsxs("div",{className:"text-xs text-stone-500 dark:text-slate-500 mt-2",children:[v.responses.length," response",v.responses.length!==1?"s":""]})]}),e.jsx("div",{className:"space-y-3",children:v.responses.map(g=>{const D=I(g),B=g.analysis?.content?.phase1?.heard;return e.jsxs("div",{className:"bg-white/85 dark:bg-slate-950/50 rounded-lg border border-stone-200 dark:border-slate-700 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:`text-xl ${D.iconColor??""}`,children:D.icon}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-stone-700 dark:text-slate-300 font-medium",children:g.participantLabel}),g.analysis?e.jsx("span",{className:"text-green-400 text-xs",title:"Analysis complete",children:"✅"}):g.hasAnalysis===!0?e.jsx("span",{className:"text-yellow-400 text-xs",title:"Analysis exists but not linked",children:"⏳"}):e.jsx("span",{className:"text-red-400 text-xs",title:"Analysis missing",children:"❌"}),e.jsx(ja,{languageCode:g.detectedLanguage,confidence:g.languageConfidence})]}),e.jsxs("div",{className:`text-xs ${D.color}`,children:[D.label,g.relevanceCheck&&e.jsxs("span",{className:"text-stone-500 dark:text-slate-500 ml-1",children:["(",Math.round(g.relevanceCheck.confidence*100),"%)"]})]})]})]}),B&&e.jsxs("div",{className:"bg-white dark:bg-slate-900/50 rounded p-3 mb-3 border border-stone-200 dark:border-slate-700",children:[e.jsx("div",{className:"text-xs text-stone-600 dar
17k:text-slate-400 font-medium mb-1",children:"Heard:"}),e.jsx("div",{className:"text-sm text-slate-800 dark:text-slate-200",children:B})]}),g.relevanceCheck?.reason&&e.jsxs("div",{className:"text-xs text-stone-500 dark:text-slate-500 italic mb-3",children:['"',g.relevanceCheck.reason,'"']}),g.hasAnalysis===!0&&!g.analysis&&e.jsxs("div",{className:"bg-emerald-900/20 border border-emerald-700 rounded p-3 mb-3 flex items-center justify-between",children:[e.jsx("div",{className:"text-sm text-emerald-700 dark:text-emerald-300",children:"Analysis exists but is not linked to this response. Click to re-link."}),e.jsx("button",{onClick:()=>E(g.responseId),disabled:C===g.responseId,className:"ml-3 px-3 py-1.5 bg-emerald-600 hover:bg-emerald-500 disabled:bg-stone-300 dark:disabled:bg-slate-700 disabled:text-stone-500 dark:text-slate-500 rounded text-xs font-medium text-white transition whitespace-nowrap",children:C===g.responseId?"Linking…":"🔗 Re-link Analysis"})]}),g.hasAnalysis===!1&&!g.analysis&&e.jsxs("div",{className:"bg-amber-900/20 border border-amber-700 rounded p-3 mb-3 flex items-center justify-between",children:[e.jsx("div",{className:"text-sm text-amber-700 dark:text-amber-300",children:"Analysis missing. The initial analysis may have failed."}),e.jsx("button",{onClick:()=>E(g.responseId),disabled:C===g.responseId,className:"ml-3 px-3 py-1.5 bg-amber-600 hover:bg-amber-500 disabled:bg-stone-300 dark:disabled:bg-slate-700 disabled:text-stone-500 dark:text-slate-500 rounded text-xs font-medium text-slate-900 dark:text-white transition whitespace-nowrap",children:C===g.responseId?"Retrying…":"🔄 Retry Analysis"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>x(g.responseId,"ACCEPTED"),disabled:m===g.responseId,className:"flex-1 px-3 py-2 bg-emerald-600 hover:bg-emerald-500 disabled:bg-stone-300 dark:disabled:bg-slate-700 disabled:text-stone-500 dark:text-slate-500 rounded text-sm font-medium text-white transition",children:m===g.responseId?"...":"✓ Accept"}),e.jsx("button",{onClick:()=>x(g.responseId,"REJECTED"),disabled:m===g.responseId,className:"flex-1 px-3 py-2 bg-red-600 hover:bg-red-500 disabled:bg-stone-300 dark:disabled:bg-slate-700 disabled:text-stone-500 dark:text-slate-500 rounded text-sm font-medium text-slate-900 dark:text-white transition",children:m===g.responseId?"...":"✗ Reject"})]})]},g.responseId)})})]},v.questionId))})]})};function wa(s){const a=s??[],d=a.length,c=a.filter(j=>j.feedbackDecision==="REJECTED").length,h=a.filter(j=>j.feedbackDecision==="ACCEPTED"?!0:j.feedbackDecision==="REJECTED"?!1:!!(j.relevanceCheck?.relevant&&j.relevanceCheck.confidence>=.7)).length,N=a.filter(j=>j.feedbackDecision==="REJECTED"||j.feedbackDecision==="ACCEPTED"?!1:!!(j.relevanceCheck&&(!j.relevanceCheck.relevant||j.relevanceCheck.confidence<.7))).length,P=d-c;return{total:d,relevant:h,flagged:N,rejected:c,included:P}}function Sa(s,a){return s?"Auto-check…":a&&a.total>0?`Auto-check ${Math.round(a.checked/a.total*100)}%`:null}const Ca=({sessionId:s,perResponseInsights:a,relevanceCoverage:d,relevanceCoverageLoading:c,onTriggerAnalysis:h,analysisRunning:N=!1,analysisProgress:P=0,analysisPhase:j=""})=>{const{total:b,relevant:T,flagged:R,rejected:m,included:l}=wa(a),C=Sa(c,d),t=b>0&&!N;return e.jsxs("div",{className:"rounded-2xl border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-900/60 p-6 shadow-xl",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-800 dark:text-slate-200",children:"Review Responses"}),C&&e.jsx("span",{className:"text-xs text-stone-500 dark:text-slate-500",children:C})]}),h&&e.jsxs("button",{onClick:h,disabled:!t,className:`relative overflow-hidden shrink-0 rounded-lg border px-4 py-2 text-sm font-medium transition flex items-center justify-center gap-2 ${N?"border-emerald-600 bg-emerald-600/20 text-emerald-700 dark:text-emerald-200 cursor-wait":t?"border-emerald-600 bg-emerald-600/10 text-emerald-700 dark:text-emerald-300 hover:bg-emerald-600/15":"border-stone-200 dark:border-slate-700 bg-stone-100 dar
17k:bg-slate-800/40 text-stone-500 dark:text-slate-500 cursor-not-allowed"}`,children:[N&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-1 bg-stone-100 dark:bg-slate-800/60",children:e.jsx("div",{className:"h-1 bg-emerald-400/70 transition-all",style:{width:`${P}%`}})}),N?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"inline-flex h-3.5 w-3.5 animate-spin rounded-full border-2 border-emerald-400 border-t-transparent"}),e.jsxs("span",{children:["Analyzing…",P>0?` ${P}%`:""]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,children:"✨"}),e.jsx("span",{children:"Generate Session Analysis"})]})]})]}),N&&j&&e.jsx("p",{className:"mt-2 text-xs text-emerald-700/80 dark:text-emerald-300/70 text-right",children:j}),b===0?e.jsx("div",{className:"mt-3 text-sm text-stone-500 dark:text-slate-500",children:"No responses yet."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/40 p-3",children:[e.jsx("div",{className:"text-xs text-stone-600 dar
17k:text-slate-400",children:"Total"}),e.jsx("div",{className:"mt-1 text-base font-semibold text-slate-900 dark:text-slate-100",children:b})]}),e.jsxs("div",{className:"rounded-lg border border-emerald-800/60 bg-white/85 dark:bg-slate-950/40 p-3",children:[e.jsx("div",{className:"text-xs text-stone-600 dark:text-slate-400",children:"Relevant"}),e.jsx("div",{className:"mt-1 text-base font-semibold text-emerald-700 dark:text-emerald-300",children:T})]}),e.jsxs("div",{className:"rounded-lg border border-amber-800/60 bg-white/85 dark:bg-slate-950/40 p-3",children:[e.jsx("div",{className:"text-xs text-stone-600 dark:text-slate-400",children:"Flagged"}),e.jsx("div",{className:"mt-1 text-base font-semibold text-amber-700 dark:text-amber-300",children:R})]}),e.jsxs("div",{className:"rounded-lg border border-rose-800/60 bg-white/85 dark:bg-slate-950/40 p-3",children:[e.jsx("div",{className:"text-xs text-stone-600 dark:text-slate-400",children:"Rejected"}),e.jsx("div",{className:"mt-1 text-base font-semibold text-rose-700 dark:text-rose-300",children:m})]})]}),e.jsxs("div",{className:"mt-3 text-xs text-stone-500 dark:text-slate-500",children:["Session Analysis uses the ",l," included response",l!==1?"s":""," (not rejected).",R>0?` ${R} flagged for review response${R!==1?"s are":" is"} included unless you reject them.`:""]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(Na,{sessionId:s})})]})},Ia=({metrics:s})=>{const a=c=>{switch(c){case"high":return"border-rose-800 bg-rose-900/20 text-rose-300";case"medium":return"border-amber-800 bg-amber-900/20 text-amber-300";case"low":return"border-stone-200 dark:border-slate-700 bg-white/70 dark:bg-slate-900/20 text-stone-700 dark:text-slate-300";default:return"border-stone-200 dark:border-slate-700 bg-white/70 dark:bg-slate-900/20 text-stone-700 dark:text-slate-300"}},d=c=>{switch(c){case"positive":return"border-emerald-800 bg-emerald-900/20 text-emerald-300";case"negative":return"border-rose-800 bg-rose-900/20 text-rose-300";case"neutral":return"border-stone-200 dark:border-slate-700 bg-white/70 dark:bg-slate-900/20 text-stone-700 dark:text-slate-300";case"mixed":return"border-emerald-800 bg-emerald-900/20 text-emerald-300";default:return"border-stone-200 dark:border-slate-700 bg-white/70 dark:bg-slate-900/20 text-stone-700 dark:text-slate-300"}};return e.jsx("div",{className:"space-y-5",children:e.jsxs("div",{className:"rounded-xl border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 p-5",children:[e.jsx("h3",{className:"mb-4 text-sm font-semibold uppercase tracking-wide text-stone-700 dark:text-slate-300",children:"Strategic Intelligence"}),e.jsx("div",{className:"mb-4 flex items-center gap-3 rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/50 p-3",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-slate-500",children:"Data Quality"}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2 text-xs text-stone-700 dark:text-slate-300",children:[e.jsxs("span",{className:"rounded px-2 py-1 bg-white/85 dark:bg-slate-900/40",children:[s.dataQuality.responseCount," responses"]}),e.jsxs("span",{className:"rounded px-2 py-1 bg-white/85 dark:bg-slate-900/40",children:[Math.round(s.dataQuality.completeness*100),"% complete"]}),e.jsxs("span",{className:"rounded px-2 py-1 bg-white/85 dark:bg-slate-900/40",children:[Math.round(s.dataQuality.consistency*100),"% consistent"]})]})]})}),s.consensusMap.length>0&&e.jsxs("div",{className:"mb-5 space-y-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-emerald-400",children:"Group Consensus"}),e.jsx("div",{className:"space-y-2",children:s.consensusMap.map((c,h)=>{const N=Math.round(c.consensusLevel*100);return e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/50 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:c.topic}),e.jsxs("span",{className:`whitespace-nowrap rounded px-2 py-1 text-xs font-semibold ${d(c.majoritySentiment)}`,children:[N,"% consensus"]})]}),e.jsx("div",{className:"mb-2 h-1 w-full overflow-hidden rounded-full bg-stone-100 dar
17k:bg-slate-800",children:e.jsx("div",{className:"h-full bg-emerald-500/70",style:{width:`${N}%`}})}),c.minorityCount>0&&e.jsxs("p",{className:"text-xs text-stone-600 dark:text-slate-400",children:[c.minorityCount," participants hold minority view"]})]},`consensus-${h}`)})})]}),s.audiences.length>0&&e.jsxs("div",{className:"mb-5 space-y-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-emerald-400",children:"Audience Breakdown"}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:s.audiences.map((c,h)=>{const N=Math.round(c.percentOfTotal*100);return e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/50 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:c.segment}),e.jsxs("span",{className:"rounded px-2 py-1 text-xs font-mono text-stone-600 dark:text-slate-400",children:[c.size," / ",N,"%"]})]}),c.uniquePositions.length>0&&e.jsxs("p",{className:"text-xs text-stone-700 dark:text-slate-300",children:[e.jsx("span",{className:"font-semibold",children:"Unique view:"})," ",c.uniquePositions[0]]})]},`audience-${h}`)})})]}),s.tensions.length>0&&e.jsxs("div",{className:"mb-5 space-y-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-amber-400",children:"Key Tensions"}),e.jsx("div",{className:"space-y-2",children:s.tensions.map((c,h)=>e.jsxs("div",{className:`rounded-lg border p-3 ${a(c.impact)}`,children:[e.jsxs("div",{className:"mb-1 flex items-start justify-between gap-2",children:[e.jsx("p",{className:"text-sm font-medium",children:c.tension}),e.jsxs("span",{className:"whitespace-nowrap rounded px-2 py-1 text-xs font-semibold uppercase",children:[c.impact," impact"]})]}),c.description&&e.jsx("p",{className:"text-xs opacity-90",children:c.description})]},`tension-${h}`))})]}),s.outliers.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-rose-400",children:"Notable Outliers"}),e.jsx("div",{className:"space-y-2",children:s.outliers.map((c,h)=>e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/50 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between gap-2",children:[e.jsxs("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100",children:[c.type==="high_outlier"?"⬆":"⬇"," ",c.dimension]}),e.jsxs("span",{className:"rounded px-2 py-1 text-xs font-mono text-stone-600 dar
17k:text-slate-400",children:[c.respondents," respondents"]})]}),e.jsx("p",{className:"text-xs text-stone-700 dark:text-slate-300",children:c.implication})]},`outlier-${h}`))})]}),s.consensusMap.length===0&&s.audiences.length===0&&s.tensions.length===0&&s.outliers.length===0&&e.jsx("p",{className:"text-xs text-stone-600 dark:text-slate-400",children:"No strategic metrics computed yet."})]})})},Aa=s=>{if(!s||typeof s!="object")return!1;const a=s;return"day_overview"in a||"word_observation"in a||"themes_observed"in a},Pa=({content:s,summaryId:a})=>e.jsxs("div",{className:"space-y-5",children:[s.day_overview&&e.jsxs("div",{className:"rounded-xl border border-emerald-900 bg-emerald-950/30 p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-3",children:[e.jsx("h4",{className:"text-sm font-semibold uppercase tracking-wide text-emerald-300",children:"Day Overview"}),s.day_overview.date&&e.jsx("span",{className:"text-xs text-emerald-400",children:s.day_overview.date})]}),s.day_overview.word_of_day&&e.jsxs("p",{className:"text-lg font-bold text-emerald-100 mb-2",children:['Word: "',s.day_overview.word_of_day,'"']}),typeof s.day_overview.response_count=="number"&&e.jsxs("p",{className:"text-xs text-emerald-400 mb-2",children:[s.day_overview.response_count," response",s.day_overview.response_count!==1?"s":""," collected"]}),s.day_overview.summary&&e.jsx("p",{className:"text-sm leading-relaxed text-emerald-100",children:s.day_overview.summary})]}),s.word_observation&&e.jsxs("div",{className:"rounded-xl border border-emerald-900 bg-emerald-950/40 p-5",children:[e.jsxs("h4",{className:"text-sm font-semibold uppercase tracking-wide text-emerald-400 mb-3",children:['How "',s.word_observation.word,'" Was Framed']}),s.word_observation.how_framed&&e.jsx("p",{className:"text-sm leading-relaxed text-slate-900 dark:text-slate-100 mb-3",children:s.word_observation.how_framed}),s.word_observation.key_themes&&s.word_observation.key_themes.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-3",children:s.word_observation.key_themes.map((d,c)=>e.jsx("span",{className:"rounded-full border border-emerald-800 bg-emerald-900/30 px-3 py-1 text-xs text-emerald-200",children:d},`${a}-word-theme-${c}`))}),s.word_observation.sample_voice&&e.jsxs("blockquote",{className:"rounded-md border border-emerald-800 bg-emerald-950/60 p-3 text-sm text-emerald-100 italic",children:['"',s.word_observation.sample_voice,'"']})]}),s.voice_patterns&&e.jsxs("div",{className:"rounded-xl border border-emerald-900 bg-emerald-950/30 p-4",children:[e.jsx("h4",{className:"text-sm font-semibold uppercase tracking-wide text-emerald-400 mb-3",children:"Voice Patterns"}),s.voice_patterns.observed_patterns&&e.jsx("p",{className:"text-sm text-emerald-100 mb-2",children:s.voice_patterns.observed_patterns}),s.voice_patterns.notable_tensions&&s.voice_patterns.notable_tensions.length>0&&e.jsxs("div",{className:"mb-2",children:[e.jsx("p",{className:"text-xs text-emerald-400 mb-1",children:"Notable Tensions:"}),e.jsx("ul",{className:"list-disc pl-5 text-xs text-emerald-200",children:s.voice_patterns.notable_tensions.map((d,c)=>e.jsx("li",{children:d},`${a}-tension-${c}`))})]}),s.voice_patterns.data_quality_note&&e.jsxs("p",{className:"text-xs text-emerald-400 italic",children:["Note: ",s.voice_patterns.data_quality_note]})]}),s.themes_observed&&s.themes_observed.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-stone-500 dark:text-slate-500",children:"Themes Observed"}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:s.themes_observed.map((d,c)=>e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/50 p-4",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-900 dark:text-slate-100",children:d.theme}),d.description&&e.jsx("p",{className:"mt-1 text-xs text-stone-600 dar
17k:text-slate-400",children:d.description}),d.evidence&&e.jsx("p",{className:"mt-2 text-xs text-stone-500 dark:text-slate-500 italic",children:d.evidence})]},`${a}-theme-${c}`))})]}),s.open_observations&&s.open_observations.length>0&&e.jsxs("div",{className:"rounded-xl border border-amber-900 bg-amber-950/20 p-4",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-amber-400 mb-2",children:"Open Observations"}),e.jsx("ul",{className:"space-y-1 text-sm text-amber-100",children:s.open_observations.map((d,c)=>e.jsxs("li",{children:["• ",d]},`${a}-obs-${c}`))})]}),s.ethical_compliance?.notes&&e.jsx("p",{className:"text-xs text-stone-500 dark:text-slate-500 italic",children:s.ethical_compliance.notes})]}),Ke=s=>{if(!s)return"–";const a=new Date(s);return Number.isNaN(a.getTime())?s:a.toLocaleString()},Ta=({sessionId:s,summaries:a,selectedSummaryId:d,onSelectSummary:c,loading:h,error:N,onRefresh:P,onChangeVisibility:j,visibilityUpdatingId:b})=>{const[T,R]=n.useState(!1),m=n.useMemo(()=>d?a.find(t=>t.summary.id===d)??a[0]??null:a[0]??null,[d,a]),l=n.useMemo(()=>m?ma(m):{},[m]),C=n.useMemo(()=>{if(!m?.summary.content)return null;const t=m.summary.content;if(t.metadata&&typeof t.metadata=="object"){const f=t.metadata;if(f.summaryMetrics&&typeof f.summaryMetrics=="object")return f.summaryMetrics}return null},[m]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-base font-semibold text-slate-900 dark:text-white",children:"Format summary"}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-stone-600 dar
17k:text-slate-400",children:[P&&e.jsx("button",{type:"button",onClick:P,className:"rounded-md border border-stone-200 dark:border-slate-700 px-3 py-1 font-semibold uppercase tracking-wide text-slate-800 dark:text-slate-200 transition hover:bg-stone-100 dark:hover:bg-stone-100 dark:bg-slate-800 disabled:cursor-not-allowed disabled:text-stone-500 dark:text-slate-500",disabled:h,children:"Refresh summaries"}),e.jsxs("span",{className:"rounded-full border border-stone-200 dark:border-slate-700 px-3 py-1 font-mono text-[11px] uppercase tracking-wide text-stone-500 dark:text-slate-500",children:["Session ",s.slice(0,8),"…"]})]})]}),N&&e.jsx("p",{className:"rounded-md border border-rose-900 bg-rose-950/40 p-3 text-sm text-rose-200",children:N}),e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row",children:[e.jsx("aside",{className:"flex flex-shrink-0 flex-col gap-2 md:w-60",children:h?e.jsx("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 p-4 text-sm text-stone-700 dark:text-slate-300",children:"Loading summaries…"}):a.length===0?e.jsx("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 p-4 text-sm text-stone-700 dark:text-slate-300",children:"No summaries generated yet."}):a.map(t=>{const f=m?.summary.id===t.summary.id;return e.jsxs("button",{type:"button",onClick:()=>c(t.summary.id),className:`flex flex-col gap-1 rounded-lg border px-4 py-3 text-left transition ${f?"border-emerald-500 bg-emerald-500/10 text-slate-900 dark:text-white shadow-lg shadow-emerald-500/20":"border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/50 text-stone-700 dark:text-slate-300 hover:border-emerald-600/60 hover:text-slate-900 dark:hover:text-white"}`,children:[e.jsx("span",{className:"text-xs uppercase tracking-wide text-stone-600 dar
17k:text-slate-400",children:Ke(t.summary.publishedAt)}),e.jsx("span",{className:"text-sm font-semibold",children:t.summary.visibility==="HOST"?"Internal summary":t.summary.visibility==="PARTICIPANT"?"Shared with participants":"Public summary"}),t.synthesis&&e.jsxs("span",{className:"text-[11px] text-stone-500 dark:text-slate-500",children:["Based on synthesis run ",Ke(t.synthesis.generatedAt)]})]},t.summary.id)})}),e.jsx("section",{className:"flex-1 space-y-5",children:m?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 p-4 text-sm text-slate-800 dark:text-slate-200",children:[e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-3",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("span",{className:"text-xs uppercase tracking-wide text-stone-500 dark:text-slate-500",children:["Published ",Ke(m.summary.publishedAt)]}),m.synthesis&&e.jsxs("span",{className:"text-xs text-stone-500 dark:text-slate-500",children:["Synthesis run ",Ke(m.synthesis.generatedAt)]})]})}),b===m.summary.id&&e.jsx("p",{className:"text-[11px] text-emerald-300",children:"Updating visibility…"})]}),Aa(m.summary.content)?e.jsx(Pa,{content:m.summary.content,summaryId:m.summary.id}):e.jsxs(e.Fragment,{children:[l.sessionPurpose&&e.jsx("div",{className:"rounded-xl border border-emerald-900 bg-emerald-950/30 p-4 text-slate-900 dark:text-slate-100",children:e.jsx("p",{className:"text-sm leading-relaxed text-emerald-100",children:l.sessionPurpose})}),l.executiveSummary&&e.jsxs("div",{className:"rounded-xl border border-emerald-900 bg-emerald-950/40 p-5 text-slate-900 dark:text-slate-100",children:[e.jsx("h4",{className:"text-sm font-semibold uppercase tracking-wide text-emerald-400",children:"Key insights"}),e.jsx("p",{className:"mt-2 text-base leading-relaxed text-slate-900 dark:text-slate-100",children:l.executiveSummary})]}),C&&e.jsx(Ia,{metrics:C}),l.topicSnapshots&&l.topicSnapshots.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-stone-500 dark:text-slate-500",children:"Topic snapshots"}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:(l.topicSnapshots??[]).map((t,f)=>e.jsxs("div",{className:"flex h-full flex-col gap-3 rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/50 p-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-slate-900 dark:text-slate-100",children:t.topic}
17),e.jsx("p",{className:"mt-1 text-xs text-stone-600 dark:text-slate-400",children:t.frameSummary})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-[11px] text-stone-600 dark:text-slate-400",children:[typeof t.participantCount=="number"&&e.jsxs("span",{className:"rounded-full border border-stone-200 dark:border-slate-800 px-3 py-1",children:[t.participantCount," participants"]}),typeof t.responseCount=="number"&&e.jsxs("span",{className:"rounded-full border border-stone-200 dark:border-slate-800 px-3 py-1",children:[t.responseCount," responses"]})]}),(t.toneVector?.valence||t.toneVector?.agency||t.toneVector?.certainty)&&e.jsxs("div",{className:"flex flex-wrap gap-2 text-[11px] text-stone-700 dark:text-slate-300",children:[t.toneVector?.valence&&e.jsxs("span",{className:"rounded-full border border-emerald-900 bg-emerald-900/10 px-2 py-1",children:["Valence: ",t.toneVector.valence]}),t.toneVector?.agency&&e.jsxs("span",{className:"rounded-full border border-emerald-900 bg-emerald-900/10 px-2 py-1",children:["Agency: ",t.toneVector.agency]}),t.toneVector?.certainty&&e.jsxs("span",{className:"rounded-full border border-emerald-900 bg-emerald-900/10 px-2 py-1",children:["Certainty: ",t.toneVector.certainty]})]}),(t.alignmentSignals?.length||t.divergenceSignals?.length)&&e.jsxs("div",{className:"space-y-2 text-xs text-stone-700 dark:text-slate-300",children:[t.alignmentSignals&&t.alignmentSignals.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"uppercase tracking-wide text-stone-500 dark:text-slate-500",children:"Alignment"}),e.jsx("ul",{className:"mt-1 list-disc space-y-1 pl-5",children:(t.alignmentSignals??[]).map((x,E)=>e.jsx("li",{children:x},`${m.summary.id}-align-${f}-${E}`))})]}),t.divergenceSignals&&t.divergenceSignals.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"uppercase tracking-wide text-stone-500 dark:text-slate-500",children:"Divergence"}),e.jsx("ul",{className:"mt-1 list-disc space-y-1 pl-5 text-rose-300",children:(t.divergenceSignals??[]).map((x,E)=>e.jsx("li",{children:x},`${m.summary.id}-diverge-${f}-${E}`))})]})]}),t.notableQuote&&e.jsxs("blockquote",{className:"rounded-md border border-stone-200 dark:border-slate-800 bg-white/90 dark:bg-slate-950/80 p-3 text-xs text-slate-800 dark:text-slate-200",children:[e.jsxs("p",{className:"italic",children:['"',t.notableQuote.quote,'"']}),t.notableQuote.participantLabel&&e.jsx("p",{className:"mt-1 text-[10px] uppercase tracking-wide text-stone-500 dark:text-slate-500",children:t.notableQuote.participantLabel})]})]},`${m.summary.id}-topic-${f}`))})]}),l.insightSpotlight&&l.insightSpotlight.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-stone-500 dark:text-slate-500",children:"Insight spotlights"}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:(l.insightSpotlight??[]).map((t,f)=>e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/50 p-4",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-900 dark:text-slate-100",children:t.title}),e.jsx("p",{className:"mt-2 text-xs text-stone-700 dark:text-slate-300",children:t.takeaway})]},`${m.summary.id}-spotlight-${f}`))})]}),l.recommendedNextMove&&e.jsxs("div",{className:"rounded-xl border border-emerald-800 bg-emerald-950/20 p-4 text-slate-900 dark:text-slate-100",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-emerald-300",children:"Recommended next move"}),e.jsx("p",{className:"mt-2 text-sm text-emerald-200",children:l.recommendedNextMove})]}),l.keyStats&&l.keyStats.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-stone-500 dark:text-slate-500",children:"Key stats"}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:(l.keyStats??[]).map((t,f)=>e.jsx("span",{className:"rounded-full border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 px-3 py-1 text-xs text-slate-800 dark:text-slate-200",children:t},`${m.summary.id}-stat-${f}`))})]}),e.jsxs("button",{type:"button",onClick:()=>R(!T),className:"rounded-md border border-stone-200 dark:border-slate-700 bg-white/85 dark:bg-slate-950/50 px-3 py-2 text-xs font-semibold uppercase tracking-wide text-stone-700 dark:text-slate-300 transition hover:bg-stone-100 dar
17k:hover:bg-stone-100 dark:bg-slate-800",children:[T?"Hide":"Show"," Raw JSON / Summary Content"]}),T&&e.jsxs("div",{className:"space-y-2 rounded-lg border border-stone-200 dark:border-slate-700 bg-white dark:bg-slate-950/60 p-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-stone-600 dark:text-slate-400 mb-2",children:"Raw Content (summary.content):"}),e.jsx("pre",{className:"max-h-96 overflow-auto rounded bg-white dark:bg-slate-900 p-2 text-[10px] text-stone-700 dark:text-slate-300 whitespace-pre-wrap break-words",children:JSON.stringify(m?.summary.content,null,2)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-stone-600 dark:text-slate-400 mb-2",children:"Parsed Deliverable:"}),e.jsx("pre",{className:"max-h-96 overflow-auto rounded bg-white dark:bg-slate-900 p-2 text-[10px] text-stone-700 dark:text-slate-300 whitespace-pre-wrap break-words",children:JSON.stringify(l,null,2)})]}),m?.summary.analysis&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-stone-600 dar
17k:text-slate-400 mb-2",children:"Analysis Data:"}),e.jsx("pre",{className:"max-h-96 overflow-auto rounded bg-white dark:bg-slate-900 p-2 text-[10px] text-stone-700 dark:text-slate-300 whitespace-pre-wrap break-words",children:JSON.stringify(m.summary.analysis,null,2)})]})]}),l.sessionPurpose&&e.jsx("div",{className:"rounded-xl border border-emerald-900 bg-emerald-950/30 p-4 text-slate-900 dark:text-slate-100",children:e.jsx("p",{className:"text-sm leading-relaxed text-emerald-100",children:l.sessionPurpose})}),l.executiveSummary&&e.jsxs("div",{className:"rounded-xl border border-emerald-900 bg-emerald-950/40 p-5 text-slate-900 dark:text-slate-100",children:[e.jsx("h4",{className:"text-sm font-semibold uppercase tracking-wide text-emerald-400",children:"Key insights"}),e.jsx("p",{className:"mt-2 text-base leading-relaxed text-slate-900 dark:text-slate-100",children:l.executiveSummary})]}),l.keyStats&&l.keyStats.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-stone-500 dark:text-slate-500",children:"Key stats"}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:(l.keyStats??[]).map((t,f)=>e.jsx("span",{className:"rounded-full border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 px-3 py-1 text-xs text-slate-800 dark:text-slate-200",children:t},`${m.summary.id}-stat-${f}`))})]}),l.recommendedNextMove&&e.jsxs("div",{className:"rounded-xl border border-emerald-800 bg-emerald-950/20 p-4 text-slate-900 dark:text-slate-100",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-emerald-300",children:"Recommended next move"}),e.jsx("p",{className:"mt-2 text-sm text-emerald-200",children:l.recommendedNextMove})]}),l.insightSpotlight&&l.insightSpotlight.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-stone-500 dark:text-slate-500",children:"Insight spotlights"}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:(l.insightSpotlight??[]).map((t,f)=>e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/50 p-4",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-900 dark:text-slate-100",children:t.title}),e.jsx("p",{className:"mt-2 text-xs text-stone-700 dark:text-slate-300",children:t.takeaway})]},`${m.summary.id}-spotlight-${f}`))})]}),l.topicSnapshots&&l.topicSnapshots.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-stone-500 dark:text-slate-500",children:"Topic snapshots"}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:(l.topicSnapshots??[]).map((t,f)=>e.jsxs("div",{className:"flex h-full flex-col gap-3 rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/50 p-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-slate-900 dark:text-slate-100",children:t.topic}
17),e.jsx("p",{className:"mt-1 text-xs text-stone-600 dark:text-slate-400",children:t.frameSummary})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-[11px] text-stone-600 dark:text-slate-400",children:[typeof t.participantCount=="number"&&e.jsxs("span",{className:"rounded-full border border-stone-200 dark:border-slate-800 px-3 py-1",children:[t.participantCount," participants"]}),typeof t.responseCount=="number"&&e.jsxs("span",{className:"rounded-full border border-stone-200 dark:border-slate-800 px-3 py-1",children:[t.responseCount," responses"]})]}),(t.toneVector?.valence||t.toneVector?.agency||t.toneVector?.certainty)&&e.jsxs("div",{className:"flex flex-wrap gap-2 text-[11px] text-stone-700 dark:text-slate-300",children:[t.toneVector?.valence&&e.jsxs("span",{className:"rounded-full border border-emerald-900 bg-emerald-900/10 px-2 py-1",children:["Valence: ",t.toneVector.valence]}),t.toneVector?.agency&&e.jsxs("span",{className:"rounded-full border border-emerald-900 bg-emerald-900/10 px-2 py-1",children:["Agency: ",t.toneVector.agency]}),t.toneVector?.certainty&&e.jsxs("span",{className:"rounded-full border border-emerald-900 bg-emerald-900/10 px-2 py-1",children:["Certainty: ",t.toneVector.certainty]})]}),(t.alignmentSignals?.length||t.divergenceSignals?.length)&&e.jsxs("div",{className:"space-y-2 text-xs text-stone-700 dark:text-slate-300",children:[t.alignmentSignals&&t.alignmentSignals.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"uppercase tracking-wide text-stone-500 dark:text-slate-500",children:"Alignment"}),e.jsx("ul",{className:"mt-1 list-disc space-y-1 pl-5",children:(t.alignmentSignals??[]).map((x,E)=>e.jsx("li",{children:x},`${m.summary.id}-align-${f}-${E}`))})]}),t.divergenceSignals&&t.divergenceSignals.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"uppercase tracking-wide text-stone-500 dark:text-slate-500",children:"Divergence"}),e.jsx("ul",{className:"mt-1 list-disc space-y-1 pl-5 text-rose-300",children:(t.divergenceSignals??[]).map((x,E)=>e.jsx("li",{children:x},`${m.summary.id}-diverge-${f}-${E}`))})]})]}),t.notableQuote&&e.jsxs("blockquote",{className:"rounded-md border border-stone-200 dark:border-slate-800 bg-white/90 dark:bg-slate-950/80 p-3 text-xs text-slate-800 dark:text-slate-200",children:[e.jsxs("p",{className:"italic",children:["“",t.notableQuote.quote,"”"]}),t.notableQuote.participantLabel&&e.jsx("p",{className:"mt-1 text-[10px] uppercase tracking-wide text-stone-500 dark:text-slate-500",children:t.notableQuote.participantLabel})]})]},`${m.summary.id}-topic-${f}`))})]}),!l.executiveSummary&&(!l.topicSnapshots||l.topicSnapshots.length===0)&&(!l.insightSpotlight||l.insightSpotlight.length===0)&&e.jsx("p",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 p-4 text-sm text-stone-700 dark:text-slate-300",children:"Summary generated but no structured content returned."})]})]}):h?e.jsx("p",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 p-4 text-sm text-stone-700 dark:text-slate-300",children:"Loading summaries…"}):e.jsx("p",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 p-4 text-sm text-stone-700 dark:text-slate-300",children:"No summary selected."})})]})]})},Ra=s=>s.formatKey==="self-research-daily"?e.jsx(xa,{...s}):e.jsx(ua,{...s}),Y=({label:s,checked:a,onChange:d,description:c,disabled:h,locked:N})=>e.jsxs("div",{className:"flex items-start justify-between py-2",children:[e.jsxs("div",{className:"flex-1 pr-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-slate-800",children:s}),N&&e.jsx("span",{className:"text-xs bg-amber-900/50 text-amber-300 px-1.5 py-0.5 rounded",children:"🔒 Host Only"})]}),c&&e.jsx("p",{className:u("text-xs mt-0.5",i.dark.textMuted),children:c})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":a,disabled:h,onClick:()=>d(!a),className:`
18                relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent
19                transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 focus:ring-offset-slate-900
20                ${a?"bg-emerald-600":"bg-stone-300"}
21                ${h?"opacity-50 cursor-not-allowed":""}
22            `,children:e.jsx("span",{className:`
23                    pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 
24                    transition duration-200 ease-in-out
25                    ${a?"translate-x-5":"translate-x-0"}
26                `})})]}),Ea=({sessionId:s,summaryId:a,initialSections:d,onUpdate:c})=>{const[h,N]=n.useState(!1),[P,j]=n.useState(!1),[b,T]=n.useState(()=>({sessionSummary:{...qs.sessionSummary,...d?.sessionSummary},perTopic:{...qs.perTopic,...d?.perTopic}})),R=n.useCallback(async(m,l,C)=>{const t={...b,[m]:{...b[m],[l]:C}};T(t),j(!0);try{await Xt(s,a,t),c?.(t)}catch(f){console.error("Failed to update published sections:",f),T(b)}finally{j(!1)}},[s,a,b,c]);return e.jsxs("div",{className:u("rounded-lg border overflow-hidden",i.dark.borderSubtle,i.dark.surface),children:[e.jsxs("button",{type:"button",onClick:()=>N(!h),className:"w-full flex items-center justify-between px-4 py-3 text-left hover:bg-slate-700/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-slate-800",children:"📋 Publication Settings"}),P&&e.jsx("span",{className:"text-xs text-emerald-400 animate-pulse",children:"Saving..."})]}),e.jsx("span",{className:u("transition-transform",i.dark.textMuted,h?"rotate-180":""),children:"▼"})]}),h&&e.jsxs("div",{className:u("px-4 pb-4 space-y-4 border-t",i.dark.borderSubtle),children:[e.jsxs("div",{className:"pt-4",children:[e.jsx("h4",{className:u("text-xs font-semibold uppercase tracking-wider mb-2",i.dark.textMuted),children:"Session Summary"}),e.jsxs("div",{className:u("space-y-1 border-l-2 pl-3",i.dark.borderSubtle),children:[e.jsx(Y,{label:"Executive Summary",checked:b.sessionSummary?.executiveSummary??!0,onChange:m=>R("sessionSummary","executiveSummary",m),description:"Board-ready overview with key findings"}),e.jsx(Y,{label:"Session Purpose",checked:b.sessionSummary?.sessionPurpose??!0,onChange:m=>R("sessionSummary","sessionPurpose",m),description:"Why this exercise was conducted"}),e.jsx(Y,{label:"What We Heard You Say",checked:b.sessionSummary?.groupHeard??!0,onChange:m=>R("sessionSummary","groupHeard",m),description:"Summary of collective voice"}),e.jsx(Y,{label:"Key Themes",checked:b.sessionSummary?.keyThemes??!0,onChange:m=>R("sessionSummary","keyThemes",m),description:"Cross-topic patterns"}),e.jsx(Y,{label:"Group Tensions",checked:b.sessionSummary?.groupTensions??!0,onChange:m=>R("sessionSummary","groupTensions",m),description:"Areas of divergence"}),e.jsx(Y,{label:"How We Think Differently",checked:b.sessionSummary?.clusterInsights??!0,onChange:m=>R("sessionSummary","clusterInsights",m),description:"Participant group insights"}),e.jsx(Y,{label:"Recommended Next Move",checked:b.sessionSummary?.recommendedNextMove??!0,onChange:m=>
26R("sessionSummary","recommendedNextMove",m),description:"Suggested action steps"})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:u("text-xs font-semibold uppercase tracking-wider mb-2",i.dark.textMuted),children:"Per-Topic Analysis"}),e.jsxs("div",{className:u("space-y-1 border-l-2 pl-3",i.dark.borderSubtle),children:[e.jsx(Y,{label:"Themes",checked:b.perTopic?.themes??!0,onChange:m=>R("perTopic","themes",m),description:"Topic-specific themes"}),e.jsx(Y,{label:"Tensions",checked:b.perTopic?.tensions??!0,onChange:m=>R("perTopic","tensions",m),description:"Topic-specific divergences"}),e.jsx(Y,{label:"Participant Groups",checked:b.perTopic?.clusters??!0,onChange:m=>R("perTopic","clusters",m),description:"How participants cluster per topic"}),e.jsx(Y,{label:"Polar Graphs",checked:b.perTopic?.polarGraphs??!0,onChange:m=>R("perTopic","polarGraphs",m),description:"5 reflection angle visualizations"}),e.jsx(Y,{label:"Open Questions",checked:b.perTopic?.openQuestions??!0,onChange:m=>R("perTopic","openQuestions",m),description:"Questions worth exploring together"}),e.jsx(Y,{label:"All Responses",checked:b.perTopic?.allResponses??!0,onChange:m=>R("perTopic","allResponses",m),description:"Individual response analysis cards"}),e.jsx(Y,{label:"Clustering Analysis",checked:b.perTopic?.clusteringAnalysis??!1,onChange:m=>R("perTopic","clusteringAnalysis",m),description:"Technical clustering metrics (silhouette scores, etc.)",locked:!0})]})]}),e.jsx("p",{className:u("text-xs pt-2 border-t",i.dark.textFaint,i.dark.borderSubtle),children:'Toggle sections to control what participants and public viewers can see when you share the report. Sections marked "🔒 Host Only" are never visible to non-hosts regardless of setting.'})]})]})};function js(s){if(!s)return"—";const a=new Date(s);return Number.isNaN(a.getTime())?"—":a.toLocaleString()}function qe(s){return s==="PARTICIPANT"?"Participants":s==="PUBLIC"?"Public":s==="PUBLIC_UNLISTED"?"Public (unlisted)":"Host Only"}const Da=({synthesis:s})=>{const[a,d]=n.useState(!1),c=n.useMemo(()=>{const h=s?.latestRun;if(!h?.narrative)return null;const N={...h.narrative};return h.population&&(N.population=h.population),h.topic&&(N.topic=h.topic),h.dayContext&&(N.day_context=h.dayContext),h.refusals&&(N.refusals=h.refusals),h.refusalAnalysis&&(N.refusal_analysis=h.refusalAnalysis),h.clusterQuality&&(N.clusterQuality=h.clusterQuality),JSON.stringify(N,null,2)},[s]);return c?e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/40 p-3",children:[e.jsxs("button",{type:"button",onClick:()=>d(h=>!h),className:"flex w-full items-center justify-between text-xs font-semibold text-stone-700 dark:text-slate-300 hover:text-slate-900 dark:hover:text-white transition",children:[e.jsx("span",{children:"Synthesis JSON"}),e.jsx("span",{className:"text-stone-500 dark:text-slate-500",children:a?"▲ Hide":"▼ Show"})]}),a&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"flex justify-end mb-2",children:e.jsx("button",{type:"button",onClick:()=>navigator.clipboard.writeText(c).catch(console.error),className:"rounded border border-stone-200 dark:border-slate-700 px-3 py-1 text-[11px] uppercase tracking-wide text-slate-800 dark:text-slate-200 transition hover:bg-stone-100 dark:hover:bg-slate-800",children:"Copy JSON"})}),e.jsx("pre",{className:"max-h-[70vh] overflow-y-auto rounded-lg bg-white/90 dark:bg-slate-950/80 p-3 text-[11px] leading-relaxed text-slate-800 dark:text-slate-200",children:e.jsx("code",{className:"block whitespace-pre font-mono",children:c})})]})]}):null},Ma=({sessionId:s,sessionTitle:a,formatKey:d,formats:c,questionInput:h,userRole:N,synthesis:P,summaryList:j,selectedSummaryId:b,summaryLoading:T,summaryError:R,publicShareLinks:m,analysisRunning:l,analysisProgress:C,analysisPhase:t,summaryVisibilityUpdating:f,studyContext:x,createdAt:E,currentUserResponseId:y,isAiOnlyStudy:U,configuredVisibility:I="PARTICIPANT",onTriggerAnalysis:w,onTriggerSummaryOnly:L,onSelectSummary:v,onChangeVisibility:g,onRefreshSummaries:D,shareCode:B,sessionStatus:Ce,slotAfterPurposeToc:$e})=>{const[Le,Ne]=n.useState(!1),Xe=n.useMemo(()=>h.split(`
27`).filter(S=>S.trim()).map((S,O)=>({id:`q-${O}`,text:Ye.replace("[topic]",S.trim()),topicWord:S.trim()})),[h]),le=n.useMemo(()=>b?j.find(S=>S.summary?.id===b):j[0]??null,[j,b]),z=le?.summary?.visibility??"HOST",Fe=n.useMemo(()=>c.find(S=>S.key===d),[c,d]),k=d==="reflective-intelligence-exercise"||d==="self
27-research-daily",K=n.useMemo(()=>{const S=P?.latestRun,O=S?.dataset??null,H=P?.perQuestionRuns?Object.values(P.perQuestionRuns):[],ce=H.reduce((_,Z)=>{const he=Z?.dataset?.totals?.responses;return _+(typeof he=="number"?he:0)},0),Ae=ce>0?ce:typeof O?.totals?.responses=="number"?O.totals.responses:null,_e=H.map(_=>{const Z=_?.dataset?.generatedAt,he=_?.completedAt,ss=_?.recordCreatedAt;return Z??he??ss??null}).filter(_=>typeof _=="string"),Ze=_e.length>0?_e.map(_=>new Date(_)).filter(_=>!Number.isNaN(_.getTime())).sort((_,Z)=>Z.getTime()-_.getTime()).map(_=>_.toISOString())[0]:O?.generatedAt??S?.completedAt??S?.recordCreatedAt,es=(()=>{if(H.length===0)return S?.status;const _=H.map(Z=>Z?.status).filter(Z=>Z!==void 0);return _.includes("RUNNING")?"RUNNING":_.every(Z=>Z==="COMPLETED")?"COMPLETED":_.includes("FAILED")?"FAILED":S?.status})(),pe=le?.summary?.publishedAt;return{latest:S,usedResponses:Ae,generatedAt:Ze,synthesisStatus:es,summaryPublishedAt:pe}},[P,le]),Ie=n.useMemo(()=>{const S=le?.summary?.id,O=S?m[S]:void 0,H=j?.[0]?.summary?.id,ce=!!(S&&H&&S===H),Ae=O&&O.startsWith("/")?`${window.location.origin}${O}`:O;return z==="PUBLIC"||z==="PUBLIC_UNLISTED"?Ae??null:z==="PARTICIPANT"&&B&&S?ce?`${window.location.origin}/summary/${B}`:`${window.location.origin}/summary/${B}?summaryId=${S}`:null},[le,z,m,B,j]),Oe=!!Ie,X=n.useMemo(()=>{const S=le?.summary?.id;if(!S||z!=="PUBLIC"&&z!=="PUBLIC_UNLISTED")return null;const O=m[S];return O?O.startsWith("/")?`${window.location.origin}${O}`:O:null},[le,z,m]),de=j.length>0;return e.jsxs("div",{className:"space-y-6",children:[l&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-emerald-600/40 bg-emerald-600/5 px-4 py-2.5 text-xs text-emerald-700 dark:border-emerald-800/50 dark:bg-emerald-950/20 dark:text-emerald-300",children:[e.jsx("span",{className:"inline-flex h-3 w-3 animate-spin rounded-full border-2 border-emerald-400 border-t-transparent"}),e.jsxs("span",{children:[t||"Running analysis…",C>0?` (${C}%)`:""]})]}),de?e.jsx("div",{children:k?e.jsx(Ra,{sessionId:s,sessionTitle:a,formatName:Fe?.label,formatKey:d,formatPurpose:Fe?.purposeDescription,studyName:x?.studyTitle,totalDays:x?.totalDays,isAiOnlyStudy:U,questions:Xe,summary:j[0]??null,summaryList:j,selectedSummaryId:b,onSelectSummary:v,onViewTopicSynthesis:()=>{const S=document.querySelector("[data-topic-synthesis-section]");S&&S.scrollIntoView({behavior:"smooth",block:"start"})},onChangeVisibility:g,visibilityUpdatingId:f,synthesis:P,createdAt:E,isHostPage:!0,currentUserResponseId:y,shareCode:B??void 0,slotAfterPurposeToc:$e}):e.jsx(Ta,{sessionId:s,summaries:j,selectedSummaryId:b,onSelectSummary:v,loading:T,error:R,onRefresh:D,onChangeVisibility:g,visibilityUpdatingId:f})}):e.jsx("div",{className:"rounded-2xl border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-900/60 p-4 sm:p-6 shadow-xl",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 py-6 text-center",children:[e.jsx("div",{className:"text-3xl",children:"✨"}
27),e.jsxs("p",{className:"text-sm text-stone-600 dark:text-slate-400",children:["No session analysis yet. Go to ",e.jsx("span",{className:"text-slate-800 dark:text-slate-200 font-medium",children:"Responses"})," and click ",e.jsx("span",{className:"text-emerald-700 dark:text-emerald-300 font-medium",children:"Generate Session Analysis"})," to get started."]})]})}),(de||P)&&e.jsxs("div",{className:"rounded-2xl border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-900/60 p-4 sm:p-5 shadow-xl",children:[e.jsxs("button",{type:"button",onClick:()=>Ne(S=>!S),className:"flex w-full items-center justify-between gap-3 text-left",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-800 dark:text-slate-200",children:"Publishing & versions"}),e.jsx("span",{className:"ml-3 text-xs text-stone-500 dark:text-slate-500",children:de?z==="HOST"?"Not published yet; participants see nothing":`Published to ${qe(z)}`:"No summary yet"})]}),e.jsx("span",{className:"shrink-0 text-xs text-stone-500 dark:text-slate-500",children:Le?"▲ Hide":"▼ Show"})]}),Le&&e.jsxs("div",{className:"mt-4 space-y-5",children:[de&&e.jsxs(e.Fragment,{children:[(()=>{const S=qe(I),O=z===I,H=le?.summary?.id,ce=H&&f===H;return e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between rounded-lg border p-4 border-emerald-800/50 bg-emerald-950/20",children:[e.jsxs("div",{className:"min-w-0",children:[O?e.jsxs("p",{className:"text-sm text-emerald-800 dark:text-emerald-200",children:[e.jsx("span",{className:"mr-1.5",children:"✅"}),"Results published as ",e.jsx("span",{className:"font-semibold",children:S})]}):e.jsxs("p",{className:"text-sm text-slate-800 dark:text-slate-200",children:["Publish results as ",e.jsx("span",{className:"font-semibold text-emerald-700 dark:text-emerald-300",children:S})]}),e.jsxs("p",{className:"mt-0.5 text-xs text-stone-500 dark:text-slate-500",children:["Visibility is configured in the Invite section.",z!==I&&z!=="HOST"&&e.jsxs(e.Fragment,{children:[" Currently: ",e.jsx("span",{className:"text-stone-600 dar
27k:text-slate-400",children:qe(z)})]})]})]}),!O&&H&&e.jsx("button",{type:"button",disabled:!!ce,onClick:()=>g(H,I),className:"shrink-0 rounded-lg border border-emerald-600 bg-emerald-600/20 px-4 py-2 text-sm font-medium text-emerald-800 dark:text-emerald-200 transition hover:bg-emerald-600/30 disabled:opacity-50 disabled:cursor-wait",children:ce?"Publishing…":"Publish"})]})})(),j.length>1&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold uppercase tracking-wide text-stone-600 dark:text-slate-400 mb-2",children:"Version"}),e.jsx("select",{value:b||"",onChange:S=>v(S.target.value),className:"w-full min-h-[40px] rounded-lg border border-stone-200 dark:border-slate-700 bg-white/90 dark:bg-slate-950/80 px-3 py-2 text-sm text-slate-800 dark:text-slate-200 focus:border-emerald-500 focus:outline-none",children:j.map(S=>{const O=S.summary.publishedAt?new Date(S.summary.publishedAt).toLocaleString():"Unknown date",H=qe(S.summary.visibility);return e.jsxs("option",{value:S.summary.id,children:[O," \\u2013 ",H]},S.summary.id)})})]}),(X||Oe)&&e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/40 p-3",children:[e.jsx("code",{className:"min-w-0 flex-1 truncate text-xs text-emerald-700 dark:text-emerald-300",children:X||Ie}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{const S=X||Ie;S&&navigator.clipboard.writeText(S)},className:"rounded-lg bg-stone-300 dark:bg-slate-700 px-3 py-1.5 text-xs font-medium text-slate-800 dark:text-slate-200 hover:bg-stone-300 dark:hover:bg-slate-600 transition whitespace-nowrap",children:"Copy Link"}),e.jsx("a",{href:`mailto:?subject=${encodeURIComponent(`Session results: ${a}`)}&body=${encodeURIComponent(`Here are the session results:
28
29${X||Ie}`)}`,className:"rounded-lg bg-stone-300 dark:bg-slate-700 px-3 py-1.5 text-xs font-medium text-slate-800 dark:text-slate-200 hover:bg-stone-300 dark:hover:bg-slate-600 transition whitespace-nowrap inline-flex items-center",children:"Email"})]})]}),b&&e.jsx(Ea,{sessionId:s,summaryId:b,initialSections:j.find(S=>S.summary?.id===b)?.summary?.publishedSections})]}),e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/40 p-3",children:[e.jsx("div",{className:"text-xs font-semibold text-stone-700 dark:text-slate-300",children:"Latest Session Analysis"}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-x-6 gap-y-1 text-xs text-stone-500 dark:text-slate-500",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-stone-600 dar
29k:text-slate-400",children:"Synthesis:"})," ",K.latest?K.synthesisStatus==="COMPLETED"?`Available (${js(K.generatedAt)})`:K.synthesisStatus==="FAILED"?"Failed":K.synthesisStatus==="RUNNING"?`Running (started ${js(K.latest.startedAt)})`:"Pending":"Not generated yet"]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-stone-600 dark:text-slate-400",children:"Responses:"})," ",typeof K.usedResponses=="number"?`${K.usedResponses} included`:"—"]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-stone-600 dark:text-slate-400",children:"Summary:"})," ",de?`Available (${js(K.summaryPublishedAt)})`:"Not generated yet"]})]})]}),e.jsx(Da,{synthesis:P})]})]})]})},ot=s=>{s<0&&(s=0);const a=Math.floor(s/36e5),d=Math.floor(s%36e5/6e4);return a>=48?`${Math.floor(a/24)} d`:a>0?`${a} h ${d} min`:`${d} min`};function dt({dashboard:s,hasAnalysis:a,allowOpenJoin:d=!1,onGoToAnalysis:c,latestAnalysisAt:h,onRegenerateAnalysis:N,analysisRunning:P=!1}){const{invited:j,started:b,completed:T}=s.participants,R=Math.max(j,b,T),m=Math.max(0,R-T),l=Date.now(),C=l-new Date(s.createdAt).getTime(),t=s.expiresAt?new Date(s.expiresAt).getTime():null,f=t!=null?t-l:null,x=B=>B?new Date(B).getTime():null,E=s.analysisStaleness,y=x(E?.lastSynthesisAt),U=x(h),I=x(s.timestamps?.lastConfirmedResponseAt),w=E!=null&&(U==null||y!=null&&y>=U),L=w?E.newResponsesSinceAnalysis:0,v=!!(a&&(w?L>0:U!=null&&I!=null&&I>U));let g,D=!1;return v?(D=!0,L===1?g="1 new reflection arrived after this analysis was generated. Refresh it to bring the results up to date.":L>1?g=`${L} new reflections arrived after this analysis was generated. Refresh it to see the full group read.`:g="New responses arrived after this analysis was generated. Refresh it to bring the results up to date."):s.isClosed?(D=!a&&T>0,g=D?"Session closed. Waiting on you: generate the session analysis.":`Session closed. ${T} ${T===1?"person":"people"} responded.`):R===0?g="Live · waiting for the first participant. Share the join link or send invites.":d?(g=`Live · open join: ${T} ${T===1?"person has":"people have"} responded so far. Generate the analysis whenever you're ready; you can re-run it as more come in.`,D=!1):m>0?g=`Live · waiting on participants: ${T} of ${R} responded.`:(D=!a,g=D?"Everyone invited is in. Waiting on you: generate the session analysis.":"Everyone invited is in; the analysis is ready below."),e.jsxs("div",{className:`mb-4 rounded-lg border p-4 ${D?"border-emerald-700/40 bg-emerald-950/15":"border-stone-200 dark:border-slate-700 bg-white/70 dark:bg-slate-900/30"}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("div",{className:"text-sm font-semibold text-slate-900 dark:text-slate-100",children:g}),v&&N?e.jsx("button",{type:"button",onClick:N,disabled:P,className:"rounded-lg bg-emerald-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-emerald-500 disabled:opacity-50",children:P?"Refreshing the analysis…":"Refresh the analysis"}):D&&c?e.jsx("button",{type:"button",onClick:c,className:"rounded-lg bg-emerald-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-emerald-500",children:"Go to Session Analysis"}):null]}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-x-4 gap-y-0.5 text-xs text-stone-600 dar
29k:text-slate-400",children:[e.jsxs("span",{children:["👥 ",b," joined",j>0?` · ${j} invited`:""]}),e.jsxs("span",{children:["🗣 ",T," responded",!d&&m>0?` · waiting for ${m}`:""]}),e.jsxs("span",{children:["⏱ live for ",ot(C),f==null&&!s.isClosed?" · no closing time set":""]}),f!=null&&e.jsx("span",{children:f>0?`⌛ ${ot(f)} left`:"⌛ response window closed"})]})]})}const ct=s=>{if(!s||typeof s!="object")return!1;const d=s.summary;return!d||typeof d!="object"?!1:typeof d.id=="string"&&typeof d.visibility=="string"},mt={DRAFT:"bg-amber-600/10 text-amber-300 border border-amber-600/40",ACTIVE:"bg-red-600/10 text-red-300 border border-red-600/40",CLOSED:"bg-emerald-600/10 text-emerald-700 dark:text-emerald-300 border border-emerald-600/40"},Ns=(s,a)=>{if(s==="DRAFT")return"DRAFT";if(s==="CLOSED")return"CLOSED";if(s==="ACTIVE"){if(!a)return"ACTIVE • until closed manually";const d=new Date(a),c=new Date,h=d.getTime()-c.getTime();if(h<=0)return"CLOSED";const N=Math.floor(h/(1e3*60*60*24)),P=Math.floor(h%(1e3*60*60*24)/(1e3*60*60));return N>0?`ACTIVE • ${N}d ${P}h remaining`:P>0?`ACTIVE • ${P}h remaining`:`ACTIVE • ${Math.floor(h%36e5/6e4)}m remaining`}return s},$a=s=>{const a=document.getElementById(s);if(!a)return()=>{};const d=window.scrollY;a.scrollIntoView({behavior:"smooth",block:"start"});const c=setTimeout(()=>{Math.abs(window.scrollY-d)<4&&a.scrollIntoView({block:"start"})},300);return()=>clearTimeout(c)},xt=s=>{const a=s.topicWord||"";return a&&s.topicKind==="entity"?`${a}™`:a},La=new Set(["setup","topics","participate","invite"]),Fa=new Set(["setup","topics","participate","invite"]),Oa=()=>{const{sessionId:s}=Mt(),a=$t(),d=Lt(),[c,h]=n.useState(!1),[N,P]=n.useState(null),[j]=Ft(),b=!!s,{user:T}=Ot(),[R,m]=n.useState(0),[l,C]=n.useState(null),[t,f]=n.useState([]),[x,E]=n.useState({formatKey:"",title:"",description:"",promptPackId:"",visibility:"PARTICIPANT",allowOpenJoin:!0,isEmbeddingPublic:!1,questionInput:"",timePerQuestionSec:60,aiInstructions:"",enableAiParticipants:!1,hostAsParticipant:!1,acceptedResponseLanguages:["en"],insightLanguages:["en"],primaryLanguage:"en"}),[y,U]=n.useState(et()),[I,w]=n.useState(""),[L,v]=n.useState(!1),[g,D]=n.useState(null),B=n.useRef(""),[Ce,$e]=n.useState(!1),[Le,Ne]=n.useState(null),[Xe,le]=n.useState(null),[z,Fe]=n.useState([]);n.useEffect(()=>{ia().then(Fe).catch(()=>{})},[]);const[k,K]=n.useState(null),[Ie,Oe]=n.useState(null),[X,de]=n.useState(null),[S,O]=n.useState([]),H=n.useMemo(()=>{let r=null;for(const o of S){const p=o.analysisRun?.completedAt??o.analysisRun?.startedAt??o.summary?.publishedAt??null;p&&(!r||new Date(p).getTime()>new Date(r).getTime())&&(r=p)}return r},[S]),[ce,Ae]=n.useState([]),[_e,Ze]=n.useState(0),[es,Ss]=n.useState(0),[pe,_]=n.useState(null),[Z,he]=n.useState(!1),[ss,ts]=n.useState(null),[as,Cs]=n.useState(null),[We,rs]=n.useState(null),[ut,Is]=n.useState({}),[ee,As]=n.useState([]),[Ps,pt]=n.useState(!1),[W,V]=n.useState("setup");n.useEffect(()=>{document.documentElement.classList.remove("dark")},[s]);const Be=!!k?.programmeContext,G=k?.programmeContext?.programmeId??k?.programmeHomeId??null,Ts=j.get("section")==="participate";n.useEffect(()=>{G&&Ts&&d(`/host/programmes/${G}`,{replace:!0})},[G,Ts,d]);const we=!!k&&!Be&&!k?.studyContext?.isStudySession&&x.formatKey==="reflective-intelligence-exercise",be=Be?La:we?Fa:null;n.useEffect(()=>{if(!be?.has(W))return;const r=l?.sessionId;if(we&&r&&W==="invite"){d(`/host/exercises/${r}/invite`,{replace:!0});return}if(we&&r&&W==="participate"){d(`/host/exercises/${r}/speak`,{replace:!0});return}V("summaries")},[be,W,we,l?.sessionId,d]),n.useEffect(()=>{const r=j.get("section");j.get("payment")==="success"?V("invite"):(r==="invite"||r==="participate"||r==="summaries")&&V(r)},[j]);const Rs=n.useRef(!1);n.useEffect(()=>{if(Rs.current||!k)return;Math.max(k.participants.started,k.participants.completed)>=2&&W==="participate"&&(Rs.current=!0,V("summaries"))},[k,W]);const[re,Es]=n.useState(!1),[ht,ns]=n.useState(!1),[ge,ls]=n.useState(""),[fe,is]=n.useState(""),[os,Ds]=n.useState(!1),[Pe,Ue]=n.useState(!1),[ds,ye]=n.useState(0),[cs,xe]=n.useState(""),[te,Ms]=n.useState(null),[bt,$s]=n.useState(null),[gt,Ls]=n.useState(!1),ms=n.useRef(null),xs=n.useRef(null),us=n.useRef(null),me=_t();n.useEffect(()=>{const r=l?.sessionId||s;if(!r||!me.isConnected)return;me.emit("session:subscribe",{sessionId:r});const o=async p=>{if(p.sessionId===r)try{const[A]=await Promise.all([ks(r)]);de(A)}catch(A){console.error("Failed to refresh synthesis after WS event:",A)}};return me.on("session:synthesis-updated",o),()=>
29{me.emit("session:unsubscribe",{sessionId:r}),me.off("session:synthesis-updated",o)}},[l?.sessionId,s,me.isConnected]);const[_a,ps]=n.useState({languageSettings:!1,sessionConfig:!0,participants:!1,reviewResponses:!1,analysisSynthesis:!1,jsons:!1}),hs=n.useMemo(()=>{const r=I||x.formatKey;if(!r||ee.length===0)return!1;const o=ee.find(A=>A.key===r);return o?(o.features??{}).usesStudyContainer===!0:!1},[I,x.formatKey,ee]);n.useEffect(()=>{const o=new URLSearchParams(a.search).get("section");o==="participants"?ps(p=>({...p,participants:!0,sessionConfig:!1,analysisSynthesis:!1})):o==="results"&&ps(p=>({...p,analysisSynthesis:!0,sessionConfig:!1,participants:!1}))},[a.search]);const bs=n.useCallback(async()=>{if(!T?.id){D("User ID missing");return}if(hs&&!b){if(!y.title.trim()){D("Study title is required");return}if(y.wordList.length===0){D("At least one word is required");return}try{v(!0),D(null);const r={title:y.title,description:y.description||void 0,totalDays:y.totalDays,expectedParticipantCount:y.expectedParticipantCount>0?y.expectedParticipantCount:void 0,frequency:y.frequency,startDate:y.startDate||void 0,wordList:y.wordList,wordRepeatPattern:y.wordRepeatPattern||void 0,openTime:y.openTime,closeTime:y.closeTime,publishTime:y.publishTime,timezone:y.timezone,responseWindowHours:y.responseWindowHours,canonicalPrompt:y.canonicalPrompt,participantInstructions:y.participantInstructions||void 0,aiInstructions:y.aiInstructions||void 0,enableAiParticipants:y.enableAiParticipants,aiPanelId:y.aiPanelId||void 0,acceptedResponseLanguages:y.acceptedResponseLanguages,insightLanguages:y.insightLanguages,primaryLanguage:y.primaryLanguage,autoPublishDailySynthesis:y.autoPublishDailySynthesis,autoTriggerLongitudinal:y.autoTriggerLongitudinal,publishToYouTube:y.publishToYouTube,enableVideoGeneration:y.enableVideoGeneration,visibility:y.visibility,allowOpenJoin:y.allowOpenJoin,...y.arcReflectionEnabled?{arcReflectionRhythm:y.arcReflectionRhythm,arcReflectionIntervalDays:y.arcReflectionRhythm==="custom"?y.arcReflectionIntervalDays:void 0}:{},schedulingMode:y.schedulingMode,...y.schedulingMode==="cycle"?{cycleDurationMinutes:y.cycleDurationMinutes,cycleCloseBeforePublishMinutes:y.cycleCloseBeforePublishMinutes}:{},reminderEnabled:y.reminderEnabled,...y.reminderEnabled?{reminderOffsetMinutes:y.reminderOffsetMinutes,reminderRepeatIntervalMinutes:y.reminderRepeatIntervalMinutes,reminderMaxCount:y.reminderMaxCount}:{}},o=await oa(r);d(`/host/studies/${o.id}`)}catch(r){console.error("Failed to create study:",r);let o="Failed to create study";if(r&&typeof r=="object"){const p=r,A=p.response?.data;typeof A?.message=="string"?o=A.message:typeof A?.error=="string"?o=A.error:typeof p.message=="string"&&(o=p.message)}else r instanceof Error&&(o=r.message);D(o)}finally{v(!1)}return}if(!x.formatKey||!x.promptPackId){D("Format and prompt pack are required");return}try{if(v(!0),D(null),b&&s){const r={title:x.title||"Untitled Session",description:x.description,timePerQuestionSec:x.timePerQuestionSec,visibility:x.visibility,allowOpenJoin:x.allowOpenJoin,isEmbeddingPublic:x.isEmbeddingPublic,aiInstructions:x.aiInstructions,hostAsParticipant:x.hostAsParticipant,acceptedResponseLanguages:x.acceptedResponseLanguages,insightLanguages:x.insightLanguages,primaryLanguage:x.primaryLanguage};await ve(s,r),D("Session updated successfully!");const o=await Ys(s);if(o){let p=!1;try{const F=(await vs())?.formats??[],J=o.formatKey??"";p=((J?F.find(se=>se.key===J):void 0)?.features??{}).topicListRequired===!0}catch{}const A=o.questions?.map($=>p?xt($):$.text||"").join(`
30`)||"";B.current=A,f(o.keyQuestions??[]),E({formatKey:o.formatKey||"",title:o.title||"",description:o.description||"",promptPackId:o.promptPackId||"",visibility:o.visibility||"PARTICIPANT",allowOpenJoin:o.allowOpenJoin??!0,isEmbeddingPublic:o.isEmbeddingPublic||!1,questionInput:A,timePerQuestionSec:o.timePerQuestionSec||60,aiInstructions:o.aiInstructions??"",enableAiParticipants:o.enableAiParticipants??!1,hostAsParticipant:o.hostAsParticipant??!1,minGroupSize:o.minGroupSize??null,acceptedResponseLanguages:o.acceptedResponseLanguages||["en"],insightLanguages:o.insightLanguages||["en"],primaryLanguage:o.primaryLanguage||"en",invite
30Context:o.inviteContext??null})}}else{const r={hostUserId:T.id,formatKey:x.formatKey,promptPackId:x.promptPackId,title:x.title||"Untitled Session",description:x.description,timePerQuestionSec:x.timePerQuestionSec,questionSet:x.questionInput.split(`
31`).filter(p=>p.trim()),visibility:x.visibility,allowOpenJoin:x.allowOpenJoin,isEmbeddingPublic:x.isEmbeddingPublic,aiInstructions:x.aiInstructions,enableAiParticipants:x.enableAiParticipants,hostAsParticipant:x.hostAsParticipant,acceptedResponseLanguages:x.acceptedResponseLanguages,insightLanguages:x.insightLanguages,primaryLanguage:x.primaryLanguage},o=await Zt(r);C(o),V("invite"),o.sessionId&&d(`/host/sessions/${o.sessionId}`)}}catch(r){console.error("Failed to create/update session:",r);let o="Failed to create/update session";if(r&&typeof r=="object"){const p=r,A=p.response?.data;typeof A?.message=="string"?o=A.message:typeof A?.error=="string"?o=A.error:p.response?.data!==void 0?o=JSON.stringify(p.response.data):typeof p.message=="string"&&(o=p.message)}else r instanceof Error&&(o=r.message);D(o)}finally{v(!1)}},[T,x,y,hs,b,s,d]),Fs=n.useMemo(()=>new URLSearchParams(a.search).get("type"),[a.search]);n.useEffect(()=>{(async()=>{try{const p=(await vs())?.formats??[];if(As(p),!b&&!I&&p.length>0){const A=new URLSearchParams(a.search).get("format");let $=A?p.find(F=>F.key===A):void 0;if(!$&&Fs){const F=p.filter(J=>{const M=(J.features??{}).usesStudyContainer===!0;return Fs==="study"?M:!M});F.length===1&&($=F[0])}if($){const F=$;w(F.key),pt(!0),E(J=>({...J,formatKey:F.key,promptPackId:F.defaults.promptPack.session??""}))}}}catch(o){console.error("Failed to load formats:",o)}})()},[]),n.useEffect(()=>{b&&s&&T?.id&&(async()=>{try{const o=async()=>{if(ee.length>0)return ee;try{const $=(await vs())?.formats??[];return $.length>0&&As($),$}catch{return ee}},p=await Ys(s);if(p){const J=((await o()).find(M=>M.key===p.formatKey)?.features??{}).topicListRequired===!0,ie=p.questions?.map(M=>J?xt(M):M.text||"").join(`
32`)||"";B.current=ie,f(p.keyQuestions??[]),E({formatKey:p.formatKey||"",title:p.title||"",description:p.description||"",promptPackId:p.promptPackId||"",visibility:p.visibility||"PARTICIPANT",allowOpenJoin:p.allowOpenJoin??!0,isEmbeddingPublic:p.isEmbeddingPublic||!1,questionInput:ie,timePerQuestionSec:p.timePerQuestionSec||60,aiInstructions:p.aiInstructions??"",enableAiParticipants:p.enableAiParticipants??!1,hostAsParticipant:p.hostAsParticipant??!1,minGroupSize:p.minGroupSize??null,acceptedResponseLanguages:p.acceptedResponseLanguages||["en"],insightLanguages:p.insightLanguages||["en"],primaryLanguage:p.primaryLanguage||"en",inviteContext:p.inviteContext??null}),C({sessionId:p.id,shareInfo:{sessionId:p.id,shareCode:p.shareCode||"",embedUrl:"",joinUrl:""}})}}catch(o){console.error("Failed to load session settings:",o),D("Failed to load session settings")}})()},[b,s,T?.id,ee]),n.useEffect(()=>{if(!l?.sessionId)return;const r=async()=>{try{const o=await Ge(l.sessionId);K(o),o.shareCode&&C(p=>p&&{...p,shareInfo:{...p.shareInfo||{sessionId:o.sessionId||p.sessionId,embedUrl:"",joinUrl:"",shareCode:""},shareCode:o.shareCode}})}catch(o){console.error("Failed to refresh dashboard:",o)}};return r(),ms.current=setInterval(r,3e4),()=>{ms.current&&clearInterval(ms.current)}},[l?.sessionId]);const Os=n.useRef(!1);n.useEffect(()=>{Os.current||k?.status==="ACTIVE"&&!re&&(te?.length??0)>0&&(Es(!0),Os.current=!0)},[k?.status,te?.length]),n.useEffect(()=>{if(!l?.sessionId)return;let r=!1;return(async()=>
32{try{Ls(!0);const p=await je.get(`/api/sessions/${l.sessionId}/per-response-insights/host`),A=Array.isArray(p.data)?p.data:[],$=A.length,F=A.filter(J=>!!J?.relevanceCheck).length;r||(Ms(A),$s({checked:F,total:$}))}catch{r||(Ms(null),$s(null))}finally{r||Ls(!1)}})(),()=>{r=!0}},[l?.sessionId,W]),n.useEffect(()=>{if(!l?.sessionId||!T?.id)return;const r=async()=>{try{const o=await Zs(l.sessionId);Oe(o)}catch(o){console.error("Failed to refresh token usage:",o)}};return r(),xs.current=setInterval(r,3e4),()=>{xs.current&&clearInterval(xs.current)}},[l?.sessionId]),n.useEffect(()=>{if(!l?.sessionId)return;const r=async()=>{try{const o=await ks(l.sessionId);de(o)}catch(o){console.error("Failed to refresh synthesis:",o)}};return r(),us.current=setInterval(r,6e4),()=>{us.current&&clearInterval(us.current)}},[l?.sessionId]);const ne=n.useCallback(async()=>{const r=l?.sessionId||s;if(!r)return[];try{he(!0),ts(null);const p=(await je.get(`/api/sessions/${r}/format-summaries?limit=50`)).data,A=(Array.isArray(p)?p:[]).filter(ct),$=A.filter(M=>!M.summary.formatType.startsWith("cadence-overlay-"));O($);const F=A.filter(M=>M.summary.formatType.startsWith("cadence-overlay-")),J=new Set(["cadence-overlay-mina","cadence-overlay-mina-movement"]);Ae(F.filter(M=>!J.has(M.summary.formatType)).map(M=>({id:M.summary.id,formatType:M.summary.formatType,content:M.summary.content,visibility:M.summary.visibility}))),Ze(F.filter(M=>M.summary.formatType==="cadence-overlay-mina").length),Ss(F.filter(M=>M.summary.formatType==="cadence-overlay-mina-movement").length),$.length>0&&ps(M=>({...M,analysisSynthesis:!0}));const ie=new Set($.filter(M=>M.summary.visibility==="PUBLIC"||M.summary.visibility==="PUBLIC_UNLISTED").map(M=>M.summary.id));return Is(M=>{const se={};for(const oe of $){const ke=oe.summary.publicUrl;ke&&ie.has(oe.summary.id)&&(se[oe.summary.id]=ke)}for(const[oe,ke]of Object.entries(M))ie.has(oe)&&!se[oe]&&(se[oe]=ke);return se}),$.length>0&&!pe&&_($[0].summary.id),$}catch(o){return console.error("Failed to load summaries:",o),ts(o instanceof Error?o.message:"Failed to load summaries"),[]}finally{he(!1)}},[l?.sessionId,s,pe]);n.useEffect(()=>{l?.sessionId&&ne()},[l?.sessionId,ne]);const ft=n.useCallback(r=>{_(r)},[]),yt=n.useCallback(async()=>{await ne()},[ne]),[_s,Ws]=n.useState(!1),[kt,Bs]=n.useState(!1);n.useEffect(()=>{Bs(S.length>=5)},[S.length]);const vt=n.useCallback(async()=>{const r=l?.sessionId||s;if(r)try{Ws(!0);const p=(await je.get(`/api/sessions/${r}/format-summaries?limit=50`)).data,A=(Array.isArray(p)?p:[]).filter(ct);O(A),Bs(!1)}catch(o){console.error("Failed to load more summaries:",o)}finally{Ws(!1)}},[l?.sessionId,s]),jt=n.useCallback(async(r,o)=>{if(o!=="HOST"){rs({summaryId:r,visibility:o});return}await Us(r,o)},[]),Us=n.useCallback(async(r,o)=>{const p=l?.sessionId||s;if(!p){console.error("No session ID available");return}try{Cs(r);const A=await je.patch(`/api/sessions/${p}/format-summaries/${r}`,{visibility:o});A.data?.publishError&&console.error("Publish error:",A.data.publishError),(o==="PUBLIC"||o==="PUBLIC_UNLISTED")&&A.data?.publishedDataset?.publicUrl&&Is($=>({...$,[r]:A.data.publishedDataset.publicUrl})),await ne()}catch(A){console.error("Failed to change visibility:",A),ts(A instanceof Error?A.message:"Failed to update visibility")}finally{Cs(null)}},[l?.sessionId,s,ne]),Nt=n.useCallback(()=>{if(k?.expiresAt){const r=new Date(k.expiresAt),o=r.toISOString().split("T")[0],p=r.toTimeString().slice(0,5);ls(o),is(p)}else{const r=new Date;r.setDate(r.getDate()+1);const o=r.toISOString().split("T")[0];ls(o),is("17:00")}ns(!0)},[k?.expiresAt]),wt=n.useCallback(async()=>{if(!l?.sessionId||!ge||!fe){alert("Please select both date and time");return}try{Ds(!0);const r=`${ge}T${fe}:00`,o=new Date(r).toISOString();await ve(l.sessionId,{expiresAt:o,expiryConfiguredByHost:!0});const p=await Ge(l.sessionId);K(p),ns(!1)}catch(r){console.error("Failed to set expiration:",r),alert("Failed to set expiration time")}finally{Ds(!1)}},[l?.sessionId,ge,fe]),Te=n.useCallback(async()=>{try{const r=l?.sessionId||s;if(!r)return;ye(5),xe("Starting analysis…"),Ue(!0),await Xs(r,{agentType:"all",formatType:x.formatKey||"default-summary",visibility:"HOST"}),ye(10),xe("Pipeline accepted, waiting for first phase…");const o=3e3,p=2700*1e3,A=Math.ceil(p/o);let $=!1;const F=async()=>{const[M,se]=await Promise.all([ks(r),Zs(r)]);de(M),Oe(se),await ne()},J=M=>M==="synthesis"?"Synthesizing per-question insights…":M==="summary"?"Generating session summary…":M==="executive"?"Composing executive summary…":"Analyzing responses…";await new Promise(M=>{const se=async ae=>{if(!$){if($=!0,me.off("session:synthesis-updated",oe),window.clearInterval(zs),ae==="completed"){xe("Loading results…"),ye(98);try{await F()}catch{}}else ae==="failed"?xe("Analysis failed"):(xe("Still running on the server; refresh later"),ye(Qe=>Math.min(Qe,95)));M(ae)}},oe=async ae=>{ae.sessionId!==r||$||await se(ae.status==="FAILED"?"failed":"completed")};me.on("session:synthesis-updated",oe);let ke=0;const zs=window.setInterval(async()=>
32{if(ke++,$){window.clearInterval(zs);return}if(ke>A){await se("timeout");return}try{const ae=await ea(r);if(ae.status==="IDLE"){await se("completed");return}if(ae.status==="FAILED"){await se("failed");return}xe(J(ae.phase)),ye(Qe=>Math.max(Qe,Math.min(95,ae.progress)))}catch{}},o)})==="completed"&&(ye(100),xe("Done"))}catch(r){console.error("Failed to trigger analysis:",r),alert("Failed to trigger analysis. Please try again.")}finally{Ue(!1),window.setTimeout(()=>{ye(0),xe("")},500)}},[l?.sessionId,s,x.formatKey,me,ne]),St=n.useCallback(async()=>{try{const r=l?.sessionId||s;if(!r)return;Ue(!0),await Xs(r,{agentType:"summary"}),await ne()}catch(r){console.error("Failed to generate summary:",r),alert("Failed to generate summary. Please try again.")}finally{Ue(!1)}},[l?.sessionId,s,ne]),gs=n.useCallback(async()=>{if(confirm("Are you sure you want to stop accepting responses? This will end the session immediately."))try{await ve(l?.sessionId||s||"",{status:"CLOSED",expiresAt:new Date().toISOString()});const r=await Ge(l?.sessionId||s||"");K(r)}catch(r){console.error("Failed to close session:",r),alert("Failed to close session")}},[l?.sessionId,s]),Vs=n.useRef(!1);n.useEffect(()=>{Vs.current||j.get("guide")!=="close"||!k||(Vs.current=!0,k.status==="ACTIVE"&&gs())},[j,k,gs]);const Ct=n.useCallback(async r=>{E(o=>({...o,allowOpenJoin:r}));try{l?.sessionId&&await ve(l.sessionId,{allowOpenJoin:r})}catch(o){console.error("Failed to update participation mode:",o)}},[l?.sessionId]),fs=n.useCallback(async r=>{E(o=>({...o,...r}));try{l?.sessionId&&await ve(l.sessionId,r)}catch(o){console.error("Failed to update audience settings:",o)}},[l?.sessionId]),It=n.useCallback(async()=>{if(l?.sessionId)try{const r=await Ge(l.sessionId);K(r)}catch(r){console.error("Failed to refresh dashboard:",r)}},[l?.sessionId]),ue=n.useMemo(()=>ee.find(r=>r.key===x.formatKey),[ee,x.formatKey]),Js=n.useMemo(()=>(ue?.features??{}).topicListRequired===!0||x.formatKey==="reflective-intelligence-exercise",[ue,x.formatKey]),Hs=n.useMemo(()=>{const r=ue?.features??{};return typeof r.canonicalPrompt=="string"?r.canonicalPrompt:void 0},[ue]),Ve=b&&x.questionInput!==B.current,ys=n.useCallback(async()=>{if(!s)return!1;const r=x.questionInput.split(`
33`).map(o=>o.trim()).filter(Boolean);if(r.length===0)return Ne("Add at least one topic before saving."),!1;try{return $e(!0),Ne(null),await ve(s,{questionSet:r}),B.current=x.questionInput,le(Date.now()),!0}catch(o){let p="Saving topics failed. Please try again.";if(je.isAxiosError(o)){const A=o.response?.data;p=A?.message||A?.error||p}else o instanceof Error&&o.message&&(p=o.message);return Ne(p),!1}finally{$e(!1)}},[s,x.questionInput]);if(n.useEffect(()=>{b&&W!=="topics"&&Ve&&!Ce&&!re&&ys()},[W]),!T?.id)return e.jsx("div",{className:"flex min-h-screen flex-col items-center justify-center bg-stone-50 dark:bg-slate-950 p-6",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-900 p-8 text-center",children:[e.jsx("h1",{className:"mb-4 text-2xl font-bold text-slate-900 dark:text-slate-100",children:"Host Experience"}
33),e.jsx("p",{className:"mb-6 text-stone-600 dark:text-slate-400",children:"Please sign in to access the host dashboard."}),e.jsx("button",{onClick:()=>d("/"),className:"w-full rounded-lg bg-emerald-600 px-4 py-2 font-medium text-white hover:bg-emerald-500",children:"Sign In"})]})});if(!l?.sessionId){if(b)return e.jsxs(e.Fragment,{children:[e.jsx(De,{}),e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-stone-50 dark:bg-slate-950 text-sm text-stone-600 dark:text-slate-400",children:"Loading session…"})]});if(!I&&ee.length>0)return e.jsxs(e.Fragment,{children:[e.jsx(De,{}),e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-stone-50 dark:from-slate-950 via-stone-50 dark:via-slate-900 to-white dark:to-black",children:[e.jsx("div",{className:"border-b border-stone-200 dark:border-slate-800/50 px-4 py-6 backdrop-blur sm:px-8",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{to:"/host/home",className:"text-sm text-stone-600 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-200 transition",children:"Your work"})," / ",e.jsx("span",{className:"text-sm text-slate-800 dark:text-slate-200",children:"Choose Format"})]})}),e.jsxs("main",{className:"px-4 py-8 space-y-8 sm:px-8 sm:py-12 max-w-3xl mx-auto",children:[e.jsx("h1",{className:"text-3xl font-bold text-slate-900 dark:text-slate-100",children:"Choose a Format"}
33),e.jsx("p",{className:"text-sm text-stone-600 dark:text-slate-400",children:"Select the exercise format for your session. The format determines how participants respond and how analysis is performed."}),e.jsx("div",{className:"space-y-3",children:ee.map(p=>{const $=(p.features??{}).usesStudyContainer===!0;return e.jsxs("button",{onClick:()=>{w(p.key),E(F=>({...F,formatKey:p.key,promptPackId:p.defaults.promptPack.session??""}))},className:"w-full flex items-start gap-4 rounded-xl border border-stone-200 dark:border-slate-700 bg-white/85 dark:bg-slate-950/50 p-4 text-left hover:border-emerald-500 hover:bg-stone-100 dark:hover:bg-slate-900/50 transition",children:[e.jsx("div",{className:"text-2xl",children:$?"📊":p.type==="longitudinal"?"📅":"🎯"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-semibold text-slate-900 dark:text-slate-100",children:p.label}),$&&e.jsx("span",{className:"rounded-full bg-emerald-500/20 px-2 py-0.5 text-xs text-emerald-700 dark:text-emerald-300",children:"Study"})]}
33),e.jsx("p",{className:"mt-1 text-xs text-stone-600 dark:text-slate-400",children:p.description})]})]},p.key)})})]})]})]});if(hs)return e.jsxs(e.Fragment,{children:[e.jsx(De,{}),e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-stone-50 dark:from-slate-950 via-stone-50 dark:via-slate-900 to-white dark:to-black",children:[e.jsx("div",{className:"border-b border-stone-200 dark:border-slate-800/50 px-4 py-6 backdrop-blur sm:px-8",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{to:"/host/home",className:"text-sm text-stone-600 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-200 transition",children:"Your work"})," / ",e.jsx("span",{className:"text-sm text-slate-800 dark:text-slate-200",children:"Create New Study"})]})}),e.jsxs("main",{className:"px-4 py-8 space-y-8 sm:px-8 sm:py-12",children:[!Ps&&e.jsxs("button",{onClick:()=>{w(""),E(p=>({...p,formatKey:"",promptPackId:""})),U(et())},className:"text-sm text-stone-600 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-200 transition flex items-center gap-2",children:[e.jsx("span",{children:"←"})," Change format"]}),e.jsx(ba,{state:y,onStateChange:p=>U(A=>({...A,...p})),isLoading:L,isEditMode:!1,availablePanels:z}),g&&e.jsx("div",{className:"rounded-lg border border-rose-900 bg-rose-950/30 p-4 text-sm text-rose-400",children:g}),e.jsx("button",{onClick:bs,disabled:L||!y.title.trim()||y.wordList.length===0,className:"min-h-[44px] rounded-lg bg-emerald-600 px-6 py-3 text-base font-medium text-white hover:bg-emerald-500 disabled:bg-stone-300 dark:disabled:bg-slate-600",children:L?"Creating...":"Create Study"})]})]})]});const r=x.questionInput.split(`
34`).filter(p=>p.trim()).length,o=[{id:"setup",label:"Session Setup",icon:"⚙️",status:x.title.trim()?"ready":"attention",statusText:x.title.trim()?"Ready":"Title required"},{id:"topics",label:"Topics",icon:"💬",status:r>0?"ready":"attention",statusText:r>0?`${r} topic${r!==1?"s":""}`:"Add topics"},{id:"invite",label:"Invite",icon:"👥",status:"locked",statusText:"Create session first",locked:!0,separator:!0},{id:"review",label:"Responses",icon:"🔍",status:"locked",statusText:"Create session first",locked:!0},{id:"summaries",label:"Session Analysis",icon:"✨",status:"locked",statusText:"Create session first",locked:!0},{id:"align-ai",label:"Align your AI",icon:"🤖",status:"locked",statusText:"Create session first",locked:!0}];return e.jsxs(e.Fragment,{children:[e.jsx(De,{}),e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-stone-50 dark:from-slate-950 via-stone-50 dark:via-slate-900 to-white dark:to-black",children:[e.jsx("div",{className:"border-b border-stone-200 dark:border-slate-800/50 px-4 py-4 backdrop-blur sm:px-8",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{to:"/host/home",className:"text-sm text-stone-600 dar
34k:text-slate-400 hover:text-slate-900 dark:hover:text-slate-200 transition",children:"Your work"})," / ",e.jsx("span",{className:"text-sm text-slate-800 dark:text-slate-200",children:"Create New Session"})]})}),e.jsxs("div",{className:"flex flex-col md:flex-row min-h-0 flex-1",children:[e.jsx(rt,{items:o,activeId:W,onSelect:V}),e.jsx("main",{className:"flex-1 overflow-y-auto px-4 py-6 sm:px-8 sm:py-8",children:e.jsxs("div",{className:"mx-auto max-w-3xl space-y-6",children:[!Ps&&e.jsxs("button",{onClick:()=>{w(""),E(p=>({...p,formatKey:"",promptPackId:""}))},className:"text-sm text-stone-600 dark:text-slate-400 hover:text-slate-900 dark:hover:text-slate-200 transition flex items-center gap-2",children:[e.jsx("span",{children:"←"})," Change format"]}),W==="setup"&&e.jsxs(e.Fragment,{children:[e.jsx(nt,{title:x.title,description:x.description,aiInstructions:x.aiInstructions,formatPurpose:ue?.purposeDescription,formatSystemPrompt:ue?.systemPrompt,isLoading:L,onChange:p=>E(A=>({...A,...p}))}),e.jsxs("button",{type:"button",onClick:()=>V("topics"),className:"w-full min-h-[44px] rounded-lg bg-emerald-600 px-6 py-3 text-base font-medium text-white transition hover:bg-emerald-500 inline-flex items-center justify-center gap-2",children:["Next: Add Topics ",e.jsx("span",{children:"→"})]})]}),W==="topics"&&e.jsx(it,{questionInput:x.questionInput,isTopicListFormat:Js,canonicalPromptTemplate:Hs,isLoading:L,onChange:p=>E(A=>({...A,questionInput:p})),onCreateSession:bs,createButtonDisabled:!x.formatKey||!x.promptPackId,createButtonLoading:L,createError:g||void 0})]})})]})]})]})}const Je=k?.studyContext?.isStudySession,Q=k?.studyContext,Re=x.questionInput.split(`
35`).filter(r=>r.trim()).length,At=!Je&&!k?.programmeContext&&x.formatKey==="reflective-intelligence-exercise",He=x.hostAsParticipant&&(k?.participants?.completed??0)>=1,Ee=(k?.participants?.completed??0)>(x.hostAsParticipant?1:0),Qs=!!k?.tunedFromSessionId,Pt=!!(G&&Qs&&k?.status==="DRAFT"&&He&&!Ee),Tt=async()=>{if(G){h(!0),P(null);try{await ve(l.sessionId,{status:"ACTIVE"}),d(`/host/programmes/${G}?arrived=1`)}catch(r){P(r?.response?.data?.message??(r instanceof Error?r.message:"Could not open the round."))}finally{h(!1)}}},Rt=[...[{id:"setup",label:"Session Setup",icon:"⚙️",status:"ready",statusText:(()=>{if(k?.status){if(k.status==="ACTIVE"&&re){if(k.expiresAt){const r=new Date(k.expiresAt).getTime()-Date.now();if(r<=0)return"CLOSED";const o=Math.floor(r/(1e3*60*60*24)),p=Math.floor(r%(1e3*60*60*24)/(1e3*60*60));return o>0?`LIVE • ${o}d ${p}h left`:p>0?`LIVE • ${p}h left`:`LIVE • ${Math.floor(r%(1e3*60*60)/(1e3*60))}m left`}return"LIVE"}return Ns(k.status,k.expiresAt)}})()},{id:"topics",label:"Topics",icon:"💬",status:re?"locked":Re>0?"ready":"attention",statusText:re?`${Re} topic${Re!==1?"s":""} · Locked`:`${Re} topic${Re!==1?"s":""}`},...At?[{id:"participate",label:"Your Reflection",icon:"🎙️",status:He?"ready":"attention",statusText:He?"Reflection recorded":"Try it yourself first"}]:[],{id:"invite",label:"Invite",icon:"👥",status:re?"locked":(k?.participants?.invited??0)>0?"ready":"attention",statusText:re?k?.participants?`${k.participants.invited} joined · Locked`:"Locked":k?.participants?`${k.participants.invited} joined`:"Set up invites",separator:!0},{id:"review",label:"Responses",icon:"🔍",status:!te||te.length===0||te.some(o=>o.feedbackDecision==="REJECTED"||o.feedbackDecision==="ACCEPTED"?!1:!!(o.relevanceCheck&&(!o.relevanceCheck.relevant||o.relevanceCheck.confidence<.7)))?"attention":"ready",statusText:te?`${te.length} response${te.length!==1?"s":""}`:"No data"},{id:"summaries",label:"Session Analysis",icon:"✨",status:(()=>{if(S.length===0)return"attention";const r=te?.filter(A=>A.feedbackDecision!=="REJECTED").length??0,p=(X?.perQuestionRuns?Object.values(X.perQuestionRuns):[]).reduce((A,$)=>{const F=$?.dataset?.totals?.responses;return A+(typeof F=="number"?F:0)},0)||(X?.latestRun?.dataset?.totals?.responses??0);return r>p?"attention":"ready"})(),statusText:(()=>{if(S.length===0)return"Not generated";const r=S[0]?.summary?.visibility,o=te?.filter(J=>J.feedbackDecision!=="REJECTED").length??0,A=(X?.perQuestionRuns?Object.values(X.perQuestionRuns):[]).reduce((J,ie)=>{const M=ie?.dataset?.totals?.responses;return J+(typeof M=="number"?M:0)},0)||(X?.latestRun?.dataset?.totals?.responses??0),$=o>A,F=r==="PARTICIPANT"?"Participants":r==="PUBLIC"?"Public":r==="PUBLIC_UNLISTED"?"Public (unlisted)":"Host Only";return $?`${F} · Outdated`:F})()},{id:"align-ai",label:"Align your AI",icon:"🤖",status:S.length>0?"ready":"locked",statusText:(()=>
35{if(S.length===0)return"After the analysis";const r=k?.constitution?.conceptCount;return r?`${r} concept${r===1?"":"s"} ready for your AI`:"Beta · your shared language, for your AI"})()}].filter(r=>!be?.has(r.id)&&(r.id!=="align-ai"||Ee)),...Be?[{id:"participation",label:"Participation",icon:"🌐",status:"ready",statusText:"Languages · audience"}]:[]];return e.jsxs(e.Fragment,{children:[e.jsx(De,{}),e.jsxs("div",{className:"w-full min-h-screen bg-gradient-to-br from-stone-50 dark:from-slate-950 via-stone-50 dark:via-slate-900 to-white dark:to-black",children:[G&&e.jsx("div",{className:"px-4 pt-4 sm:px-8",children:e.jsx(q,{to:`/host/programmes/${G}`,className:"text-xs text-stone-500 transition-colors hover:text-stone-700 dark:text-slate-400 dark:hover:text-slate-200",children:"← Back to the programme"})}),T?.role==="SUPERADMIN"&&k?.hostUserId&&k.hostUserId!==T.id&&e.jsxs("div",{className:"mx-4 mt-4 rounded-xl border border-amber-400 bg-amber-50 px-4 py-3 text-sm text-amber-900 sm:mx-8",children:[e.jsx("span",{className:"font-semibold",children:"Superadmin view · read-only."})," This is another host's session, shown exactly as the host sees it. Do not press anything that generates, shares or closes."]}),Je&&Q&&e.jsx("div",{className:"w-full bg-emerald-950/50 border-b border-emerald-500/30 px-4 py-3 sm:px-8",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:"📊"}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-medium text-emerald-800 dark:text-emerald-200",children:["Study Session: Day ",Q.dayIndex+1]}),e.jsxs("div",{className:"text-xs text-emerald-700 dark:text-emerald-400",children:["This session is part of ",e.jsx(q,{to:`/host/studies/${Q.studyId}`,className:"underline hover:text-emerald-800 dark:hover:text-emerald-200",children:Q.studyTitle})]})]})]}),e.jsx(q,{to:`/host/studies/${Q.studyId}`,className:"rounded-lg bg-emerald-600/50 border border-emerald-500/50 px-4 py-2 text-sm font-medium text-white hover:bg-emerald-600 transition",children:"← Back to Study"})]})}),l?.sessionId&&e.jsx("div",{className:"w-full border-b border-stone-200 dark:border-slate-800/50 px-4 py-3 sm:px-8",children:e.jsx("div",{className:"text-sm text-stone-600 dar
35k:text-slate-400",children:Je&&Q?e.jsxs(e.Fragment,{children:[e.jsx(q,{to:"/host/home",className:"hover:text-slate-900 dark:hover:text-slate-200 transition",children:"Your work"})," / ",e.jsx(q,{to:`/host/studies/${Q.studyId}`,className:"hover:text-slate-900 dark:hover:text-slate-200 transition",children:Q.studyTitle})," / ",e.jsxs("span",{className:"text-slate-800 dark:text-slate-200",children:["Day ",Q.dayIndex+1,": ",Q.word]})]}):G?e.jsxs(e.Fragment,{children:[e.jsx(q,{to:"/host/home",className:"hover:text-slate-900 dark:hover:text-slate-200 transition",children:"Your work"})," / ",e.jsx(q,{to:`/host/programmes/${G}`,className:"hover:text-slate-900 dark:hover:text-slate-200 transition",children:"Programme"})," / ",e.jsxs("span",{className:"text-slate-800 dark:text-slate-200",children:[k?.title||"Round"," · full report"]})]}):we?e.jsxs(e.Fragment,{children:[e.jsx(q,{to:"/host/home",className:"hover:text-slate-900 dark:hover:text-slate-200 transition",children:"Your work"})," / ",e.jsx(q,{to:`/host/exercises/${l.sessionId}`,className:"hover:text-slate-900 dark:hover:text-slate-200 transition",children:k?.title||"Exercise"})," / ",e.jsx("span",{className:"text-slate-800 dark:text-slate-200",children:"Full report"})]}):e.jsxs(e.Fragment,{children:[e.jsx(q,{to:"/host/home",className:"hover:text-slate-900 dark:hover:text-slate-200 transition",children:"Your work"})," / ",e.jsx("span",{className:"text-slate-800 dark:text-slate-200",children:k?.title||"Session"})]})})}),e.jsxs("div",{className:"flex flex-col md:flex-row",children:[e.jsx(rt,{items:Rt,activeId:W,onSelect:V}),e.jsxs("main",{className:"flex-1 overflow-y-auto px-4 py-8 sm:px-8 sm:py-10 space-y-6",children:[W==="setup"&&!be?.has("setup")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/40 p-4 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"font-serif text-2xl font-bold text-slate-900 dark:text-white",children:k?.title||"Session"}),k?.status&&e.jsx("span",{className:`inline-flex rounded-full px-3 py-1 text-xs uppercase tracking-wide font-medium ${mt[k.status]}`,children:Ns(k.status,k.expiresAt)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[(k?.status==="ACTIVE"||k?.status==="DRAFT")&&e.jsx("button",{onClick:gs,className:"rounded-lg border border-rose-600/50 bg-rose-600/10 px-3 py-1.5 text-xs font-medium text-rose-300 hover:bg-rose-600/20 transition whitespace-nowrap",children:"Close Session"}),e.jsx("button",{onClick:Nt,className:"rounded-lg border border-amber-600/50 bg-amber-600/10 px-3 py-1.5 text-xs font-medium text-amber-300 hover:bg-amber-600/20 transition whitespace-nowrap",children:"Set Expiration"})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2 text-sm text-stone-600 dar
35k:text-slate-400",children:e.jsx("span",{children:ee.find(r=>r.key===x.formatKey)?.label})})]}),e.jsxs("div",{className:"grid gap-3 grid-cols-2 sm:grid-cols-4",children:[e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 p-3",children:[e.jsx("div",{className:"text-xs text-stone-600 dark:text-slate-400",children:"Participants"}),e.jsx("div",{className:"mt-1 text-base font-semibold text-slate-900 dark:text-slate-100",children:k?.participants?.invited??"–"})]}),e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 p-3",children:[e.jsx("div",{className:"text-xs text-stone-600 dark:text-slate-400",children:"Responses"}),e.jsx("div",{className:"mt-1 text-base font-semibold text-slate-900 dark:text-slate-100",children:te?.length??"–"})]}),e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 p-3",children:[e.jsx("div",{className:"text-xs text-stone-600 dar
35k:text-slate-400",children:"Summaries"}),e.jsx("div",{className:"mt-1 text-base font-semibold text-slate-900 dark:text-slate-100",children:S.length>0?S.length:"–"})]}),e.jsxs("div",{className:"rounded-lg border border-stone-200 dark:border-slate-800 bg-white dark:bg-slate-950/60 p-3",children:[e.jsx("div",{className:"text-xs text-stone-600 dark:text-slate-400",children:"Visibility"}),e.jsx("div",{className:"mt-1 text-base font-semibold text-slate-900 dark:text-slate-100",children:(()=>{const o=(pe?S.find(p=>p.summary?.id===pe):S[0])?.summary?.visibility;return o==="PUBLIC"?"Public":o==="PUBLIC_UNLISTED"?"Public (unlisted)":o==="PARTICIPANT"?"Participants":o==="HOST"?"Host only":"–"})()})]})]}),Je?e.jsx("div",{className:"rounded-lg bg-emerald-50 dark:bg-emerald-950/30 border border-emerald-500/30 p-4 text-sm text-emerald-800 dark:text-emerald-200",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"text-lg",children:"📊"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"This is a Study Session"}),e.jsxs("p",{className:"mt-1 text-emerald-700 dark:text-emerald-300",children:["Configuration is managed at the study level.",Q&&e.jsxs(e.Fragment,{children:[" ","Go to the"," ",e.jsx(q,{to:`/host/studies/${Q.studyId}`,className:"underline hover:text-slate-900 dark:hover:text-white",children:"Study Settings"})," ","to modify settings."]})]}),Q&&e.jsxs("div",{className:"mt-3 grid gap-2 text-xs text-emerald-700 dark:text-emerald-400",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Study:"})," ",Q.studyTitle]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Day:"})," ",Q.dayIndex+1]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Word:"})," ",Q.word]})]})]})]})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(nt,{title:x.title,de
35scription:x.description,aiInstructions:x.aiInstructions,formatPurpose:ue?.purposeDescription,formatSystemPrompt:ue?.systemPrompt,isLoading:L,onChange:r=>E(o=>({...o,...r}))}),g&&e.jsx("div",{className:"text-sm text-rose-400",children:g}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{onClick:bs,disabled:L,className:"min-h-[44px] rounded-lg bg-emerald-600 px-6 py-3 text-base font-medium text-white hover:bg-emerald-500 disabled:bg-stone-300 dark:disabled:bg-slate-600",children:L?"Saving...":"Save session settings"}),e.jsxs("button",{type:"button",onClick:()=>V("topics"),className:"min-h-[44px] rounded-lg border border-stone-200 dark:border-slate-700 bg-stone-100 dark:bg-slate-800/50 px-5 py-3 text-sm font-medium text-stone-700 dark:text-slate-300 transition hover:bg-stone-100 dark:hover:bg-slate-700/50 inline-flex items-center gap-2",children:["Topics ",e.jsx("span",{className:"text-stone-500 dark:text-slate-500",children:"→"})]})]})]})]}),W==="topics"&&!be?.has("topics")&&e.jsxs(e.Fragment,{children:[e.jsx(it,{questionInput:x.questionInput,isTopicListFormat:Js,canonicalPromptTemplate:Hs,isLoading:L,readOnly:re,onChange:r=>{Ne(null),E(o=>({...o,questionInput:r}))},onSaveTopics:()=>void ys(),saveDirty:Ve,saveLoading:Ce,saveError:Le,savedRecently:Xe!==null&&!Ve}),!re&&e.jsx("button",{onClick:()=>{(async()=>Ve&&!await ys()||V("invite"))()},disabled:Ce,className:"min-h-[44px] w-full rounded-lg bg-emerald-600 px-6 py-3 text-base font-medium text-white hover:bg-emerald-500 inline-flex items-center justify-center gap-2 disabled:cursor-not-allowed disabled:bg-stone-300 dark:disabled:bg-slate-700 disabled:text-stone-600 dar
35k:text-slate-400",children:Ce?"Saving topics…":e.jsxs(e.Fragment,{children:["Next: Invite Participants ",e.jsx("span",{children:"→"})]})})]}),W==="participate"&&!be?.has("participate")&&e.jsx(ca,{sessionId:l.sessionId,showTune:!0,joinUrl:l.shareInfo?.shareCode?`${window.location.origin}/join/${l.shareInfo.shareCode}`:null,hostAsParticipant:x.hostAsParticipant,hostHasResponded:He,hasAnalysis:S.length>0,analysisRunning:Pe,analysisProgress:ds,analysisPhase:cs,onEnableHostParticipation:()=>fs({hostAsParticipant:!0}),onTriggerAnalysis:Te,onCheckForResponse:It,onGoToResults:()=>V("summaries"),onGoToInvite:()=>V("invite"),onReviewExercise:()=>V("topics"),keyQuestions:t}),W==="invite"&&!be?.has("invite")&&e.jsx(da,{sessionId:l.sessionId,shareCode:l.shareInfo?.shareCode??null,allowOpenJoin:x.allowOpenJoin,visibility:x.visibility,onAllowOpenJoinChange:Ct,isLive:re,onMakeLive:()=>Es(!0),onGoToResponses:()=>V("review"),readOnly:re,acceptedResponseLanguages:x.acceptedResponseLanguages||["en"],insightLanguages:x.insightLanguages||["en"],hostAsParticipant:x.hostAsParticipant,minGroupSize:x.minGroupSize??null,onAudienceChange:fs,inviteContext:x.inviteContext}),W==="participation"&&Be&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl border border-stone-200 bg-white/85 p-4 dark:border-slate-800 dark:bg-slate-950/40 sm:p-6",children:[e.jsx("h1",{className:"font-serif text-2xl font-bold text-slate-900 dark:text-white",children:"Participation"}
35),e.jsxs("p",{className:"mt-1 text-sm text-stone-600 dark:text-slate-400",children:["These settings apply to this measurement only. The participant list itself lives in"," ",e.jsx("a",{href:`/host/programmes/${k?.programmeContext?.programmeId}`,className:"text-emerald-700 hover:text-emerald-600 dark:text-emerald-300 dark:hover:text-emerald-200",children:"the programme home"}),", and every measurement invites the same people."]})]}),e.jsx(Bt,{acceptedResponseLanguages:x.acceptedResponseLanguages||["en"],insightLanguages:x.insightLanguages||["en"],hostAsParticipant:x.hostAsParticipant,visibility:x.visibility,onAudienceChange:fs})]}),W==="review"&&e.jsxs(e.Fragment,{children:[k&&e.jsx(dt,{dashboard:k,hasAnalysis:S.length>0,allowOpenJoin:x.allowOpenJoin,onGoToAnalysis:()=>V("summaries"),latestAnalysisAt:H,onRegenerateAnalysis:Te,analysisRunning:Pe}),e.jsx(Ca,{sessionId:l.sessionId,perResponseInsights:te,relevanceCoverage:bt,relevanceCoverageLoading:gt,responseRates:k?.responseRates,onTriggerAnalysis:Te,analysisRunning:Pe,analysisProgress:ds,analysisPhase:cs})]}),W==="summaries"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-xl border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/40 p-4 sm:p-6",children:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("h1",{className:"truncate font-serif text-2xl font-bold text-slate-900 dark:text-white",children:k?.title||"Session"}),k?.status&&e.jsx("span",{className:`inline-flex shrink-0 rounded-full px-3 py-1 text-xs uppercase tracking-wide font-medium ${mt[k.status]}`,children:Ns(k.status,k.expiresAt)})]}),k?.programmeContext&&e.jsx("a",{href:`/host/programmes/${k.programmeContext.programmeId}`,className:"shrink-0 text-sm text-emerald-700 hover:text-emerald-600 dark:text-emerald-300 dark:hover:text-emerald-200",children:"Setup, topic words and people live in the programme home →"}),G&&!k?.programmeContext?e.jsx("a",{href:`/host/programmes/${G}`,className:"shrink-0 text-sm text-emerald-700 hover:text-emerald-600 dark:text-emerald-300 dark:hover:text-emerald-200",children:"Setup, topic words and people live in the programme home →"}):we&&e.jsx("a",{href:`/host/exercises/${l.sessionId}`,className:"shrink-0 text-sm text-emerald-700 hover:text-emerald-600 dark:text-emerald-300 dark:hover:text-emerald-200",children:"Setup and topic words live in the exercise home →"})]})}),k&&e.jsx("div",{className:"mt-4",children:e.jsx(dt,{dashboard:k,hasAnalysis:S.length>0,allowOpenJoin:x.allowOpenJoin,latestAnalysisAt:H,onRegenerateAnalysis:Te,analysisRunning:Pe})}),e.jsx(ga,{sessionId:l.sessionId}),e.jsx(Ht,{onOpenRound:Pt?()=>void Tt():void 0,openBusy:c,openError:N,onInviteOthers:G?void 0:()=>V("invite"),onTuneFirst:Ee||Qs||G?void 0:()=>d(`/host/exercises/${l.sessionId}/tune`),onScheduleNext:Ee&&!G?()=>{m(r=>r+1),$a("talk-about-results")}:void 0}),Ee&&e.jsx(Qt,{conceptCount:k?.constitution?.conceptCount,onOpen:()=>V("align-ai")}),e.jsxs("div",{className:"mt-8 mb-2",children:[e.jsx("h2",{className:"font-serif text-xl text-emerald-900 dark:text-emerald-100",children:"The full report"}
35),e.jsx("p",{className:"mt-1 text-sm text-stone-600 dark:text-slate-400",children:"Everything the answers above were read from: this session's complete reading: purpose, what was said, themes and differences, response by response."})]}),e.jsx(Ma,{sessionId:l.sessionId,sessionTitle:k?.title||"Session",formatKey:x.formatKey,formats:ee,questionInput:x.questionInput,userRole:T?.role,synthesis:X,summaryList:S,selectedSummaryId:pe,summaryLoading:Z,summaryError:ss,publicShareLinks:ut,analysisRunning:Pe,analysisProgress:ds,analysisPhase:cs,summaryVisibilityUpdating:as,studyContext:k?.studyContext?{studyTitle:k.studyContext.studyTitle,totalDays:k.studyContext.totalDays}:null,isAiOnlyStudy:x.enableAiParticipants,createdAt:k?.createdAt,currentUserResponseId:X?.currentUserResponseId,onTriggerAnalysis:Te,onTriggerSummaryOnly:St,onSelectSummary:ft,onChangeVisibility:jt,onRefreshSummaries:yt,configuredVisibility:x.visibility,shareCode:l.shareInfo?.shareCode??null,sessionStatus:k?.status,slotAfterPurposeToc:e.jsx(Vt,{overlays:ce,minaCount:_e,arcCount:es,sessionId:l.sessionId,onShared:()=>{ne()},solo:Math.max(k?.participants?.started??0,k?.participants?.completed??0)<=1})}),kt&&e.jsx("div",{className:"mt-4 text-center",children:e.jsx("button",{onClick:vt,disabled:_s,className:"px-4 py-2 text-sm text-stone-600 dar
35k:text-slate-400 hover:text-slate-900 dark:hover:text-slate-200 border border-stone-200 dark:border-slate-700 hover:border-stone-400 dark:hover:border-slate-500 rounded-lg transition-colors disabled:opacity-50",children:_s?"Loading...":"Load older analysis runs"})}),!(x.hostAsParticipant&&(k?.participants?.completed??0)<=1)&&e.jsx("div",{id:"talk-about-results",className:"mt-10 border-t border-stone-200 dark:border-slate-800 pt-6",children:e.jsx(fa,{sessionId:l.sessionId,openRequested:R})})]}),W==="align-ai"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl border border-stone-200 dark:border-slate-800 bg-white/85 dark:bg-slate-950/40 p-4 sm:p-6",children:[e.jsx("h1",{className:"font-serif text-2xl font-bold text-slate-900 dark:text-white",children:"Align your AI"}),e.jsxs("p",{className:"mt-2 max-w-2xl text-sm text-stone-600 dark:text-slate-400",children:["Your group just built a shared language. These are the ways it keeps living in the AI tools you already use, so they speak about"," ",k?.title?`"${k.title}"`:"your topics"," ","the way your group actually does — two doors open today, three on the way."]})]}),e.jsx(zt,{sessionId:l.sessionId,onGoToResults:()=>V("summaries")})]})]})]}),ht&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30 dark:bg-black/50 backdrop-blur-sm",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-stone-200 dark:border-slate-700 bg-white dark:bg-slate-900 p-8 shadow-xl",children:[e.jsx("h2",{className:"text-2xl font-bold text-slate-900 dark:text-slate-100 mb-6",children:"Set Session Expiration"}),e.jsxs("div",{className:"space-y-4 mb-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-stone-700 dark:text-slate-300 mb-2",children:"Expiration Date"}),e.jsx("input",{type:"date",value:ge,onChange:r=>ls(r.target.value),className:"w-full rounded-lg border border-stone-200 dark:border-slate-700 bg-stone-50 dark:bg-slate-950 px-4 py-2 text-slate-900 dark:text-slate-100 focus:border-emerald-500 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-stone-700 dark:text-slate-300 mb-2",children:"Expiration Time"}),e.jsx("input",{type:"time",value:fe,onChange:r=>is(r.target.value),className:"w-full rounded-lg border border-stone-200 dark:border-slate-700 bg-stone-50 dark:bg-slate-950 px-4 py-2 text-slate-900 dark:text-slate-100 focus:border-emerald-500 focus:outline-none"})]}),e.jsxs("div",{className:"mt-4 p-3 rounded-lg bg-emerald-600/10 border border-emerald-500/30 text-sm text-emerald-800 dark:text-emerald-200",children:["Session will stop accepting responses at: ",e.jsx("br",{}),e.jsx("span",{className:"font-semibold",children:ge&&fe?new Date(`${ge}T${fe}`).toLocaleString():"Select date and time"})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>ns(!1),className:"flex-1 rounded-lg border border-stone-300 dark:border-slate-600 bg-stone-100 dark:bg-slate-800 px-4 py-2 font-medium text-slate-800 dark:text-slate-200 hover:bg-stone-200 dark:hover:bg-slate-700 transition",disabled:os,children:"Cancel"}),e.jsx("button",{onClick:wt,disabled:os||!ge||!fe,className:"flex-1 rounded-lg bg-emerald-600 px-4 py-2 font-medium text-white hover:bg-emerald-500 transition disabled:bg-stone-300 dark:disabled:bg-slate-600",children:os?"Setting...":"Set Expiration"})]})]})}),We&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/30 dark:bg-black/50",children:e.jsxs("div",{className:"rounded-lg bg-white dark:bg-slate-900 border border-stone-200 dark:border-slate-700 max-w-md w-full mx-4 p-6",children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-white mb-2",children:"Share Summary with Participants?"}),e.jsx("p",{className:"text-sm text-stone-700 dark:text-slate-300 mb-6",children:"All participants with known email addresses will be notified that the session results are now available."}),e.jsxs("div",{className:"bg-stone-100 dark:bg-slate-800/50 border border-stone-200 dark:border-slate-700 rounded p-3 mb-6",children:[e.jsx("p",{className:"text-xs text-stone-600 dar
35k:text-slate-400 mb-2",children:"Participants will receive:"}),e.jsx("p",{className:"text-sm text-slate-800 dark:text-slate-200",children:"📧 Email notification with link to view results"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>rs(null),className:"flex-1 rounded-lg border border-stone-300 dark:border-slate-600 bg-stone-100 dark:bg-slate-800 px-4 py-2 font-medium text-slate-800 dark:text-slate-200 hover:bg-stone-200 dark:hover:bg-slate-700 transition",children:"Cancel"}),e.jsx("button",{onClick:async()=>{We&&(await Us(We.summaryId,We.visibility),rs(null))},disabled:as!==null,className:"flex-1 rounded-lg bg-emerald-600 px-4 py-2 font-medium text-white hover:bg-emerald-500 transition disabled:bg-stone-300 dark:disabled:bg-slate-600",children:as?"Sending...":"Yes, Share Now"})]})]})})]})]})},kr=()=>e.jsx(Dt,{mode:"light",children:e.jsx(Oa,{})});export{kr as default};
36//# sourceMappingURL=HostExperiencePage-DoNKGeHK.js.map

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.