1import{r as n,j as e}from"./react-2yNL-0jO.js";import{d as xt,a as mt,L as qe}from"./react-router-C95oXNrA.js";import{s as y,u as G,a as D,B as H,D as de,C as ce,E as oe,G as xe,I as ee,T as se,J as me,K as ve,i as Te,h as ut,P as ht,Q as pt}from"./index-0I6tP8u4.js";import{C as U}from"./card-Dyz-4WUa.js";import{L as A}from"./label-BEk_pbj2.js";import{S as K,a as Z,b as X,c as Q,d as L}from"./select-Y_CU5rpp.js";import{T as gt,a as jt,b as bt,c as le}from"./tabs-Cnnn7Sz2.js";import{S as Fe,a as Me,b as ye,c as we}from"./sheet-3vQ-Z1K-.js";import{u as ft,F as vt}from"./FormDataDisplay-WhvXq6xn.js";import{P as ze,S as _t,R as Re,b as Nt,a as yt}from"./RequestHistory-D_1BrXsL.js";import{r as Ee}from"./roles-lceJk4Rh.js";import{ae as $e,ac as ge,Z as je,q as Ve,I as Ue,W as We,X as Je,be,bT as He,k as _e,l as wt,bI as kt,aJ as St,aq as Ae,O as he,V as Ct,d as Dt,aO as Tt,aI as $t,u as Ge,ar as At,P as Pt,af as Bt,b2 as It,an as Ot,aj as qt,aL as Lt,av as Le,as as Ft,al as Mt,r as zt}from"./lucide-YE_Cg0sW.js";import{m as Ke,c as Ze}from"./health-D-fxIjPZ.js";import{S as Rt}from"./switch-BsEXM-pL.js";import{c as Et,a as Vt,s as Ut,b as Wt,r as Jt}from"./feedback-v-95IB6_.js";import{u as Ht}from"./useChatPanel-b_vcMbNQ.js";import"./admin-vendor-CGWxZvmW.js";import"./ui-vendor-C2kPg7wM.js";import"./date-fns-VUYwK_nv.js";function Gt(){return Math.random().toString(36).slice(2,10)}async function Kt(t,i,l){const u=`${i}/${l}/${Gt()}-${t.name}`,{error:o}=await y.storage.from("onboarding-files").upload(u,t,{contentType:t.type});if(o)throw o;return u}async function Zt(t){const{data:i,error:l}=await y.storage.from("onboarding-files").createSignedUrl(t,3600);if(l||!(i!=null&&i.signedUrl))throw l||new Error("Could not generate a link for this file");window.open(i.signedUrl,"_blank","noopener")}const Xt=["pending","in_progress","blocked","complete"];function Qt({clientId:t,companyId:i,userId:l,canDelete:u,tasks:o,pendingItems:w,techRequests:v,stages:h,team:p,onChanged:a,onAddTask:N}){const{toast:b}=G(),[m,f]=n.useState(null),[P,k]=n.useState(!1),[d,j]=n.useState(null),g=new Date().toISOString().slice(0,10),O=o.filter(s=>s.status==="complete").length,C=w.filter(s=>s.status==="pending"),M=w.filter(s=>s.status!=="pending"),J=v.filter(s=>s.status!=="verified"),R=v.filter(s=>s.status==="verified"),E=s=>Math.floor((Date.now()-new Date(s.created_at).getTime())/864e5),S=s=>E(s)>3||s.due_date&&s.due_date<g,_=async(s,x)=>{await y.from("onboarding_tasks").update({status:x,completed_at:x==="complete"?new Date().toISOString():null}).eq("id",s),a()},B=async(s,x)=>{const{error:F}=await y.from("onboarding_pending_items").update({status:x,received_at:x==="received"?new Date().toISOString():null}).eq("id",s);if(F){b({title:"Update failed",description:F.message,variant:"destructive"});return}b({title:x==="received"?"Marked received":"Item cancelled"}),a()},$=async s=>{if(!confirm(`Delete "${s.title}"? This cannot be undone.`))return;const{error:x}=await y.from("onboarding_pending_items").delete().eq("id",s.id);if(x){b({title:"Delete failed",description:x.message,variant:"destructive"});return}b({title:"Item deleted"}),f(null),a()},q=(m==null?void 0:m.kind)==="task"?o.find(s=>s.id===m.id):null,V=(m==null?void 0:m.kind)==="pending"?w.find(s=>s.id===m.id):null,T=(m==null?void 0:m.kind)==="tech"?v.find(s=>s.id===m.id):null;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"font-bold text-slate-900",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:["Tasks ",e.jsxs("span",{className:"text-sm text-slate-400 font-normal ml-2",children:[O," of ",o.length," completed · ",C.length," from client · ",J.length," tech open"]})]}),e.jsxs(D,{size:"sm",className:"bg-[#BA3873] hover:bg-[#a02e62]",onClick:()=>k(!0),children:[e.jsx($e,{className:"h-4 w-4 mr-1"})," New Task"]})]}),e.jsxs("div",{className:"flex gap-3 overflow-x-auto pb-2",children:[Xt.map(s=>e.jsx(De,{title:s.replace("_"," "),count:o.filter(x=>x.status===s).length,children:o.filter(x=>x.status===s).map(x=>{const F=x.status!=="complete"&&x.due_date&&x.due_date<g;return e.jsxs(U,{className:"p-3 space-y-2 hover:shadow-sm transition-shadow cursor-pointer",onClick:()=>f({kind:"task",id:x.id}),children:[e.jsx("p",{className:"text-sm font-medium text-slate-800 leading-snug",children:x.title}),e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(H,{variant:"outline",className:"text-[10px]",children:Ee(x.assigned_role)}),x.priority==="high"&&e.jsx(H,{className:"text-[10px] bg-amber-100 text-amber-700 hover:bg-amber-100 border-amber-200",children:"High"})]}),x.due_date&&e.jsxs("p",{className:`text-[10px] flex items-center gap-1 ${F?"text-rose-600 font-bold":"text-slate-400"}`,children:[e.jsx(ge,{className:"h-2.5 w-2.5"}),"Due ",x.due_date]}),e.jsx("div",{onClick:ae=>ae.stopPropagation(),children:e.jsxs(K,{value:x.status,onValueChange:ae=>_(x.id,ae),children:[e.jsx(Z,{className:"h-7 text-xs",children:e.jsx(X,{})}),e.jsxs(Q,{children:[e.jsx(L,{value:"pending",children:"Pending"}),e.jsx(L,{value:"in_progress",children:"In Progress"}),e.jsx(L,{value:"blocked",children:"Blocked"}),e.jsx(L,{value:"complete",children:"Complete"})]})]})})]},x.id)})},s)),e.jsxs(De,{title:"Pending from Client",count:C.length,children:[C.map(s=>{const x=S(s),F=E(s);return e.jsxs(U,{className:`p-3 space-y-2 hover:shadow-sm transition-shadow cursor-pointer ${x?"border-rose-200 bg-rose-50/40":""}`,onClick:()=>f({kind:"pending",id:s.id}),children:[e.jsx("p",{className:"text-sm font-medium text-slate-800 leading-snug",children:s.title}),e.jsxs("p",{className:`text-[10px] flex items-center gap-1 ${x?"text-rose-600 font-bold":"text-slate-400"}`,children:[e.jsx(ge,{className:"h-2.5 w-2.5"})," Waiting ",F===0?"since today":`${F} day${F===1?"":"s"}`,s.due_date?` · Due ${s.due_date}`:""]}),e.jsxs(D,{size:"sm",className:"h-7 w-full text-xs bg-emerald-600 hover:bg-emerald-700",onClick:ae=>{ae.stopPropagation(),B(s.id,"received")},children:[e.jsx(je,{className:"h-3 w-3 mr-1"})," Mark Received"]})]},s.id)}),M.map(s=>e.jsxs(U,{className:"p-3 opacity-60 cursor-pointer hover:opacity-80",onClick:()=>f({kind:"pending",id:s.id}),children:[e.jsx("p",{className:"text-sm text-slate-600 line-through leading-snug",children:s.title}),e.jsx(H,{variant:"outline",className:`text-[10px] capitalize mt-1 ${s.status==="received"?"text-emerald-700 border-emerald-200 bg-emerald-50":"text-slate-500"}`,children:s.status})]},s.id))]}),e.jsxs(De,{title:"Tech Request",count:J.length,children:[J.map(s=>e.jsxs(U,{className:"p-3 space-y-1.5 hover:shadow-sm transition-shadow cursor-pointer",onClick:()=>f({kind:"tech",id:s.id}),children:[e.jsx("p",{className:"text-sm font-medium text-slate-800 leading-snug",children:s.title}),e.jsxs("div",{className:"flex flex-wrap gap-1 items-center",children:[e.jsx(ze,{priority:s.priority}),e.jsx(H,{variant:"outline",className:"text-[10px]",children:_t[s.status]||s.status})]}),s.eta_date&&e.jsxs("p",{className:`text-[10px] flex items-center gap-1 ${s.eta_date<g&&s.status!=="deployed"?"text-rose-600 font-bold":"text-slate-400"}`,children:[e.jsx(ge,{className:"h-2.5 w-2.5"})," ETA ",s.eta_date]})]},s.id)),R.map(s=>e.jsxs(U,{className:"p-3 opacity-60 cursor-pointer hover:opacity-80",onClick:()=>f({kind:"tech",id:s.id}),children:[e.jsx("p",{className:"text-sm text-slate-600 line-through leading-snug",children:s.title}),e.jsx(H,{variant:"outline",className:"text-[10px] mt-1 text-emerald-700 border-emerald-200 bg-emerald-50",children:"Verified"})]},s.id))]})]}),e.jsx(Fe,{open:!!(q||V||T),onOpenChange:s=>!s&&f(null),children:e.jsxs(Me,{className:"overflow-y-auto sm:max-w-md",children:[q&&e.jsx(Yt,{task:q,tasks:o,stages:h,team:p,onStatusChange:_}),V&&e.jsx(es,{item:V,team:p,canDelete:u,onSetStatus:B,onDelete:$,onChanged:a},V.id),T&&e.jsx(ts,{request:T,team:p,userId:l,onChanged:a},T.id)]})}),e.jsx(de,{open:P,onOpenChange:k,children:e.jsxs(ce,{className:"max-w-sm",children:[e.jsx(oe,{children:e.jsx(xe,{children:"What do you want to add?"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{className:"w-full p-3 border rounded-lg hover:border-pink-300 hover:bg-pink-50/30 flex items-center gap-3 text-left",onClick:()=>{k(!1),N()},children:[e.jsx(Ve,{className:"h-5 w-5 text-[#BA3873] shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-sm",children:"Internal Task"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Assign to the team with stage, due date and priority"})]})]}),e.jsxs("button",{className:"w-full p-3 border rounded-lg hover:border-amber-300 hover:bg-amber-50/30 flex items-center gap-3 text-left",onClick:()=>{k(!1),j("pending")},children:[e.jsx(Ue,{className:"h-5 w-5 text-amber-600 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-sm",children:"Pending from Client"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Something we're waiting to re
1ceive from the client"})]})]}),e.jsxs("button",{className:"w-full p-3 border rounded-lg hover:border-blue-300 hover:bg-blue-50/30 flex items-center gap-3 text-left",onClick:()=>{k(!1),j("tech")},children:[e.jsx(We,{className:"h-5 w-5 text-blue-600 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-sm",children:"Tech Request"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Bug, feature or integration for the tech team"})]})]})]})]})}),e.jsx(ss,{open:d==="pending",onClose:()=>j(null),clientId:t,companyId:i,userId:l,onCreated:a}),e.jsx(as,{open:d==="tech",onClose:()=>j(null),clientId:t,companyId:i,userId:l,onCreated:a})]})}function De({title:t,count:i,children:l}){return e.jsxs("div",{className:"bg-slate-50/60 rounded-lg p-3 w-60 shrink-0",children:[e.jsxs("div",{className:"text-[10px] font-bold uppercase tracking-wider mb-3 text-slate-500 flex items-center justify-between",children:[e.jsx("span",{children:t}),e.jsx("span",{className:"bg-white px-1.5 py-0.5 rounded text-slate-600",children:i})]}),e.jsx("div",{className:"space-y-2",children:l})]})}function Yt({task:t,tasks:i,stages:l,team:u,onStatusChange:o}){const w=u.find(p=>p.id===t.assigned_to),v=l.find(p=>p.id===t.stage_id),h=t.depends_on_task_id?i.find(p=>p.id===t.depends_on_task_id):null;return e.jsxs(e.Fragment,{children:[e.jsx(ye,{children:e.jsx(we,{children:t.title})}),e.jsxs("div",{className:"space-y-4 mt-4 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx(H,{variant:"outline",className:"text-[10px]",children:Ee(t.assigned_role)}),e.jsxs(H,{variant:"outline",className:`text-[10px] capitalize ${t.priority==="high"?"bg-amber-100 text-amber-700 border-amber-200":""}`,children:[t.priority," priority"]}),t.is_visible_to_client&&e.jsx(H,{variant:"outline",className:"text-[10px]",children:"Visible to client"})]}),t.description&&e.jsx("p",{className:"text-slate-600 whitespace-pre-wrap",children:t.description}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ue,{label:"Assigned to",value:(w==null?void 0:w.full_name)||"â"}),e.jsx(ue,{label:"Stage",value:(v==null?void 0:v.name)||"â"}),e.jsx(ue,{label:"Due date",value:t.due_date||"â"}),h&&e.jsx(ue,{label:"Depends on",value:h.title}),e.jsx(ue,{label:"Created",value:new Date(t.created_at).toLocaleString()}),t.completed_at&&e.jsx(ue,{label:"Completed",value:new Date(t.completed_at).toLocaleString()})]}),e.jsxs("div",{children:[e.jsx(A,{className:"text-xs",children:"Status"}),e.jsxs(K,{value:t.status,onValueChange:p=>o(t.id,p),children:[e.jsx(Z,{className:"mt-1",children:e.jsx(X,{})}),e.jsxs(Q,{children:[e.jsx(L,{value:"pending",children:"Pending"}),e.jsx(L,{value:"in_progress",children:"In Progress"}),e.jsx(L,{value:"blocked",children:"Blocked"}),e.jsx(L,{value:"complete",children:"Complete"})]})]})]})]})]})}function es({item:t,team:i,canDelete:l,onSetStatus:u,onDelete:o,onChanged:w}){const{toast:v}=G(),[h,p]=n.useState(t.title||""),[a,N]=n.useState(t.description||""),[b,m]=n.useState(t.due_date||""),[f,P]=n.useState(!1),k=Math.floor((Date.now()-new Date(t.created_at).getTime())/864e5),d=h!==(t.title||"")||a!==(t.description||"")||b!==(t.due_date||""),j=async()=>{if(!h.trim())return;P(!0);const{error:g}=await y.from("onboarding_pending_items").update({title:h.trim(),description:a.trim()||null,due_date:b||null}).eq("id",t.id);if(P(!1),g){v({title:"Could not save",description:g.message,variant:"destructive"});return}v({title:"Item updated"}),w()};return e.jsxs(e.Fragment,{children:[e.jsx(ye,{children:e.jsx(we,{children:"Pending from Client"})}),e.jsxs("div",{className:"space-y-4 mt-4 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{variant:"outline",className:`text-[10px] capitalize ${t.status==="received"?"text-emerald-700 border-emerald-200 bg-emerald-50":t.status==="pending"?"text-amber-700 border-amber-200 bg-amber-50":"text-slate-500"}`,children:t.status}),t.status==="pending"&&e.jsxs("span",{className:"text-[11px] text-slate-500 flex items-center gap-1",children:[e.jsx(ge,{className:"h-3 w-3"})," Waiting ",k===0?"since today":`${k} day${k===1?"":"s"}`]}),t.status==="received"&&t.received_at&&e.jsxs("span",{className:"text-[11px] text-emerald-600",children:["Received ",new Date(t.re
1ceived_at).toLocaleDateString()]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(A,{children:"Title *"}),e.jsx(ee,{value:h,onChange:g=>p(g.target.value)})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Description"}),e.jsx(se,{rows:2,value:a,onChange:g=>N(g.target.value)})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Due Date"}),e.jsx(ee,{type:"date",value:b,onChange:g=>m(g.target.value),className:"w-44"})]}),d&&e.jsx(D,{size:"sm",onClick:j,disabled:f||!h.trim(),className:"bg-[#BA3873] hover:bg-[#a02e62]",children:"Save Changes"})]}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[t.status==="pending"&&e.jsxs(e.Fragment,{children:[e.jsxs(D,{size:"sm",className:"h-8 text-xs bg-emerald-600 hover:bg-emerald-700",onClick:()=>u(t.id,"received"),children:[e.jsx(je,{className:"h-3.5 w-3.5 mr-1"})," Mark Received"]}),e.jsxs(D,{size:"sm",variant:"outline",className:"h-8 text-xs text-slate-600",onClick:()=>u(t.id,"cancelled"),children:[e.jsx(Je,{className:"h-3.5 w-3.5 mr-1"})," Cancel Item"]})]}),l&&e.jsxs(D,{size:"sm",variant:"ghost",className:"h-8 text-xs text-slate-400 hover:text-rose-600",onClick:()=>o(t),children:[e.jsx(be,{className:"h-3.5 w-3.5 mr-1"})," Delete"]})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[11px] font-semibold text-slate-500 flex items-center gap-1 mb-1",children:[e.jsx(He,{className:"h-3 w-3"})," History"]}),e.jsx(Re,{entityId:t.id,team:i})]})]})]})}function ts({request:t,team:i,userId:l,onChanged:u}){const o=new Date().toISOString().slice(0,10);return e.jsxs(e.Fragment,{children:[e.jsx(ye,{children:e.jsx(we,{children:"Tech Request"})}),e.jsxs("div",{className:"space-y-4 mt-4 text-sm",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"font-semibold text-slate-800",children:t.title}),e.jsx(ze,{priority:t.priority})]}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 whitespace-pre-wrap",children:t.description}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-1",children:["Submitted ",new Date(t.submitted_at).toLocaleDateString(),t.eta_date&&e.jsxs(e.Fragment,{children:[" · ETA ",e.jsx("b",{className:t.eta_date<o&&t.status!=="verified"&&t.status!=="deployed"?"text-rose-600":"text-slate-600",children:t.eta_date})]})]}),t.ack_notes&&e.jsxs("p",{className:"text-[11px] text-slate-500 mt-1",children:[e.jsx("b",{children:"Tech notes:"})," ",t.ack_notes]}),t.deployed_notes&&e.jsxs("p",{className:"text-[11px] text-violet-600 mt-1",children:[e.jsx("b",{children:"Deployed:"})," ",t.deployed_notes]}),t.rejection_note&&t.status==="in_progress"&&e.jsxs("p",{className:"text-[11px] text-rose-600 mt-1",children:[e.jsx("b",{children:"Sent back:"})," ",t.rejection_note]})]}),e.jsx(Nt,{request:t}),e.jsx(yt,{request:t,userId:l,onChanged:u}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[11px] font-semibold text-slate-500 flex items-center gap-1 mb-1",children:[e.jsx(He,{className:"h-3 w-3"})," History"]}),e.jsx(Re,{entityId:t.id,team:i})]})]})]})}function ss({open:t,onClose:i,clientId:l,companyId:u,userId:o,onCreated:w}){const{toast:v}=G(),[h,p]=n.useState(""),[a,N]=n.useState(""),[b,m]=n.useState(""),[f,P]=n.useState(!1),k=async()=>{if(!h.trim())return;P(!0);const{error:d}=await y.from("onboarding_pending_items").insert({company_id:u,client_id:l,title:h.trim(),description:a.trim()||null,due_date:b||null,created_by:o});if(P(!1),d){v({title:"Could not add item",description:d.message,variant:"destructive"});return}p(""),N(""),m(""),w(),i()};return e.jsx(de,{open:t,onOpenChange:d=>!d&&i(),children:e.jsxs(ce,{children:[e.jsx(oe,{children:e.jsx(xe,{children:"Pending from Client"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(A,{children:"What are we waiting for? *"}),e.jsx(ee,{value:h,onChange:d=>p(d.target.value),placeholder:"e.g. Logo files, bank details, API credentials"})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Description"}),e.jsx(se,{rows:2,value:a,onChange:d=>N(d.target.value)})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Due Date (optional)"}),e.jsx(ee,{type:"date",value:b,onChange:d=>m(d.target.value),className:"w-44"})]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:i,children:"Cancel"}),e.jsx(D,{className:"bg-[#BA3873] hover:bg-[#a02e62]",onClick:k,disabled:f||!h.trim(),children:"Save"})]})]})})}function as({open:t,onClose:i,clientId:l,companyId:u,userId:o,onCreated:w}){const{toast:v}=G(),[h,p]=n.useState(""),[a,N]=n.useState(""),[b,m]=n.useState("medium"),[f,P]=n.useState(!1),k=async()=>
1{if(!h.trim())return;P(!0);const{error:d}=await y.from("onboarding_tech_requests").insert({company_id:u,client_id:l,title:h.trim(),description:a.trim()||null,priority:b,submitted_by:o});if(P(!1),d){v({title:"Could not submit request",description:d.message,variant:"destructive"});return}v({title:"Request sent to tech team"}),p(""),N(""),m("medium"),w(),i()};return e.jsx(de,{open:t,onOpenChange:d=>!d&&i(),children:e.jsxs(ce,{children:[e.jsx(oe,{children:e.jsx(xe,{children:"New Tech Request"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(A,{children:"Title *"}),e.jsx(ee,{value:h,onChange:d=>p(d.target.value),placeholder:"Bug, feature, or integration needed"})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Description"}),e.jsx(se,{rows:3,value:a,onChange:d=>N(d.target.value),placeholder:"Steps to reproduce / what's needed and why"})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Priority"}),e.jsxs(K,{value:b,onValueChange:m,children:[e.jsx(Z,{className:"w-44",children:e.jsx(X,{})}),e.jsxs(Q,{children:[e.jsx(L,{value:"blocker",children:"Blocker"}),e.jsx(L,{value:"high",children:"High"}),e.jsx(L,{value:"medium",children:"Medium"}),e.jsx(L,{value:"low",children:"Low"})]})]})]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:i,children:"Cancel"}),e.jsx(D,{className:"bg-[#BA3873] hover:bg-[#a02e62]",onClick:k,disabled:f||!h.trim(),children:"Submit to Tech Team"})]})]})})}function ue({label:t,value:i}){return e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-slate-400 text-xs",children:t}),e.jsx("span",{className:"text-slate-700 text-xs font-medium text-right",children:i})]})}function ns({client:t,tasks:i,pendingItems:l,techRequests:u,trainings:o,docs:w,team:v,stages:h,milestoneDefs:p,milestoneProgress:a,onGoTo:N}){const b=new Date().toISOString().slice(0,10),m=t.onboarding_type==="trial",f=i.filter(r=>r.status==="complete").length,P=i.length?Math.round(f/i.length*100):0,k=i.filter(r=>r.status!=="complete"&&r.due_date&&r.due_date<b),d=l.filter(r=>r.status==="pending"),j=d.filter(r=>r.due_date&&r.due_date<b||(Date.now()-new Date(r.created_at).getTime())/864e5>3),g=u.filter(r=>r.status!=="verified"),O=g.filter(r=>r.priority==="blocker"||r.status==="submitted"||r.eta_date&&r.eta_date<b&&r.status!=="deployed"),C=o.filter(r=>r.status==="scheduled"),M=C[0]||null,J=o.filter(r=>r.status==="completed").length,R=i.filter(r=>r.status==="blocked"),E=t.enabled_modules||[],{achieved:S,total:_}=Ke(E,p,a),B=Ze(S,_,t.trial_end_date||null),$=t.trial_end_date?Math.ceil((new Date(t.trial_end_date).getTime()-Date.now())/864e5):null,q=E.map(r=>{const z=p.filter(ne=>ne.module_key===r),ke=new Set(a.filter(ne=>ne.module_key===r).map(ne=>ne.milestone_key));return{moduleKey:r,achieved:z.filter(ne=>ke.has(ne.milestone_key)).length,total:z.length}}).filter(r=>r.total>0),V=t.handoff_date||t.created_at,T=V?Math.max(0,Math.floor((Date.now()-new Date(V).getTime())/864e5)):null,s=v.find(r=>r.id===t.account_manager_id),x=h.find(r=>r.id===t.current_stage_id),F=[];m&&!t.converted_at&&$!==null&&$<=5&&F.push({icon:ge,iconClass:"text-rose-600 bg-rose-50",text:$<=0?"Trial has expired":`Trial expires in ${$} day${$===1?"":"s"}`,sub:`Ends ${t.trial_end_date}${_>0?` · ${B.pct}% adopted (${S}/${_})`:""} â convert or extend before it lapses`,urgent:!0,tab:"adoption",action:$<=0?"Act now":"Review"}),m&&E.length===0?F.push({icon:_e,iconClass:"text-amber-600 bg-amber-50",text:"No subscribed modules selected",sub:"Pick the client's eTaps modules to generate adoption milestones",urgent:!1,tab:"adoption",action:"Set up"}):m&&_>0&&B.label==="At Risk"&&F.push({icon:_e,iconClass:"text-rose-600 bg-rose-50",text:`Adoption at risk â ${S}/${_} milestones`,sub:"Push the next module milestone before the trial expires",urgent:!0,tab:"adoption",action:"Review"}),d.length>0&&F.push({icon:Ue,iconClass:j.length?"text-rose-600 bg-rose-50":"text-amber-600 bg-amber-50",text:`${d.length} item${d.length===1?"":"s"} waiting from client`,sub:j.length?`${j.length} overdue: ${j.slice(0,2).map(r=>r.title).join(", ")}${j.length>2?"â¦":""}`:d.slice(0,3).map(r=>r.title).join(", "),urgent:j.length>0,tab:"tasks",action:"Chase client"}),g.length>0&&F.push({icon:We,iconClass:O.length?"text-rose-600 bg-rose-50":"text-blue-600 bg-blue-50",text:`${g.length} open tech request${g.length===1?"":"s"}`,sub:O.length?O.slice(0,2).map(r=>r.title).join(", "):void 0,urgent:O.length>0,tab:"tasks",action:"View"}),M&&F.push({icon:wt,iconClass:"text-violet-600 bg-violet-50",text:`Training: ${M.title}`,sub:M.scheduled_date?`Scheduled ${M.scheduled_date}`:"No date set",urgent:!1,tab:"training",action:"Open"}),k.length>0&&F.push({icon:Ve,iconClass:"text-rose-600 bg-rose-50",text:`${k.length} overdue task${k.length===1?"":"s"}`,sub:k.slice(0,3).map(r=>r.title).join(", "),urgent:!0,tab:"tasks",action:"View tasks"}),R.length>0&&F.push({icon:kt,iconClass:"text-amber-600 bg-amber-50",text:`${R.length} blocked task${R.length===1?"":"s"}`,sub:`Waiting on a dependency â ${R.slice(0,2).map(r=>r.title).join(", ")}${R.length>2?"â¦":""}`,urgent:!1,tab:"tasks",action:"Unblock"});const ae=[...i].sort((r,z)=>(z.updated_at||z.created_at).localeCompare(r.updated_at||r.created_at)).slice(0,5);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(te,{label:"Tasks Done",value:`${f}/${i.length}`,tint:"text-emerald-600 bg-emerald-50"}),e.jsx(te,{label:"Overdue",value:k.length,tint:k.length>0?"text-rose-600 bg-rose-50":"text-slate-500 bg-slate-50"}),e.jsx(te,{label:"From Client",value:d.length,tint:j.length?"text-rose-600 bg-rose-50":"text-amber-600 bg-amber-50"}),e.jsx(te,{label:"Tech Open",value:g.length,tint:O.length?"text-rose-600 bg-rose-50":"text-blue-600 bg-blue-50"}),e.jsx(te,{label:"Documents",value:w.length,tint:"text-blue-600 bg-blue-50"}),e.jsx(te,{label:"Trainings",value:`${J}/${o.length}`,tint:C.length?"text-violet-600 bg-violet-50":"text-slate-500 bg-slate-50"}),T!==null&&e.jsx(te,{label:"Days in Onboarding",value:T,tint:"text-slate-600 bg-slate-50"}),e.jsx(te,{label:"Overall Progress",value:`${P}%`,tint:"text-[#BA3873] bg-pink-50"}),m&&e.jsx(te,{label:_>0?`Trial Adoption · ${B.label}`:"Trial Adoption · No modules",value:_>0?`${B.pct}%`:"â",tint:_===0?"text-slate-500 bg-slate-50":B.label==="On Track"?"text-emerald-600 bg-emerald-50":B.label==="Needs Attention"?"text-amber-600 bg-amber-50":"text-rose-600 bg-rose-50"}),m&&$!==null&&e.jsx(te,{label:"Trial Days Left",value:$<=0?"Expired":$,tint:$<=0?"text-rose-600 bg-rose-50":$<=3?"text-amber-600 bg-amber-50":"text-emerald-600 bg-emerald-50"}
1),m&&$===null&&!t.converted_at&&e.jsx(te,{label:`Trial · ${t.trial_length_days||14}d`,value:"Not started",tint:"text-slate-500 bg-slate-50"})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"font-bold text-slate-900 mb-3",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:["Needs Attention",F.some(r=>r.urgent)&&e.jsx(St,{className:"h-4 w-4 text-rose-500 inline ml-2 mb-0.5"})]}),F.length===0?e.jsx("div",{className:"text-center py-8 border-2 border-dashed border-emerald-200 bg-emerald-50/30 rounded-lg text-sm text-emerald-700 font-medium",children:"All clear â nothing waiting on this client right now. ð"}):e.jsx("div",{className:"space-y-2",children:F.map((r,z)=>e.jsxs("div",{className:`flex items-center justify-between gap-3 p-3 border rounded-lg ${r.urgent?"border-rose-200 bg-rose-50/40":"hover:bg-slate-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:`w-8 h-8 rounded-md flex items-center justify-center shrink-0 ${r.iconClass}`,children:e.jsx(r.icon,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-slate-800",children:r.text}),r.sub&&e.jsx("p",{className:"text-[11px] text-slate-500 truncate",children:r.sub})]})]}),e.jsx(D,{size:"sm",variant:"outline",className:"h-8 text-xs shrink-0",onClick:()=>N(r.tab),children:r.action})]},z))})]}),m&&q.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"font-bold text-slate-900 mb-3 flex items-center gap-2",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:[e.jsx(_e,{className:"h-4 w-4 text-[#BA3873]"})," Module Adoption",e.jsxs("span",{className:"text-sm text-slate-400 font-normal ml-1",children:[S,"/",_," milestones"]})]}),e.jsx(U,{className:"p-4 space-y-3",children:q.map(r=>{const z=r.total?Math.round(r.achieved/r.total*100):0;return e.jsxs("button",{onClick:()=>N("adoption"),className:"w-full text-left group",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700 capitalize group-hover:text-[#BA3873]",children:r.moduleKey.replace(/_/g," ")}),e.jsxs("span",{className:"text-xs font-bold text-slate-500",children:[r.achieved,"/",r.total," · ",z,"%"]})]}),e.jsx("div",{className:"w-full h-1.5 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full transition-all ${z>=60?"bg-emerald-500":z>=30?"bg-amber-500":"bg-rose-500"}`,style:{width:`${z}%`}})})]},r.moduleKey)})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-slate-900 mb-3",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:"Client Details"}),e.jsx(U,{className:"p-4",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-x-6 gap-y-3 text-sm",children:[e.jsx(Y,{label:"Brand",value:t.brand_name||"â"}),e.jsx(Y,{label:"Contact",value:t.client_name||"â"}),e.jsx(Y,{label:"Phone",value:t.client_phone?ve(t.client_phone):"â"}),e.jsx(Y,{label:"Email",value:t.client_email||"â"}),e.jsx(Y,{label:"Onboarding Manager",value:(s==null?void 0:s.full_name)||"Unassigned"}),e.jsx(Y,{label:"Type",value:t.onboarding_type,cap:!0}),e.jsx(Y,{label:"Status",value:t.status,cap:!0}),e.jsx(Y,{label:"Current Stage",value:(x==null?void 0:x.name)||"â"}),e.jsx(Y,{label:"Handoff",value:t.handoff_date?new Date(t.handoff_date).toLocaleDateString():"â"}),e.jsx(Y,{label:"Target Go-Live",value:t.target_go_live_date||"â"}),m&&e.jsx(Y,{label:"Trial Ends",value:t.trial_end_date||"â"}),m&&e.jsx(Y,{label:"Trial Extensions",value:String(t.trial_extended_count||0)}),m&&E.length>0&&e.jsxs("div",{className:"col-span-2 md:col-span-3",children:[e.jsx("p",{className:"text-[11px] text-slate-400 uppercase tracking-wider font-semibold mb-1",children:"Subscribed Modules"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:E.map(r=>e.jsx(H,{variant:"outline",className:"text-[10px] uppercase",children:r.replace(/_/g," ")},r))})]}),t.converted_at&&e.jsxs("div",{className:"col-span-2 md:col-span-3 text-emerald-700 text-xs font-bold flex items-center gap-1",children:[e.jsx(Ae,{className:"h-3.5 w-3.5"})," Converted ",new Date(t.converted_at).toLocaleDateString()]})]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-slate-900 mb-3",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:"Recent Activity"}),ae.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No activity yet."}):e.jsxs("div",{className:"space-y-2",children:[ae.map(r=>e.jsxs("div",{className:"flex gap-3 text-sm items-start",children:[e.jsx("div",{className:`mt-1.5 h-2 w-2 rounded-full shrink-0 ${r.status==="complete"?"bg-emerald-500":r.status==="blocked"?"bg-amber-500":r.status==="in_progress"?"bg-blue-500":"bg-slate-300"}`}),e.jsxs("div",{className:"flex-1 border-b border-slate-100 pb-2 min-w-0",children:[e.jsxs("p",{className:"text-slate-800 truncate",children:[e.jsx("b",{children:r.title})," ",e.jsxs("span",{className:"text-xs text-slate-500 capitalize ml-1",children:["â ",(r.status||"").replace("_"," ")]})]}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5",children:new Date(r.updated_at||r.created_at).toLocaleStr
1ing()})]})]},r.id)),e.jsx("button",{className:"text-xs text-[#BA3873] font-semibold hover:underline",onClick:()=>N("timeline"),children:"Full timeline â"})]})]})]})}function te({label:t,value:i,tint:l}){return e.jsxs(U,{className:"p-4",children:[e.jsx("div",{className:`inline-flex items-center justify-center w-8 h-8 rounded-md ${l} mb-2`,children:e.jsx(Ae,{className:"h-4 w-4"})}),e.jsx("p",{className:"text-xl font-bold text-slate-900 leading-none",children:i}),e.jsx("p",{className:"text-[11px] text-slate-500 mt-1 uppercase tracking-wider font-semibold",children:t})]})}function Y({label:t,value:i,cap:l}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] text-slate-400 uppercase tracking-wider font-semibold",children:t}),e.jsx("p",{className:`text-slate-800 font-medium truncate ${l?"capitalize":""}`,children:i})]})}function ls(t){if(t.scheduled_at)try{const i=new Date(t.scheduled_at),l=t.timezone||void 0,u=i.toLocaleString("en-US",{weekday:"short",day:"numeric",month:"short",timeZone:l}),o=i.toLocaleString("en-US",{hour:"numeric",minute:"2-digit",timeZone:l});return`${u} · ${o}${t.timezone?` (${t.timezone})`:""}`}catch{}return t.scheduled_date?`Scheduled ${t.scheduled_date}`:"No date set"}function Ne({value:t,onChange:i,size:l="h-5 w-5"}){return e.jsx("div",{className:"flex gap-0.5",children:[1,2,3,4,5].map(u=>e.jsx("button",{type:"button",disabled:!i,onClick:()=>i==null?void 0:i(u),className:i?"cursor-pointer":"cursor-default",children:e.jsx($t,{className:`${l} ${u<=t?"fill-amber-400 text-amber-400":"text-slate-300"}`})},u))})}function is({clientId:t,companyId:i,userId:l,team:u}){const{toast:o}=G(),{can:w}=Te(),v=w("onboarding","delete"),[h,p]=n.useState([]),[a,N]=n.useState(!0),[b,m]=n.useState(!1),[f,P]=n.useState(null),[k,d]=n.useState(null),[j,g]=n.useState(""),[O,C]=n.useState(""),[M,J]=n.useState(""),[R,E]=n.useState(""),[S,_]=n.useState(!1),B=async()=>{const{data:s}=await y.from("onboarding_training_sessions").select("*").eq("client_id",t).order("created_at",{ascending:!1});p(s||[]),N(!1)};n.useEffect(()=>{B()},[t]);const $=async()=>{if(!j.trim())return;_(!0);const{error:s}=await y.from("onboarding_training_sessions").insert({company_id:i,client_id:t,session_number:h.length+1,title:j.trim(),topics:O.trim()||null,scheduled_date:M||null,trainer_id:R||null,created_by:l});if(_(!1),s){o({title:"Could not schedule session",description:s.message,variant:"destructive"});return}o({title:"Session scheduled"}),g(""),C(""),J(""),E(""),m(!1),B()},q=async s=>{const{error:x}=await y.from("onboarding_training_sessions").update({status:"cancelled"}).eq("id",s);if(x){o({title:"Update failed",description:x.message,variant:"destructive"});return}B()},V=async s=>{if(!confirm(`Delete session "${s.title}"? This cannot be undone.`))return;const{error:x}=await y.from("onboarding_training_sessions").delete().eq("id",s.id);if(x){o({title:"Delete failed",description:x.message,variant:"destructive"});return}o({title:"Session deleted"}),B()},T=s=>{var x;return((x=u.find(F=>F.id===s))==null?void 0:x.full_name)||"â"};return a?e.jsx("div",{className:"p-8 flex justify-center",children:e.jsx(he,{className:"h-5 w-5 animate-spin text-[#BA3873]"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"font-bold text-slate-900",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:["Training Sessions ",e.jsxs("span",{className:"text-sm text-slate-400 font-normal ml-2",children:[h.filter(s=>s.status==="completed").length," completed"]})]}),e.jsxs(D,{size:"sm",className:"bg-[#BA3873] hover:bg-[#a02e62]",onClick:()=>m(s=>!s),children:[e.jsx($e,{className:"h-4 w-4 mr-1"})," Schedule Session"]})]}),b&&e.jsxs(U,{className:"p-4 space-y-3 border-pink-200 bg-pink-50/30",children:[e.jsxs("div",{children:[e.jsx(A,{children:"Title *"}),e.jsx(ee,{value:j,onChange:s=>g(s.target.value),placeholder:`Training session #${h.length+1}`})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Topics"}),e.jsx(se,{rows:2,value:O,onChange:s=>C(s.target.value),placeholder:"What will be covered"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{children:[e.jsx(A,{children:"Date"}),e.jsx(ee,{type:"date",value:M,onChange:s=>J(s.target.value),className:"w-44"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx(A,{children:"Trainer"}),e.jsxs(K,{value:R,onValueChange:E,children:[e.jsx(Z,{children:e.jsx(X,{placeholder:"Pick a team member"})}),e.jsx(Q,{children:u.map(s=>e.jsx(L,{value:s.id,children:s.full_name},s.id))})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(D,{size:"sm",className:"bg-[#BA3873] hover:bg-[#a02e62]",onClick:$,disabled:S||!j.trim(),children:"Save"}),e.jsx(D,{size:"sm",variant:"outline",onClick:()=>m(!1),children:"Cancel"})]})]}),h.length===0&&!b&&e.jsx("div",{className:"text-center py-12 border-2 border-dashed border-slate-200 rounded-lg text-sm text-muted-foreground",children:"No training sessions yet â schedule the first one."}),e.jsx("div",{className:"space-y-3",children:h.map(s=>e.jsx(U,{className:`p-4 ${s.status==="cancelled"?"opacity-60":""}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"text-[10px] font-bold text-slate-400",children:["#",s.session_number]}),e.jsx("p",{className:"text-sm font-semibold text-slate-800",children:s.title}),e.jsx(H,{variant:"outline",className:`text-[10px] capitalize ${s.status==="completed"?"bg-emerald-50 text-emerald-700 border-emerald-200":s.status==="cancelled"?"text-slate-500":"bg-blue-50 text-blue-700 border-blue-200"}`,children:s.status}),s.status==="completed"&&!s.client_attended&&e.jsx(H,{variant:"outline",className:"text-[10px] bg-rose-50 text-rose-700 border-rose-200",children:"No-show"}),s.booked_by_client&&e.jsx(H,{variant:"outline",className:"text-[10px] bg-violet-50 text-violet-700 border-violet-200",children:"Client booked"})]}),s.topics&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s.topics}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-1",children:[ls(s)," · Trainer: ",s.host_name||T(s.trainer_id)]}),(s.meet_link||s.recording_url)&&e.jsxs("div",{className:"flex items-center gap-3 mt-1.5",children:[s.meet_link&&e.jsxs("a",{href:s.meet_link,target:"_blank",rel:"noopener",className:"text-[11px] font-semibold text-blue-600 hover:underline inline-flex items-center gap-1",children:[e.jsx(Ct,{className:"h-3 w-3"})," Google Meet"]}),s.recording_url&&e.jsxs("a",{href:s.recording_url,target:"_blank",rel:"noopener",className:"text-[11px] font-semibold text-emerald-600 hover:underline inline-flex items-center gap-1",children:[e.jsx(Dt,{className:"h-3 w-3"})," Recording"]})]}),s.status==="completed"&&e.jsxs("div",{className:"mt-2 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-slate-500",children:[e.jsx("span",{className:"w-24 font-semibold",children:"Trainer rating"}),s.trainer_rating?e.jsx(Ne,{value:s.trainer_rating,size:"h-3.5 w-3.5"}):"â"]}),e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-slate-500",children:[e.jsx("span",{className:"w-24 font-semibold",children:"Client rating"}),s.client_rating?e.jsx(Ne,{value:s.client_rating,size:"h-3.5 w-3.5"}):"â"]}),s.trainer_notes&&e.jsxs("p",{className:"text-[11px] text-slate-500",children:[e.jsx("b",{children:"Trainer notes:"})," ",s.trainer_notes]}),s.client_feedback&&e.jsxs("p",{className:"text-[11px] text-slate-500",children:[e.jsx("b",{children:"Client feedback:"})," ",s.client_feedback]})]})]}),e.jsxs("div",{className:"flex gap-1.5 shrink-0",children:[s.status==="scheduled"&&e.jsxs(e.Fragment,{children:[e.jsx(D,{size:"sm",className:"h-8 text-xs bg-emerald-600 hover:bg-emerald-700",onClick:()=>P(s),children:"Mark Complete"}),e.jsx(D,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0 text-slate-400 hover:text-slate-700",title:"Edit session",onClick:()=>d(s),children:e.jsx(Tt,{className:"h-3.5 w-3.5"})}),e.jsx(D,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0 text-slate-400 hover:text-rose-600",title:"Cancel session",onClick:()=>q(s.id),children:e.jsx(Je,{className:"h-4 w-4"})})]}),v&&e.jsx(D,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0 text-slate-400 hover:text-rose-600",title:"Delete session",onClick:()=>V(s),children:e.jsx(be,{className:"h-3.5 w-3.5"})})]})]})},s.id))}),e.jsx(ds,{session:f,userId:l,onClose:()=>P(null),onDone:B}),e.jsx(rs,{session:k,team:u,onClose:()=>d(null),onSaved:B})]})}
1function rs({session:t,team:i,onClose:l,onSaved:u}){const{toast:o}=G(),[w,v]=n.useState(""),[h,p]=n.useState(""),[a,N]=n.useState(""),[b,m]=n.useState(""),[f,P]=n.useState(!1);if(n.useEffect(()=>{t&&(v(t.title||""),p(t.topics||""),N(t.scheduled_date||""),m(t.trainer_id||""))},[t==null?void 0:t.id]),!t)return null;const k=async()=>{if(!w.trim())return;P(!0);const{error:d}=await y.from("onboarding_training_sessions").update({title:w.trim(),topics:h.trim()||null,scheduled_date:a||null,trainer_id:b||null}).eq("id",t.id);if(P(!1),d){o({title:"Could not save",description:d.message,variant:"destructive"});return}o({title:"Session updated"}),u(),l()};return e.jsx(de,{open:!!t,onOpenChange:d=>!d&&l(),children:e.jsxs(ce,{children:[e.jsx(oe,{children:e.jsxs(xe,{children:["Edit Session â #",t.session_number]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(A,{children:"Title *"}),e.jsx(ee,{value:w,onChange:d=>v(d.target.value)})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Topics"}),e.jsx(se,{rows:2,value:h,onChange:d=>p(d.target.value)})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{children:[e.jsx(A,{children:"Date"}),e.jsx(ee,{type:"date",value:a,onChange:d=>N(d.target.value),className:"w-44"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx(A,{children:"Trainer"}),e.jsxs(K,{value:b,onValueChange:m,children:[e.jsx(Z,{children:e.jsx(X,{placeholder:"Pick a team member"})}),e.jsx(Q,{children:i.map(d=>e.jsx(L,{value:d.id,children:d.full_name},d.id))})]})]})]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:l,children:"Cancel"}),e.jsx(D,{onClick:k,disabled:f||!w.trim(),className:"bg-[#BA3873] hover:bg-[#a02e62]",children:"Save"})]})]})})}function ds({session:t,userId:i,onClose:l,onDone:u}){const{toast:o}=G(),[w,v]=n.useState(!0),[h,p]=n.useState(0),[a,N]=n.useState(""),[b,m]=n.useState(0),[f,P]=n.useState(""),[k,d]=n.useState(!1);if(n.useEffect(()=>{t&&(v(!0),p(0),N(""),m(0),P(""))},[t==null?void 0:t.id]),!t)return null;const j=async()=>{d(!0);const{error:g}=await y.from("onboarding_training_sessions").update({status:"completed",completed_at:new Date().toISOString(),client_attended:w,trainer_rating:h||null,trainer_notes:a.trim()||null,client_rating:b||null,client_feedback:f.trim()||null}).eq("id",t.id);if(!g&&b){const{data:O}=await y.from("feedback_campaigns").select("id").eq("company_id",t.company_id).eq("key","onboarding_training").maybeSingle();O&&await y.from("feedback_responses").insert({company_id:t.company_id,campaign_id:O.id,subject_type:"onboarding_client",subject_id:t.client_id,score:b,comment:f.trim()||null,source:"internal"})}if(d(!1),g){o({title:"Could not complete session",description:g.message,variant:"destructive"});return}o({title:"Session completed"}),u(),l()};return e.jsx(de,{open:!!t,onOpenChange:g=>!g&&l(),children:e.jsxs(ce,{children:[e.jsx(oe,{children:e.jsxs(xe,{children:["Complete Session â ",t.title]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("label",{className:"flex items-center justify-between text-sm font-medium",children:["Client attended",e.jsx(Rt,{checked:w,onCheckedChange:v})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Session quality â trainer's rating"}),e.jsx("div",{className:"mt-1",children:e.jsx(Ne,{value:h,onChange:p})})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Trainer notes"}),e.jsx(se,{rows:2,value:a,onChange:g=>N(g.target.value),placeholder:"How did it go? Any gaps to follow up on?"})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Client's rating"}),e.jsx("div",{className:"mt-1",children:e.jsx(Ne,{value:b,onChange:m})})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Client feedback"}),e.jsx(se,{rows:2,value:f,onChange:g=>P(g.target.value),placeholder:"What the client said"})]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:l,children:"Cancel"}),e.jsx(D,{onClick:j,disabled:k,className:"bg-emerald-600 hover:bg-emerald-700",children:"Complete Session"})]})]})})}function cs({clientId:t,companyId:i,userId:l,client:u,onAdoptionChange:o}){const{toast:w}=G(),[v,h]=n.useState([]),[p,a]=n.useState([]),[N,b]=n.useState([]),[m,f]=n.useState(u.enabled_modules||[]),[P,k]=n.useState(!0),d=async()=>{const[{data:S},{data:_},{data:B}]=await Promise.all([y.from("product_modules").select("module_key, label, position").eq("company_id",i).eq("is_active",!0).order("position"),y.from("product_module_milestones").select("module_key, milestone_key, title, description, position").eq("company_id",i).eq("is_active",!0).order("position"),y.from("onboarding_client_milestone_progress").select("module_key, milestone_key, achieved_at").eq("client_id",t)]);h(S||[]),a(_||[]),b(B||[]),k(!1),o==null||o({progress:B||[]})};n.useEffect(()=>{d()},[t]);const j=async S=>{const _=m.includes(S)?m.filter($=>$!==S):[...m,S];f(_);const{error:B}=await y.from("onboarding_clients").update({enabled_modules:_}).eq("id",t);if(B){f(m),w({title:"Could not update modules",description:B.message,variant:"destructive"});return}o==null||o({enabledModules:_})},g=S=>N.some(_=>_.module_key===S.module_key&&_.milestone_key===S.milestone_key),O=S=>{var _;return(_=N.find(B=>B.module_key===S.module_key&&B.milestone_key===S.milestone_key))==null?void 0:_.achieved_at},C=async S=>{if(g(S)){const{error:_}=await y.from("onboarding_client_milestone_progress").delete().eq("client_id",t).eq("module_key",S.module_key).eq("milestone_key",S.milestone_key);if(_){w({title:"Could not update milestone",description:_.message,variant:"destructive"});return}}else{const{error:_}=await y.from("onboarding_client_milestone_progress").insert({company_id:i,client_id:t,module_key:S.module_key,milestone_key:S.milestone_key,achieved_by:l});if(_){w({title:"Could not update milestone",description:_.message,variant:"destructive"});return}}d()};if(P)return e.jsx("div",{className:"p-8 flex justify-center",children:e.jsx(he,{className:"h-5 w-5 animate-spin text-[#BA3873]"})});const{achieved:M,total:J}=Ke(m,p,N),R=Ze(M,J,u.trial_end_date||null),E=v.filter(S=>m.includes(S.module_key));return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-1",children:e.jsx("h3",{className:"font-bold text-slate-900",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:"Subscribed Modules"})}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Select the eTaps modules this client subscribed to â adoption milestones are generated from them."}),e.jsx("div",{className:"flex flex-wrap gap-2",children:v.map(S=>{const _=m.includes(S.module_key);return e.jsxs("button",{onClick:()=>j(S.module_key),className:`flex items-center gap-2 px-3.5 py-2 rounded-full border text-sm font-semibold transition-colors ${_?"border-[#BA3873] bg-pink-50 text-[#BA3873]":"border-slate-200 text-slate-500 hover:border-slate-300"}`,children:[e.jsx(_e,{className:"h-3.5 w-3.5"}
1)," ",S.label,_&&e.jsx(je,{className:"h-3.5 w-3.5",strokeWidth:3})]},S.module_key)})})]}),E.length===0?e.jsx("div",{className:"text-center py-12 border-2 border-dashed border-slate-200 rounded-lg text-sm text-muted-foreground",children:"Select the client's subscribed modules above to generate their adoption milestones."}):e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("p",{className:"text-[10px] font-extrabold uppercase tracking-widest text-slate-400",children:"Adoption Health"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-bold text-slate-700",children:[M,"/",J," · ",R.pct,"%"]}),e.jsx(H,{variant:"outline",className:`text-[10px] ${R.badgeClass}`,children:R.label})]})]}),e.jsx("div",{className:"w-full h-2 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full ${R.barClass} transition-all`,style:{width:`${R.pct}%`}})})]}),E.map(S=>{const _=p.filter($=>$.module_key===S.module_key),B=_.filter(g).length;return e.jsxs("div",{children:[e.jsxs("h3",{className:"font-bold text-slate-900 mb-3",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:[S.label,e.jsxs("span",{className:"text-sm text-slate-400 font-normal ml-2",children:[B," of ",_.length]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:_.map($=>{const q=g($),V=O($);return e.jsxs("button",{onClick:()=>C($),className:`flex items-start gap-3 p-3 border rounded-lg text-left transition-colors ${q?"border-emerald-200 bg-emerald-50/60":"hover:bg-slate-50"}`,children:[e.jsx("div",{className:`w-5 h-5 rounded-full flex items-center justify-center shrink-0 mt-0.5 ${q?"bg-emerald-500":"border-2 border-slate-300"}`,children:q&&e.jsx(je,{className:"h-3 w-3 text-white",strokeWidth:3})}),e.jsxs("div",{children:[e.jsx("p",{className:`text-sm font-medium ${q?"text-emerald-800":"text-slate-700"}`,children:$.title}),$.description&&e.jsx("p",{className:"text-[11px] text-slate-500 mt-0.5",children:$.description}),q&&V&&e.jsx("p",{className:"text-[10px] text-emerald-600 mt-0.5",children:new Date(V).toLocaleDateString()})]})]},$.milestone_key)})})]},S.module_key)})]})]})}function os({clientId:t,companyId:i,userId:l,clientName:u,clientPhone:o}){var V,T;const{toast:w}=G(),{can:v}=Te(),h=v("onboarding","delete"),[p,a]=n.useState([]),[N,b]=n.useState([]),[m,f]=n.useState(!0),[P,k]=n.useState(!1),[d,j]=n.useState(!1),g=async()=>{const[{data:s},{data:x}]=await Promise.all([y.from("feedback_responses").select("id, campaign_id, score, comment, source, created_at").eq("subject_type","onboarding_client").eq("subject_id",t).order("created_at",{ascending:!1}),y.from("feedback_campaigns").select("*").eq("company_id",i).eq("audience","client").eq("is_active",!0).order("name")]);a(s||[]),b(x||[]),f(!1)};n.useEffect(()=>{g()},[t]);const O=s=>N.find(x=>x.id===s),C=s=>{var x;return((x=O(s))==null?void 0:x.question_type)||"text"},M=s=>{var x;return((x=O(s))==null?void 0:x.name)||"Feedback"},J=async s=>{if(!confirm("Delete this feedback entry?"))return;const{error:x}=await y.from("feedback_responses").delete().eq("id",s);if(x){w({title:"Delete failed",description:x.message,variant:"destructive"});return}g()},R=(V=N.find(s=>s.key==="monthly_nps"))==null?void 0:V.id,E=(T=N.find(s=>s.key==="onboarding_training"))==null?void 0:T.id,S=p.filter(s=>s.campaign_id===R&&s.score!==null).map(s=>s.score),_=p.filter(s=>s.campaign_id===E&&s.score!==null).map(s=>s.score),B=Et(S),$=Vt(_),q=S[0];return m?e.jsx("div",{className:"p-8 flex justify-center",children:e.jsx(he,{className:"h-5 w-5 animate-spin text-[#BA3873]"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("h3",{className:"font-bold text-slate-900",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:["Client Feedback ",e.jsxs("span",{className:"text-sm text-slate-400 font-normal ml-2",children:[p.length," response",p.length===1?"":"s"]})]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(D,{size:"sm",variant:"outline",disabled:!o||d,onClick:()=>j(!0),children:[e.jsx(Ge,{className:"h-3.5 w-3.5 mr-1"})," Request via WhatsApp"]}),e.jsxs(D,{size:"sm",className:"bg-[#BA3873] hover:bg-[#a02e62]",onClick:()=>k(!0),children:[e.jsx($e,{className:"h-4 w-4 mr-1"})," Log feedback"]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs(U,{className:"p-4",children:[e.jsx("p",{className:"text-[10px] font-extrabold uppercase tracking-widest text-slate-400 mb-1.5",children:"Latest NPS"}),e.jsx("p",{className:`text-xl font-bold ${q===void 0?"text-slate-400":q>=9?"text-emerald-600":q>=7?"text-amber-600":"text-rose-600"}`,children:q===void 0?"â":`${q}/10`}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-1",children:[B.count," monthly response",B.count===1?"":"s"]})]}),e.jsxs(U,{className:"p-4",children:[e.jsx("p",{className:"text-[10px] font-extrabold uppercase tracking-widest text-slate-400 mb-1.5",children:"Training CSAT"}),e.jsx("p",{className:`text-xl font-bold ${$.count===0?"text-slate-400":$.csat>=80?"text-emerald-600":"text-amber-600"}`,children:$.count===0?"â":`${$.avg}â
`}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-1",children:[$.count," rated session",$.count===1?"":"s"]})]}),e.jsxs(U,{className:"p-4",children:[e.jsx("p",{className:"text-[10px] font-extrabold uppercase tracking-widest text-slate-400 mb-1.5",children:"Responses"}),e.jsx("p",{className:"text-xl font-bold text-slate-900",children:p.length}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:"all-time"})]})]}),p.length===0?e.jsx("div",{className:"text-center py-12 border-2 border-dashed border-slate-200 rounded-lg text-sm text-muted-foreground",children:"No feedback yet. Send a request over WhatsApp, or log a response you collected over a call."}):e.jsx("div",{className:"space-y-2",children:p.map(s=>{const x=C(s.campaign_id);return e.jsxs("div",{className:"flex items-start justify-between gap-3 p-3 border rounded-lg hover:bg-slate-50",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-800",children:M(s.campaign_id)}),e.jsx(H,{variant:"outline",className:`text-[10px] ${Ut(x,s.score)}`,children:Wt(x,s.score)}),e.jsxs("span",{className:"text-[10px] text-slate-400 capitalize",children:["· ",s.source==="link"?"from client":s.source]})]}),s.comment&&e.jsx("p",{className:"text-xs text-slate-600 mt-1 whitespace-pre-wrap",children:s.comment}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:new Date(s.created_at).toLocaleStr
1ing()})]}),h&&e.jsx(D,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-slate-400 hover:text-rose-600 shrink-0",onClick:()=>J(s.id),children:e.jsx(be,{className:"h-3.5 w-3.5"})})]},s.id)})}),e.jsx(xs,{open:d,onClose:()=>j(!1),campaigns:N,onSend:async s=>{const x=await Jt({campaign:s,companyId:i,subjectType:"onboarding_client",subjectId:t,recipientName:u||"there",recipientPhone:o,createdBy:l});x.ok?w({title:"Feedback request sent"}):w({title:"Not sent",description:`${x.error}. Link: ${x.link||"â"}`,variant:"destructive"}),j(!1),g()}}),e.jsx(ms,{open:P,onClose:()=>k(!1),campaigns:N,companyId:i,clientId:t,userId:l,onSaved:g})]})}function xs({open:t,onClose:i,campaigns:l,onSend:u}){const[o,w]=n.useState(""),[v,h]=n.useState(!1),p=l.find(a=>a.id===o);return e.jsx(de,{open:t,onOpenChange:a=>!a&&i(),children:e.jsxs(ce,{children:[e.jsx(oe,{children:e.jsx(xe,{children:"Request feedback via WhatsApp"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(A,{children:"Which feedback?"}),e.jsxs(K,{value:o,onValueChange:w,children:[e.jsx(Z,{children:e.jsx(X,{placeholder:"Pick a campaign"})}),e.jsx(Q,{children:l.map(a=>e.jsx(L,{value:a.id,children:a.name},a.id))})]})]}),p&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Sends the â",p.prompt,"â link to the client over WhatsApp."]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:i,children:"Cancel"}),e.jsxs(D,{disabled:!p||v,className:"bg-[#BA3873] hover:bg-[#a02e62]",onClick:async()=>{h(!0),await u(p),h(!1)},children:[v?e.jsx(he,{className:"h-4 w-4 animate-spin mr-1.5"}):e.jsx(Ge,{className:"h-4 w-4 mr-1.5"})," Send"]})]})]})})}function ms({open:t,onClose:i,campaigns:l,companyId:u,clientId:o,userId:w,onSaved:v}){const{toast:h}=G(),[p,a]=n.useState(""),[N,b]=n.useState(""),[m,f]=n.useState(""),[P,k]=n.useState(!1),d=l.find(C=>C.id===p),j=(d==null?void 0:d.question_type)||"text",g=j==="nps"?Array.from({length:11},(C,M)=>({v:String(M),label:String(M)})):j==="csat"||j==="stars"?[1,2,3,4,5].map(C=>({v:String(C),label:`${C} â
`})):j==="pulse"?[{v:"3",label:"ð Happy"},{v:"2",label:"ð Okay"},{v:"1",label:"ð Unhappy"}]:[],O=async()=>{if(!d)return;if(j!=="text"&&!N){h({title:"Pick a score",variant:"destructive"});return}k(!0);const{error:C}=await y.from("feedback_responses").insert({company_id:u,campaign_id:d.id,subject_type:"onboarding_client",subject_id:o,score:N?parseInt(N,10):null,comment:m.trim()||null,source:"internal"});if(k(!1),C){h({title:"Could not save",description:C.message,variant:"destructive"});return}h({title:"Feedback logged"}),a(""),b(""),f(""),v(),i()};return e.jsx(de,{open:t,onOpenChange:C=>!C&&i(),children:e.jsxs(ce,{children:[e.jsx(oe,{children:e.jsx(xe,{children:"Log client feedback"})}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-1",children:"Record feedback you collected over a call or WhatsApp."}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(A,{children:"Type"}),e.jsxs(K,{value:p,onValueChange:C=>{a(C),b("")},children:[e.jsx(Z,{children:e.jsx(X,{placeholder:"Pick a campaign"})}),e.jsx(Q,{children:l.map(C=>e.jsx(L,{value:C.id,children:C.name},C.id))})]})]}),d&&j!=="text"&&e.jsxs("div",{children:[e.jsx(A,{children:"Score"}),e.jsxs(K,{value:N,onValueChange:b,children:[e.jsx(Z,{children:e.jsx(X,{placeholder:"Select"})}),e.jsx(Q,{children:g.map(C=>e.jsx(L,{value:C.v,children:C.label},C.v))})]})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Comment"}),e.jsx(se,{rows:3,value:m,onChange:C=>f(C.target.value),placeholder:"What did the client say?"})]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:i,children:"Cancel"}),e.jsx(D,{onClick:O,disabled:P||!d,className:"bg-[#BA3873] hover:bg-[#a02e62]",children:"Save"})]})]})})}function Ls(){const{id:t}=xt(),i=mt(),{user:l}=ut(),{toast:u}=G(),{can:o}=Te(),{dial:w,sipStatus:v}=ht(),{openChatWithPhone:h}=Ht(),p=o("onboarding","delete"),[a,N]=n.useState(null),[b,m]=n.useState([]),[f,P]=n.useState([]),[k,d]=n.useState([]),[j,g]=n.useState([]),[O,C]=n.useState([]),[M,J]=n.useState([]),[R,E]=n.useState([]),[S,_]=n.useState([]),[B,$]=n.useState([]),[q,V]=n.useState(!0),[T,s]=n.useState(!1),[x,F]=n.useState(!1),[ae,r]=n.useState("tasks"),z=async()=>
1{if(!(l!=null&&l.companyId)||!t)return;V(!0);const[{data:c},{data:I},{data:W},{data:re},{data:pe},{data:fe},{data:rt},{data:dt},{data:ct},{data:ot}]=await Promise.all([y.from("onboarding_clients").select("*").eq("id",t).maybeSingle(),y.from("onboarding_stages").select("*").eq("company_id",l.companyId).order("position"),y.from("onboarding_tasks").select("*").eq("onboarding_client_id",t).order("created_at"),y.from("profiles").select("id, full_name, avatar_url").eq("company_id",l.companyId),y.from("onboarding_documents").select("*").eq("client_id",t).order("created_at",{ascending:!1}),y.from("onboarding_pending_items").select("id, title, description, due_date, status, received_at, created_at").eq("client_id",t).order("created_at",{ascending:!1}),y.from("onboarding_tech_requests").select("*").eq("client_id",t).order("submitted_at",{ascending:!1}),y.from("product_module_milestones").select("module_key, milestone_key").eq("company_id",l.companyId).eq("is_active",!0),y.from("onboarding_client_milestone_progress").select("module_key, milestone_key").eq("client_id",t),y.from("onboarding_training_sessions").select("id, title, scheduled_date, status").eq("client_id",t).order("scheduled_date")]);N(c),m(I||[]),P(W||[]),d(re||[]),g(pe||[]),C(fe||[]),J(rt||[]),E(dt||[]),_(ct||[]),$(ot||[]),V(!1)};n.useEffect(()=>{z()},[l==null?void 0:l.companyId,t]);const ke=({enabledModules:c,progress:I})=>{c!==void 0&&N(W=>W&&{...W,enabled_modules:c}),I!==void 0&&_(I)},ne=b.find(c=>/go[\s-]?live/i.test(c.name||"")),Pe=()=>{const c=Number(a==null?void 0:a.trial_length_days)||14,I=new Date().toISOString().slice(0,10),W=new Date(Date.now()+c*864e5).toISOString().slice(0,10);return{startD:I,endD:W}},Xe=async c=>{const I={current_stage_id:c,updated_at:new Date().toISOString()},W=b.find(pe=>pe.id===c),re=a.onboarding_type==="trial"&&!a.trial_start_date&&ne&&W&&W.position>=ne.position;if(re){const{startD:pe,endD:fe}=Pe();I.trial_start_date=pe,I.trial_end_date=fe,I.trial_original_end_date=fe}await y.from("onboarding_clients").update(I).eq("id",t),z(),u(re?{title:"Stage updated â trial started",description:`Trial ends ${I.trial_end_date}`}:{title:"Stage updated"})},Qe=async()=>{const{startD:c,endD:I}=Pe(),{error:W}=await y.from("onboarding_clients").update({trial_start_date:c,trial_end_date:I,trial_original_end_date:I,status:"in_progress",expired_at:null}).eq("id",t);if(W){u({title:"Could not start trial",description:W.message,variant:"destructive"});return}u({title:"Trial started",description:`Ends ${I}`}),z()};if(q&&!a)return e.jsx("div",{className:"p-12 flex justify-center",children:e.jsx(he,{className:"h-6 w-6 animate-spin text-[#BA3873]"})});if(!q&&!a)return e.jsx("div",{className:"p-12 text-center",children:"Client not found"});const Be=f.filter(c=>c.status==="complete").length,Ie=f.length?Math.round(Be/f.length*100):0,Ye=f.length>0&&Be===f.length,Se=`https://etaps.ai/onboarding/progress/${a.portal_token}`,Ce=k.find(c=>c.id===a.account_manager_id),Oe=b.findIndex(c=>c.id===a.current_stage_id),ie=a.trial_end_date?Math.ceil((new Date(a.trial_end_date).getTime()-Date.now())/864e5):null,et=(a.client_name||"?").split(" ").map(c=>c[0]).slice(0,2).join("").toUpperCase(),tt=O.filter(c=>c.status==="pending").length,st=M.filter(c=>c.status!=="verified").length,at=async c=>{if(!confirm("Delete this document?"))return;const{error:I}=await y.from("onboarding_documents").delete().eq("id",c);if(I){u({title:"Delete failed",description:I.message,variant:"destructive"});return}z()},nt=async c=>{await y.from("onboarding_clients").update({target_go_live_date:c||null}).eq("id",t),z()},lt=async()=>{await y.from("onboarding_clients").update({status:"complete",completed_at:new Date().toISOString()}).eq("id",t),u({title:"Onboarding marked complete"}),z()},it=async()=>{if(!confirm(`Delete "${a.client_name}"? This removes their tasks, documents, and trial history from both Clients and Trials. This cannot be undone.`))return;const{error:c}=await y.from("onboarding_clients").delete().eq("id",t);if(c){u({title:"Delete failed",description:c.message,variant:"destructive"});return}u({title:"Client deleted"}),i("/admin/onboarding/active")};return e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsxs(qe,{to:"/admin/onboarding/active",className:"text-sm text-muted-foreground hover:underline inline-flex items-center gap-1",children:[e.jsx(At,{className:"h-3.5 w-3.5"})," All clients"]}),e.jsxs("div",{className:"grid grid-cols-12 gap-6",children:[e.jsxs("aside",{className:"col-span-12 lg:col-span-3 space-y-5",children:[e.jsxs(U,{className:"overflow-hidden",children:[e.jsxs("div",{className:"p-6 bg-gradient-to-br from-pink-50 to-white border-b border-slate-200",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("div",{className:"w-14 h-14 roun
1ded-xl bg-white border border-pink-100 flex items-center justify-center font-bold text-[#BA3873] text-lg shadow-sm mb-3",children:et}),p&&e.jsx(D,{size:"sm",variant:"ghost",className:"text-slate-400 hover:text-rose-600 h-8 w-8 p-0",onClick:it,children:e.jsx(be,{className:"h-4 w-4"})})]}),e.jsx("h2",{className:"text-xl font-bold tracking-tight text-slate-900",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:a.brand_name||a.client_name}),a.brand_name&&a.client_name&&e.jsxs("p",{className:"text-xs text-slate-500 mt-0.5",children:["Contact: ",a.client_name]}),e.jsxs("div",{className:"flex gap-1.5 mt-2",children:[e.jsx(H,{variant:"outline",className:"text-[10px]",children:a.onboarding_type}),e.jsx(H,{variant:"outline",className:"text-[10px]",children:a.status})]})]}),e.jsxs("div",{className:"p-5 space-y-3 text-sm",children:[a.client_phone&&e.jsxs("div",{className:"flex items-center gap-2 text-slate-600",children:[e.jsx(Pt,{className:"h-3.5 w-3.5 text-slate-400"}),a.client_phone]}),a.client_email&&e.jsxs("div",{className:"flex items-center gap-2 text-slate-600 truncate",children:[e.jsx(Bt,{className:"h-3.5 w-3.5 text-slate-400"}),a.client_email]}),e.jsxs("div",{className:"flex items-center gap-2 text-slate-600",children:[e.jsx(It,{className:"h-3.5 w-3.5 text-slate-400"}),"OM: ",e.jsx("b",{className:"text-slate-800",children:(Ce==null?void 0:Ce.full_name)||"Unassigned"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-slate-600",children:[e.jsx(Ot,{className:"h-3.5 w-3.5 text-slate-400"}),"Handoff: ",a.handoff_date?new Date(a.handoff_date).toLocaleDateString():"â"]}),e.jsxs("div",{className:"flex items-center gap-2 text-slate-600",children:[e.jsx(qt,{className:"h-3.5 w-3.5 text-slate-400 shrink-0"}),"Go-Live:",e.jsx("input",{type:"date",value:a.target_go_live_date||"",onChange:c=>nt(c.target.value),className:"text-xs border rounded px-1.5 py-0.5 ml-1 text-slate-700"})]})]})]}),a.onboarding_type==="trial"&&ie!==null&&e.jsxs(U,{className:`p-5 border-2 ${ie<=0?"bg-rose-50 border-rose-200":ie<=3?"bg-amber-50 border-amber-200":"bg-emerald-50 border-emerald-200"}`,children:[e.jsx("p",{className:"text-[10px] font-extrabold uppercase tracking-widest text-slate-500 mb-2",children:"Trial Timeline"}),e.jsxs("div",{className:"flex items-end gap-1.5 mb-3",children:[e.jsx("span",{className:`text-3xl font-black leading-none ${ie<=0?"text-rose-700":ie<=3?"text-amber-700":"text-emerald-700"}`,children:ie<=0?"0":String(ie).padStart(2,"0")}),e.jsx("span",{className:"text-xs font-bold text-slate-600 mb-1",children:ie<=0?"Expired":"Days left"})]}),e.jsxs("p",{className:"text-[11px] text-slate-600",children:["Ends ",a.trial_end_date," · Extensions: ",a.trial_extended_count||0]}),a.converted_at&&e.jsxs("p",{className:"text-[11px] text-emerald-700 mt-2 font-bold",children:["â Converted ",new Date(a.converted_at).toLocaleDateString()]}),e.jsx(qe,{to:"/admin/onboarding/trials",children:e.jsx(D,{size:"sm",variant:"outline",className:"w-full mt-3 h-8 text-xs",children:"Manage Trial"})})]}),a.onboarding_type==="trial"&&!a.trial_start_date&&!a.converted_at&&e.jsxs(U,{className:"p-5 border-2 bg-slate-50 border-slate-200",children:[e.jsx("p",{className:"text-[10px] font-extrabold uppercase tracking-widest text-slate-500 mb-2",children:"Trial Timeline"}),e.jsxs("div",{className:"flex items-end gap-1.5 mb-1",children:[e.jsx("span",{className:"text-2xl font-black leading-none text-slate-700",children:Number(a.trial_length_days)||14}),e.jsx("span",{className:"text-xs font-bold text-slate-600 mb-0.5",children:"day trial"})]}),e.jsxs("p",{className:"text-[11px] text-slate-600 mb-3",children:["Not started yet â the clock begins automatically when this client reaches ",e.jsx("b",{children:"Go-Live"}),", so setup time doesn't burn trial days."]}),e.jsx(D,{size:"sm",className:"w-full h-8 text-xs bg-[#BA3873] hover:bg-[#a02e62]",onClick:Qe,children:"Start trial now"})]}),e.jsxs(U,{className:"p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("p",{className:"text-[10px] font-extrabold uppercase tracking-widest text-slate-400",children:"Stage Progress"}),e.jsxs("span",{className:"text-xs font-bold text-[#BA3873]",children:[Ie,"%"]})]}),e.jsx("div",{className:"w-full h-1.5 bg-slate-100 rounded-full overflow-hidden mb-5",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-[#BA3873] to-[#d64e8c]",style:{width:`${Ie}%`}})}),e.jsx("div",{className:"space-y-1 relative",children:b.map((c,I)=>{const W=c.id===a.current_stage_id,re=Oe>-1&&I<Oe;return e.jsxs("button",{onClick:()=>Xe(c.id),className:`w-full flex items-center gap-3 text-left py-1.5 px-2 rounded-md transition-colors ${W?"bg-pink-50":"hover:bg-slate-50"}`,children:[e.jsxs("div",{className:`w-5 h-5 rounded-full flex items-center justify-center shrink-0 ${re?"bg-emerald-500":W?"ring-4 ring-pink-100":"border-2 border-slate-200"}`,style:W?{backgroundColor:c.color}:void 0,children:[re&&e.jsx(je,{className:"h-3 w-3 text-white",strokeWidth:3}),W&&e.jsx("div",{className:"w-1.5 h-1.5 bg-white rounded-full"})]}),e.jsx("span",{className:`text-xs ${W?"font-bold text-slate-900":re?"text-slate-400 line-through":"text-slate-500"}`,children:c.name})]},c.id)})})]}),e.jsxs(U,{className:"p-5 space-y-2",children:[e.jsx("p",{className:"text-[10px] font-extrabold uppercase tracking-widest text-slate-400",children:"Client Portal"}),e.jsx("code",{className:"block text-[10px] bg-slate-50 p-2 rounded break-all text-slate-600 leading-tight",children:Se}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(D,{size:"sm",variant:"outline",className:"flex-1 h-8 text-xs",onClick:()=>{navigator.clipboard.writeText(Se),u({title:"Copied"})},children:[e.jsx(Lt,{className:"h-3 w-3 mr-1"})," Copy"]}),e.jsxs(D,{size:"sm",variant:"outline",className:"flex-1 h-8 text-xs",onClick:()=>window.open(`https://wa.me/${(a.client_phone||"").replace(/\D/g,"")}?text=${encodeURIComponent(`Track your onboarding: ${Se}`)}`,"_blank"),children:[e.jsx(Le,{className:"h-3 w-3 mr-1"})," Send"]})]})]}),e.jsxs(D,{className:"w-full bg-[#BA3873] hover:bg-[#a02e62]",disabled:!Ye||a.status==="complete",onClick:lt,children:[e.jsx(Ae,{className:"h-4 w-4 mr-2"})," Mark Onboarding Complete"]})]}),e.jsx("main",{className:"col-span-12 lg:col-span-9 space-y-5",children:e.jsx(U,{children:e.jsxs(gt,{value:ae,onValueChange:r,children:[e.jsx(jt,{className:"rounded-none border-b w-full justify-start h-auto bg-transparent p-0 flex-wrap",children:[{value:"overview",label:"Overview"},{value:"tasks",label:"Tasks",badge:tt+st},{value:"training",label:"Training"},{value:"adoption",label:"Trial Adoption"},{value:"feedback",label:"Feedback"},{value:"timeline",label:"Timeline"},{value:"notes",label:"Notes"},{value:"documents",label:"Documents"},{value:"communication",label:"Communication"},{value:"form",label:"Form Data"}].map(c=>e.jsxs(bt,{value:c.value,className:"rounded-none border-b-2 border-transparent data-[state=active]:border-[#BA3873] data-[state=active]:text-[#BA3873] data-[state=active]:bg-transparent data-[state=active]:shadow-none px-4 py-3 text-sm font-semibold text-slate-500",children:[c.label,!!c.badge&&e.jsx("span",{className:"ml-1.5 text-[10px] font-bold bg-[#BA3873] text-white rounded-full px-1.5 py-0.5 leading-none",children:c.badge>9?"9+":c.badge})]},c.value))}),e.jsx(le,{value:"overview",className:"p-6 mt-0",children:e.jsx(ns,{client:a,tasks:f,pendingItems:O,techRequests:M,trainings:B,docs:j,team:k,stages:b,milestoneDefs:R,milestoneProgress:S,onGoTo:r})}),e.jsx(le,{value:"tasks",className:"p-6 mt-0",children:e.jsx(Qt,{clientId:t,companyId:l.companyId,userId:l.id,canDelete:p,tasks:f,pendingItems:O,techRequests:M,stages:b,team
1:k,onChanged:z,onAddTask:()=>s(!0)})}),e.jsx(le,{value:"training",className:"p-6 mt-0",children:e.jsx(is,{clientId:t,companyId:l.companyId,userId:l.id,team:k})}),e.jsx(le,{value:"adoption",className:"p-6 mt-0",children:e.jsx(cs,{clientId:t,companyId:l.companyId,userId:l.id,client:a,onAdoptionChange:ke})}),e.jsx(le,{value:"feedback",className:"p-6 mt-0",children:e.jsx(os,{clientId:t,companyId:l.companyId,userId:l.id,clientName:a.brand_name||a.client_name,clientPhone:a.client_phone})}),e.jsxs(le,{value:"timeline",className:"p-6 mt-0",children:[e.jsx("h3",{className:"font-bold mb-4 text-slate-900",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:"Activity Timeline"}),e.jsxs("div",{className:"space-y-3",children:[[...f].sort((c,I)=>(I.updated_at||I.created_at).localeCompare(c.updated_at||c.created_at)).slice(0,20).map(c=>e.jsxs("div",{className:"flex gap-3 text-sm",children:[e.jsx("div",{className:`mt-1.5 h-2 w-2 rounded-full shrink-0 ${c.status==="complete"?"bg-emerald-500":c.status==="blocked"?"bg-amber-500":c.status==="in_progress"?"bg-blue-500":"bg-slate-300"}`}),e.jsxs("div",{className:"flex-1 border-b border-slate-100 pb-3",children:[e.jsxs("p",{className:"text-slate-800",children:[e.jsx("b",{children:c.title})," ",e.jsxs("span",{className:"text-xs text-slate-500 capitalize ml-1",children:["â ",(c.status||"").replace("_"," ")]})]}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5",children:new Date(c.updated_at||c.created_at).toLocaleString()})]})]},c.id)),f.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No activity yet."})]})]}),e.jsx(le,{value:"notes",className:"p-6 mt-0",children:e.jsx(us,{clientId:t,initial:a.internal_notes||"",onSaved:z})}),e.jsxs(le,{value:"documents",className:"p-6 mt-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"font-bold text-slate-900",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:"Documents"}),e.jsxs(D,{size:"sm",className:"bg-[#BA3873] hover:bg-[#a02e62]",onClick:()=>F(!0),children:[e.jsx(Ft,{className:"h-4 w-4 mr-1"})," Upload"]})]}),j.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No documents uploaded yet."}):e.jsx("div",{className:"space-y-2",children:j.map(c=>e.jsxs("div",{className:"flex items-center justify-between p-3 border rounded-lg hover:bg-slate-50",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:c.file_name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c.description||(c.is_visible_to_client?"Visible to client":"Internal only")})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 ml-3",children:[e.jsxs("button",{onClick:()=>Zt(c.file_url).catch(I=>u({title:"Could not open file",description:I==null?void 0:I.message,variant:"destructive"})),className:"text-[#BA3873] text-xs font-bold hover:underline flex items-center gap-1",children:["Open ",e.jsx(Mt,{className:"h-3 w-3"})]}),p&&e.jsx(D,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>at(c.id),children:e.jsx(be,{className:"h-3 w-3"})})]})]},c.id))})]}),e.jsxs(le,{value:"communication",className:"p-6 mt-0",children:[e.jsx("h3",{className:"font-bold mb-4 text-slate-900",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:"Communication"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("button",{disabled:!a.client_phone,onClick:()=>h(a.client_phone),className:"p-4 border rounded-lg hover:border-emerald-300 hover:bg-emerald-50/30 flex items-center gap-3 text-left disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(Le,{className:"h-5 w-5 text-emerald-600 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-sm",children:"WhatsApp"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.client_phone?`Open CRM chat with ${ve(a.client_phone)}`:"No phone number on file"})]})]}),e.jsxs("button",{disabled:!a.client_phone||v!=="registered",onClick:()=>w(pt(a.client_phone)??a.client_phone),title:v!=="registered"?"SIP not connected":`Call ${ve(a.client_phone)}`,className:"p-4 border rounded-lg hover:border-blue-300 hover:bg-blue-50/30 flex items-center gap-3 text-left disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(zt,{className:"h-5 w-5 text-blue-600 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-sm",children:"Call"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.client_phone?v!=="registered"?"Dialer not connected â check VoIP settings":`Call ${ve(a.client_phone)} from the CRM dialer`:"No phone number on file"})]})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-4",children:"Calls go through the CRM dialer and are saved in Call Logs. WhatsApp opens the CRM chat panel â same as on a lead."})]}),e.jsx(le,{value:"form",className:"p-6 mt-0",children:a.submission_id?e.jsx(hs,{submissionId:a.submission_id}):e.jsx("p",{className:"text-muted-foreground text-sm",children:"No linked submission."})})]})})})]}),e.jsx(ps,{open:T,onClose:()=>
1s(!1),clientId:t,companyId:l.companyId,stages:b,team:k,tasks:f,onCreated:z,userId:l.id}),e.jsx(js,{open:x,onClose:()=>F(!1),clientId:t,companyId:l.companyId,userId:l.id,onUploaded:z})]})}function us({clientId:t,initial:i,onSaved:l}){const{toast:u}=G(),[o,w]=n.useState(i),[v,h]=n.useState(!1),p=async()=>{h(!0);const{error:a}=await y.from("onboarding_clients").update({internal_notes:o}).eq("id",t);h(!1),a?u({title:"Notes not saved",description:a.message,variant:"destructive"}):(u({title:"Notes saved"}),l==null||l())};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"font-bold text-slate-900",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:"Internal Notes"}),e.jsx(se,{rows:10,placeholder:"Private team notes about this onboardingâ¦",value:o,onChange:a=>w(a.target.value)}),e.jsx(D,{onClick:p,disabled:v,className:"bg-[#BA3873] hover:bg-[#a02e62]",children:v?"Savingâ¦":"Save Notes"})]})}function hs({submissionId:t}){const[i,l]=n.useState(null),u=ft(t);return n.useEffect(()=>{y.from("onboarding_submissions").select("form_data").eq("id",t).maybeSingle().then(({data:o})=>l(o==null?void 0:o.form_data))},[t]),i?e.jsxs("div",{className:"text-sm",children:[e.jsx("h3",{className:"font-bold text-slate-900 mb-3",style:{fontFamily:"'Plus Jakarta Sans', sans-serif"},children:"Submitted Form Data"}),e.jsx(vt,{formData:i,submissionId:t,state:u})]}):e.jsx("p",{children:"Loadingâ¦"})}function ps({open:t,onClose:i,clientId:l,companyId:u,stages:o,team:w,tasks:v,onCreated:h,userId:p}){const{toast:a}=G(),[N,b]=n.useState(""),[m,f]=n.useState(""),[P,k]=n.useState("account_manager"),[d,j]=n.useState(""),[g,O]=n.useState(""),[C,M]=n.useState(""),[J,R]=n.useState("medium"),[E,S]=n.useState(""),[_,B]=n.useState(!0),[$,q]=n.useState(!1),V=async()=>{N.trim()&&(q(!0),await y.from("onboarding_tasks").insert({company_id:u,onboarding_client_id:l,title:N.trim(),description:m||null,assigned_role:P,assigned_to:d||null,stage_id:g||null,due_date:C||null,priority:J,status:E?"blocked":"pending",depends_on_task_id:E||null,is_visible_to_client:_,created_by:p}),a({title:"Task added"}),b(""),f(""),h(),i(),q(!1))};return e.jsx(Fe,{open:t,onOpenChange:T=>!T&&i(),children:e.jsxs(Me,{className:"overflow-y-auto",children:[e.jsx(ye,{children:e.jsx(we,{children:"Add Task"})}),e.jsxs("div",{className:"space-y-3 mt-4",children:[e.jsxs("div",{children:[e.jsx(A,{children:"Title *"}),e.jsx(ee,{value:N,onChange:T=>b(T.target.value)})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Description"}),e.jsx(se,{value:m,onChange:T=>f(T.target.value)})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Assigned Role *"}),e.jsxs(K,{value:P,onValueChange:T=>k(T),children:[e.jsx(Z,{children:e.jsx(X,{})}),e.jsxs(Q,{children:[e.jsx(L,{value:"account_manager",children:"Onboarding Manager"}),e.jsx(L,{value:"dev_team",children:"Dev Team"}),e.jsx(L,{value:"client",children:"Client"})]})]})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Assigned To"}),e.jsxs(K,{value:d,onValueChange:j,children:[e.jsx(Z,{children:e.jsx(X,{placeholder:"â"})}),e.jsx(Q,{children:w.map(T=>e.jsx(L,{value:T.id,children:T.full_name},T.id))})]})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Stage"}),e.jsxs(K,{value:g,onValueChange:O,children:[e.jsx(Z,{children:e.jsx(X,{placeholder:"â"})}),e.jsx(Q,{children:o.map(T=>e.jsx(L,{value:T.id,children:T.name},T.id))})]})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Due Date"}),e.jsx(ee,{type:"date",value:C,onChange:T=>M(T.target.value)})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Priority"}),e.jsxs(K,{value:J,onValueChange:T=>R(T),children:[e.jsx(Z,{children:e.jsx(X,{})}),e.jsxs(Q,{children:[e.jsx(L,{value:"low",children:"Low"}),e.jsx(L,{value:"medium",children:"Medium"}),e.jsx(L,{value:"high",children:"High"})]})]})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Depends On"}),e.jsxs(K,{value:E,onValueChange:S,children:[e.jsx(Z,{children:e.jsx(X,{placeholder:"â"})}),e.jsx(Q,{children:v.map(T=>e.jsx(L,{value:T.id,children:T.title},T.id))})]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:_,onChange:T=>B(T.target.checked)})," Visible to client"]}),e.jsx(D,{className:"w-full bg-[#BA3873] hover:bg-[#a02e62]",onClick:V,disabled:$||!N.trim(),children:"Save Task"})]})]})})}const gs=20*1024*1024;function js({open:t,onClose:i,clientId:l,companyId:u,userId:o,onUploaded:w}){const{toast:v}=G(),[h,p]=n.useState(null),[a,N]=n.useState(""),[b,m]=n.useState(!0),[f,P]=n.useState(!1),k=()=>{p(null),N(""),m(!0)},d=async()=>
1{if(h){if(h.size>gs){v({title:"File too large",description:"Max 20MB per document.",variant:"destructive"});return}P(!0);try{const j=await Kt(h,u,l),{error:g}=await y.from("onboarding_documents").insert({company_id:u,client_id:l,uploaded_by:"internal",uploaded_by_id:o,file_name:h.name,file_url:j,file_type:h.type||null,file_size_bytes:h.size,description:a||null,is_visible_to_client:b});if(g)throw g;v({title:"Document uploaded"}),k(),w(),i()}catch(j){v({title:"Upload failed",description:j.message,variant:"destructive"})}finally{P(!1)}}};return e.jsx(de,{open:t,onOpenChange:j=>!j&&i(),children:e.jsxs(ce,{children:[e.jsx(oe,{children:e.jsx(xe,{children:"Upload Document"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(A,{children:"File *"}),e.jsx(ee,{type:"file",onChange:j=>{var g;return p(((g=j.target.files)==null?void 0:g[0])||null)}})]}),e.jsxs("div",{children:[e.jsx(A,{children:"Description"}),e.jsx(se,{value:a,onChange:j=>N(j.target.value),placeholder:"What is this document?"})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:b,onChange:j=>m(j.target.checked)})," Visible to client"]})]}),e.jsxs(me,{children:[e.jsx(D,{variant:"outline",onClick:i,children:"Cancel"}),e.jsxs(D,{onClick:d,disabled:f||!h,children:[f?e.jsx(he,{className:"h-4 w-4 animate-spin mr-2"}):null,"Upload"]})]})]})})}export{Ls as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.