PageSourceSearch

https://digitalbehandling.se/assets/TherapistVideos-BnDi4HT5.js

js digitalbehandling.se collected 2026-09-30 08:26:47 UTC 25,783 bytes, 1 lines download raw bytes

1import{h as xe,r as o,s as p,j as e,e as se,C as Ce,k as D,aM as Se,aL as Le,B as P,Q as pe,D as ve,p as fe,q as ge,t as _e,T as Ee,v as Oe,aA as Ve,b as ie,w as K,x as Ie,A as Ue,c4 as me,S as Pe,J as Be,K as qe,M as $e,N as De,E as Te,G as Me,i as Ae,U as ze,$ as Re,cC as Ke,cD as Fe,cE as We,Y as Ge}from"./index-CobRY8C4.js";import{V as Ze}from"./VideoMaterialList-B1rzPJEJ.js";import{D as He}from"./download-3GrjRmzB.js";import{A as Je}from"./aspect-ratio-BZvRbQhT.js";import{C as Qe,a as Ye,b as Xe}from"./collapsible-akAvtlAp.js";import{P as ue}from"./play-CqtS4evW.js";import{L as he}from"./lock-open-CgtwVVEO.js";import"./MaterialViewer-EQcrSviN.js";function et({orgId:t,onReviewAction:u}){const{user:s}=xe(),[l,f]=o.useState([]),[j,y]=o.useState(!0),[w,c]=o.useState(null),[v,k]=o.useState(""),[O,V]=o.useState(!1),T=async()=>{s&&await p.from("notifications").update({is_read:!0}).eq("user_id",s.id).eq("type","material_submitted").eq("is_read",!1)},M=o.useCallback(async()=>{y(!0);const{data:h}=await p.from("clients").select("id, first_name, last_name").eq("organization_id",t).eq("status","active");if(!h||h.length===0){f([]),y(!1),T();return}const L=h.map(b=>b.id),A={};h.forEach(b=>{A[b.id]=`${b.first_name} ${b.last_name}`});const{data:I}=await p.from("client_material_responses").select("id, client_id, material_id, response_text, status, submitted_at, reviewed_at, reviewer_comment").in("client_id",L).eq("status","submitted");if(!I||I.length===0){f([]),y(!1),T();return}const C=[...new Set(I.map(b=>b.material_id))],{data:Y}=await p.from("video_materials").select("id, title, filename, storage_path").in("id",C),g={};(Y||[]).forEach(b=>{g[b.id]=b});const W=I.map(b=>{var U,G,q;return{...b,client_name:A[b.client_id]||"Okänd",material_title:((U=g[b.material_id])==null?void 0:U.title)||"Okänt material",material_filename:((G=g[b.material_id])==null?void 0:G.filename)||"",material_storage_path:((q=g[b.material_id])==null?void 0:q.storage_path)||""}});f(W),y(!1)},[t]);o.useEffect(()=>{t&&M()},[t,M]);const F=async h=>{V(!0);const{error:L}=await p.from("client_material_responses").update({status:"approved",reviewed_by:s==null?void 0:s.id,reviewed_at:new Date().toISOString(),reviewer_comment:v||null}).eq("id",h.id);L?K({title:"Kunde inte godkänna",description:L.message,variant:"destructive"}):(K({title:"Godkänd",description:`Svaret från ${h.client_name} har godkänts.`}),c(null),k(""),await M(),T(),u==null||u()),V(!1)},B=async h=>{if(!v.trim()){K({title:"Ange en kommentar",description:"Beskriv vad som behöver ändras.",variant:"destructive"});return}V(!0);const{error:L}=await p.from("client_material_responses").update({status:"revision_requested",reviewed_by:s==null?void 0:s.id,reviewed_at:new Date().toISOString(),reviewer_comment:v}).eq("id",h.id);L?K({title:"Kunde inte begära revidering",description:L.message,variant:"destructive"}):(K({title:"Revidering begärd",description:"Klienten har informerats."}),c(null),k(""),await M(),T(),u==null||u()),V(!1)},Q=async h=>{const{data:L,error:A}=await p.storage.from("video-materials").download(h.material_storage_path);if(A||!L){K({title:"Kunde inte ladda ner",variant:"destructive"});return}const I=URL.createObjectURL(L),C=document.createElement("a");C.href=I,C.download=h.material_filename,document.body.appendChild(C),C.click(),document.body.removeChild(C),URL.revokeObjectURL(I)};return j?e.jsxs("div",{className:"flex items-center gap-2 py-4 text-muted-foreground",children:[e.jsx(se,{className:"w-4 h-4 animate-spin"}),e.jsx("span",{className:"text-sm",children:"Laddar uppgifter…"})]}):l.length===0?e.jsx("div",{className:"text-sm text-muted-foreground py-4 text-center",children:"Inga inskickade uppgifter att granska just nu."}):e.jsxs("div",{className:"space-y-3",children:[l.map(h=>e.jsx(Ce,{className:"p-4",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 mb-1",children:[e.jsx("span",{className:"font-medium text-sm",children:h.client_name}),e.jsxs(D,{className:"bg-amber-100 text-amber-800 border-0 text-[10px] gap-0.5",children:[e.jsx(Se,{className:"w-2.5 h-2.5"}),"Inväntar granskning"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Le,{className:"w-3 h-3"}),h.material_title,h.submitted_at&&e.jsxs("span",{children:["· Inskickad ",new Date(h.submitted_at).toLocaleDateString("sv-SE")]})]}),e.jsx("div",{className:"mt-2 p-3 rounded-lg bg-muted/50 text-sm whitespace-pre-wrap max-h-32 overflow-auto",children:h.response_text||e.jsx("span",{className:"text-muted-foreground italic",children:"Inget svar"})})]}),e.jsxs("div",{className:"flex gap-1.5 shrink-0",children:[e.jsxs(P,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>Q(h),children:[e.jsx(He,{className:"w-3 h-3 mr-1"}),"Material"]}),e.jsxs(P,{size:"sm",className:"h-7 text-xs",onClick:()=>{c(h),k("")},children:[e.jsx(pe,{className:"w-3 h-3 mr-1"}),"Granska"]})]})]})},h.id)),e.jsx(ve,{open:!!w,onOpenChange:h=>{h||c(null)},children:e.jsxs(fe,{className:"sm:max-w-lg",children:[e.jsx(ge,{children:e.jsx(_e,{children:"Granska uppgift"})}),w&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:w.
1client_name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:w.material_title})]}),e.jsx("div",{className:"p-3 rounded-lg border bg-muted/30 text-sm whitespace-pre-wrap max-h-48 overflow-auto",children:w.response_text}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:"Kommentar (valfritt vid godkännande, obligatoriskt vid revidering)"}),e.jsx(Ee,{value:v,onChange:h=>k(h.target.value),placeholder:"Skriv feedback till klienten...",className:"min-h-[80px]"})]})]}),e.jsxs(Oe,{className:"gap-2",children:[e.jsxs(P,{variant:"outline",className:"gap-1.5 border-red-200 text-red-700 hover:bg-red-50",disabled:O,onClick:()=>w&&B(w),children:[O?e.jsx(se,{className:"w-4 h-4 animate-spin"}):e.jsx(Ve,{className:"w-4 h-4"}),"Begär revidering"]}),e.jsxs(P,{className:"gap-1.5",disabled:O,onClick:()=>w&&F(w),children:[O?e.jsx(se,{className:"w-4 h-4 animate-spin"}):e.jsx(ie,{className:"w-4 h-4"}),"Godkänn"]})]})]})})]})}function tt(t,u){const s=t.match(/^(\d+)(?:\/([a-zA-Z0-9]+))?$/);if(s){const l=s[1],f=s[2];return f?`https://player.vimeo.com/video/${l}?h=${f}`:`https://player.vimeo.com/video/${l}`}if(u){const l=u.match(/vimeo\.com\/(\d+)(?:\/([a-zA-Z0-9]+))?/);if(l)return l[2]?`https://player.vimeo.com/video/${l[1]}?h=${l[2]}`:`https://player.vimeo.com/video/${l[1]}`}return""}async function st(t,u){const s=tt(t,u);if(s)return s;try{const{data:l,error:f}=await p.functions.invoke("resolve-vimeo-url",{body:{vimeo_url:u}});if(!f&&(l!=null&&l.video_id)){const j=new URLSearchParams;l.hash&&j.set("h",l.hash);const y=j.toString();return`https://player.vimeo.com/video/${l.video_id}${y?`?${y}`:""}`}}catch(l){console.error("resolve-vimeo-url failed",l)}return""}function it(){var de;const{roles:t,user:u}=xe(),s=(de=t==null?void 0:t[0])==null?void 0:de.organization_id,{toast:l}=Ie(),[f,j]=o.useState([]),[y,w]=o.useState(!0),[c,v]=o.useState({}),[k,O]=o.useState(null),[V,T]=o.useState([]),[M,F]=o.useState(!1),[B,Q]=o.useState(null),[h,L]=o.useState(null),[A,I]=o.useState(!1),[C,Y]=o.useState([]),[g,W]=o.useState(""),[b,U]=o.useState(new Set),[G,q]=o.useState(null),[je,Z]=o.useState(null),[X,ne]=o.useState({}),[ee,$]=o.useState(new Set),[be,ae]=o.useState(new Set),[H,re]=o.useState([]),[J,z]=o.useState([]),[Ne,le]=o.useState(!1);o.useEffect(()=>{if(!B){L(null);return}I(!0),st(B.vimeo_video_id,B.vimeo_url).then(i=>L(i||null)).finally(()=>I(!1))},[B]),o.useEffect(()=>{s&&(async()=>{w(!0);const{data:i}=await p.from("video_license_access").select("collection_id").eq("organization_id",s).is("revoked_at",null),d=(i==null?void 0:i.map(n=>n.collection_id))??[];if(d.length===0){j([]),w(!1);return}const{data:a}=await p.from("video_collections").select("id, name, description, video_collection_items(count)").in("id",d);j((a??[]).map(n=>{var N,m;return{id:n.id,name:n.name,description:n.description,videoCount:((m=(N=n.video_collection_items)==null?void 0:N[0])==null?void 0:m.count)??0}})),w(!1)})()},[s]);const te=o.useCallback(async()=>{if(f.length===0||!s)return;const i=f.map(_=>_.id),{data:d}=await p.from("video_materials").select("id, collection_id").in("collection_id",i),{data:a}=await p.from("video_collection_items").select("collection_id, video_id").in("collection_id",i),n={};(a??[]).forEach(_=>{n[_.video_id]=_.collection_id});const N=Object.keys(n);let m=[];if(N.length>0){const{data:_}=await p.from("video_materials").select("id, video_id").in("video_id",N);m=_??[]}const r={};(d??[]).forEach(_=>{_.collection_id&&(r[_.id]=_.collection_id)}),m.forEach(_=>{_.video_id&&n[_.video_id]&&(r[_.id]=n[_.video_id])});const x=Object.keys(r);if(x.length===0){v({});return}const{data:S}=await p.from("client_material_responses").select("material_id").in("material_id",x).eq("status","submitted"),E={};(S??[]).forEach(_=>{const R=r[_.material_id];R&&(E[R]=(E[R]||0)+1)}),v(E)},[f,s]);o.useEffect(()=>{te()},[te]),o.useEffect(()=>{s&&(async()=>{const{data:i}=await p.from("clients").select("id, first_name, last_name").eq("organization_id",s).eq("status","active").order("last_name");Y(i??[])})()},[s]),o.useEffect(()=>{if(!g||f.length===0){ne({}),$(new Set),U(new Set);return}(async()=>{const i=f.map(r=>r.id),{data:d}=await p.from("video_collection_items").select("collection_id, sort_order, video_content(id, title, description, duration_seconds, vimeo_video_id, vimeo_url)").in("collection_id",i).order("sort_order"),a={};
1(d??[]).forEach(r=>{var S,E,_,R,oe,ce;const x=r.collection_id;a[x]||(a[x]=[]),a[x].push({sortOrder:r.sort_order??0,video:{id:(S=r.video_content)==null?void 0:S.id,title:((E=r.video_content)==null?void 0:E.title)??"",description:(_=r.video_content)==null?void 0:_.description,duration_seconds:(R=r.video_content)==null?void 0:R.duration_seconds,vimeo_video_id:((oe=r.video_content)==null?void 0:oe.vimeo_video_id)??"",vimeo_url:((ce=r.video_content)==null?void 0:ce.vimeo_url)??""}})});const n=(r,x)=>r.localeCompare(x,"sv",{numeric:!0,sensitivity:"base"}),N={};for(const[r,x]of Object.entries(a))x.sort((S,E)=>S.sortOrder-E.sortOrder||n(S.video.title,E.video.title)),N[r]=x.map(S=>S.video);ne(N);const m=(d??[]).map(r=>{var x;return(x=r.video_content)==null?void 0:x.id}).filter(Boolean);if(m.length>0){const{data:r}=await p.from("client_video_overrides").select("video_id").eq("client_id",g).in("video_id",m),x=new Set((r??[]).map(S=>S.video_id));$(x),U(x)}else $(new Set),U(new Set);k&&ae(new Set([k.id]))})()},[g,f]),o.useEffect(()=>{if(V.length===0||C.length===0){re([]),z([]);return}const i=V.map(a=>a.id),d=C.map(a=>a.id);(async()=>{const[a,n]=await Promise.all([p.from("client_video_progress").select("client_id, video_id, watch_percentage, completed_at").in("video_id",i).in("client_id",d),p.from("client_video_overrides").select("client_id, video_id").in("video_id",i).in("client_id",d)]);re(a.data??[]),z(n.data??[])})()},[V,C]);const we=o.useMemo(()=>{const i={};return H.forEach(d=>{i[d.client_id]||(i[d.client_id]={}),i[d.client_id][d.video_id]={pct:d.watch_percentage,completed:!!d.completed_at}}),i},[H]),ke=o.useMemo(()=>{const i={};return J.forEach(d=>{i[d.client_id]||(i[d.client_id]=new Set),i[d.client_id].add(d.video_id)}),i},[J]),ye=o.useMemo(()=>{const i=new Set;return H.forEach(d=>i.add(d.client_id)),J.forEach(d=>i.add(d.client_id)),C.filter(d=>i.has(d.id))},[C,H,J]);return{orgId:s,collections:f,loading:y,pendingByCollection:c,selectedCollection:k,setSelectedCollection:O,videos:V,videosLoading:M,playingVideo:B,setPlayingVideo:Q,therapistEmbedUrl:h,therapistEmbedLoading:A,clients:C,selectedClientId:g,setSelectedClientId:W,unlockedVideoIds:b,unlocking:G,batchLoading:je,allCollectionVideos:X,allClientOverrideIds:ee,openSections:be,showProgress:Ne,setShowProgress:le,progressByClient:we,overridesByClient:ke,clientsWithActivity:ye,openCollection:async i=>{O(i),W(""),le(!1),F(!0);const{data:d}=await p.from("video_collection_items").select("sort_order, video_content(id, title, description, duration_seconds, vimeo_video_id, vimeo_url)").eq("collection_id",i.id).order("sort_order"),a=(d??[]).map(n=>{var N,m,r,x,S,E;return{sortOrder:n.sort_order??0,video:{id:(N=n.video_content)==null?void 0:N.id,title:((m=n.video_content)==null?void 0:m.title)??"",description:(r=n.video_content)==null?void 0:r.description,duration_seconds:(x=n.video_content)==null?void 0:x.duration_seconds,vimeo_video_id:((S=n.video_content)==null?void 0:S.vimeo_video_id)??"",vimeo_url:((E=n.video_content)==null?void 0:E.vimeo_url)??""}}});a.sort((n,N)=>n.sortOrder-N.sortOrder||n.video.title.localeCompare(N.video.title,"sv",{numeric:!0,sensitivity:"base"})),T(a.map(n=>n.video)),F(!1)},handleUnlock:async i=>{if(!g||!(u!=null&&u.id))return;q(i);const{error:d}=await p.from("client_video_overrides").insert({client_id:g,video_id:i,unlocked_by:u.id});q(null),d?l({title:"Fel",description:"Kunde inte låsa upp videon.",variant:"destructive"}):(l({title:"Upplåst",description:"Videon har låsts upp för klienten."}),U(a=>new Set([...a,i])),$(a=>new Set([...a,i])),z(a=>[...a,{client_id:g,video_id:i}]))},handleLock:async i=>{if(!g)return;q(i);const{error:d}=await p.from("client_video_overrides").delete().eq("client_id",g).eq("video_id",i);q(null),d?l({title:"Fel",description:"Kunde inte låsa videon.",variant:"destructive"}):(l({title:"Låst",description:"Videon har låsts för klienten."}),U(a=>{const n=new Set(a);return n.delete(i),n}),z(a=>a.filter(n=>!(n.client_id===g&&n.video_id===i))),$(a=>{const n=new Set(a);return n.delete(i),n}))},handleBatchUnlock:async i=>{if(!g||!(u!=null&&u.id))return;const a=(X[i]??[]).filter(m=>!ee.has(m.id));if(a.length===0)return;Z(i);const n=a.map(m=>({client_id:g,video_id:m.id,unlocked_by:u.id})),{error:N}=await p.from("client_video_overrides").upsert(n,{onConflict:"client_id,video_id"});if(Z(null),N)l({title:"Fel",description:"Kunde inte låsa upp videorna.",variant:"destructive"});else{l({title:"Upplåst",description:`${a.length} videor upplåsta.`});const m=a.map(r=>r.id);U(r=>new Set([...r,...m])),$(r=>new Set([...r,...m])),z(r=>[...r,...m.map(x=>({client_id:g,video_id:x}))])}},handleBatchLock:async i=>{if(!g)return;const a=(X[i]??[]).filter(m=>ee.has(m.id));if(a.length===0)return;Z(i);const n=a.map(m=>m.id),{error:N}=await p.from("client_video_overrides").delete().eq("client_id",g).in("video_id",n);Z(null),N?l({title:"Fel",description:"Kunde inte låsa videorna.",variant:"destructive"}):(l({title:"Låst",description:`${a.length} videor låsta.`}),U(m=>{const r=new Set(m);
1return n.forEach(x=>r.delete(x)),r}),$(m=>{const r=new Set(m);return n.forEach(x=>r.delete(x)),r}),z(m=>m.filter(r=>!(r.client_id===g&&n.includes(r.video_id)))))},toggleSection:i=>{ae(d=>{const a=new Set(d);return a.has(i)?a.delete(i):a.add(i),a})},refreshPendingCounts:te}}function nt(t){if(!t)return"—";const u=Math.floor(t/60),s=t%60;return s>0?`${u} min ${s} sek`:`${u} min`}function _t(){var u;const t=it();return t.selectedCollection?e.jsxs("div",{className:"max-w-5xl mx-auto",children:[e.jsxs(P,{variant:"ghost",size:"sm",className:"mb-4 text-muted-foreground",onClick:()=>t.setSelectedCollection(null),children:[e.jsx(Ue,{className:"h-4 w-4 mr-1"})," Tillbaka"]}),e.jsx("h1",{className:"text-2xl font-bold mb-1",children:t.selectedCollection.name}),t.selectedCollection.description&&e.jsx("p",{className:"text-muted-foreground mb-6",children:t.selectedCollection.description}),t.videosLoading?e.jsx("p",{className:"text-muted-foreground",children:"Laddar videor…"}):t.videos.length===0?e.jsx("p",{className:"text-muted-foreground",children:"Inga videor i denna samling."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bg-card rounded-xl border border-border overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border bg-muted/30",children:[e.jsx("th",{className:"text-left px-4 py-3 font-medium text-muted-foreground",children:"#"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-muted-foreground",children:"Titel"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-muted-foreground hidden sm:table-cell",children:"Beskrivning"}),e.jsx("th",{className:"text-right px-4 py-3 font-medium text-muted-foreground",children:"Längd"})]})}),e.jsx("tbody",{children:t.videos.map((s,l)=>e.jsxs("tr",{className:"border-b border-border last:border-0 cursor-pointer hover:bg-muted/40 transition-colors",onClick:()=>t.setPlayingVideo(s),children:[e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:l+1}),e.jsx("td",{className:"px-4 py-3 font-medium",children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(ue,{className:"h-3.5 w-3.5 text-primary shrink-0"}),s.title]})}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground hidden sm:table-cell max-w-xs truncate",children:s.description?s.description.length>80?s.description.slice(0,80)+"…":s.description:"—"}),e.jsx("td",{className:"px-4 py-3 text-right text-muted-foreground whitespace-nowrap",children:nt(s.duration_seconds)})]},s.id))})]})}),e.jsx("div",{className:"mt-4",children:e.jsx(Ze,{collectionId:t.selectedCollection.id,canEditAccessRule:!0})}),t.orgId&&e.jsxs("div",{className:"bg-card rounded-xl border border-border p-5 mt-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(me,{className:"h-4 w-4 text-primary"}),e.jsx("h2",{className:"font-semibold",children:"Uppgifter att granska"})]}),e.jsx(et,{orgId:t.orgId,onReviewAction:t.refreshPendingCounts})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border p-5 mt-6",children:[e.jsx("h2",{className:"font-semibold mb-4",children:"Lås upp video för klient"}),e.jsx("div",{className:"mb-4 max-w-xs",children:e.jsxs(Pe,{value:t.selectedClientId,onValueChange:t.setSelectedClientId,children:[e.jsx(Be,{children:e.jsx(qe,{placeholder:"Välj klient…"})}),e.jsx($e,{children:t.clients.map(s=>e.jsxs(De,{value:s.id,children:[s.last_name,", ",s.first_name]},s.id))})]})}),t.selectedClientId&&e.jsx("div",{className:"space-y-3",children:t.collections.map(s=>{const l=t.allCollectionVideos[s.id]??[];if(l.length===0)return null;const f=t.openSections.has(s.id),j=l.filter(c=>t.allClientOverrideIds.has(c.id)).length,y=j===l.length,w=j===0;return e.jsx(Qe,{open:f,onOpenChange:()=>t.toggleSection(s.id),children:e.jsxs("div",{className:"rounded-lg border border-border overflow-hidden",children:[e.jsx(Ye,{asChild:!0,children:e.jsxs("button",{className:"w-full flex items-center justify-between gap-2 px-4 py-3 bg-muted/30 hover:bg-muted/50 transition-colors text-left",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[f?e.jsx(Te,{className:"h-4 w-4 text-muted-foreground shrink-0"}):e.jsx(Me,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("span",{className:"font-medium text-sm truncate",children:s.name}),e.jsxs(D,{variant:"secondary",className:"text-xs shrink-0",children:[l.length," videor"]}),j>0&&e.jsxs(D,{className:"bg-primary/10 text-primary border-0 text-xs shrink-0",children:[j," upplåsta"]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",onClick:c=>c.stopPropagation(),children:[!y&&e.jsx(P,{size:"sm",variant:"outline",disabled:t.batchLoading===s.id,onClick:()=>t.handleBatchUnlock(s.id),className:"text-xs h-7",children:t.batchLoading===s.id?"…":"Lås upp alla"}),!w&&e.jsx(P,{size:"sm",variant:"outline",disabled:t.batchLoading===s.id,onClick:()=>t.handleBatchLock(s.id),className:"text-xs h-7",children:t.batchLoading===s.id?"…":"Lås alla"})]})]})}),e.jsx(Xe,{children:e.jsx("div",{className:"divide-y divide-border",children:l.map(c=>{const v=t.allClientOverrideIds.has(c.id);return e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[v?e.jsx(he,{className:"h-4 w-4 text-primary shrink-0"}):e.jsx(Ae,{className:"h-4 w-4 text-destructive shrink-0"}),e.jsx("span",{className:"truncate text-sm",children:c.title})]}),v?e.jsx(P,{size:"sm",variant:"outline",disabled:t.unlocking===c.id,onClick:()=>t.handleLock(c.id),className:"text-xs h-7",children:t.unlocking===c.id?"…":"Lås"}):e.jsx(P,{size:"sm",variant:"outline",disabled:t.unlocking===c.id,onClick:()=>t.handleUnlock(c.id),className:"text-xs h-7",children:t.unlocking===c.id?"…":"Lås upp"})]},c.id)})})})]})},s.id)})})]}),e.jsxs("div",{className:"bg-card rounded-xl border border-border p-5 mt-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"font-semibold",children:"Klienternas framsteg"}),t.clientsWithActivity.length>0&&e.jsxs(D,{variant:"secondary",className:"text-xs",children:[t.clientsWithActivity.length," klient",t.clientsWithActivity.length!==1?"er":""]})]}),e.jsxs(P,{variant:"ghost",size:"sm",onClick:()=>t.setShowProgress(!t.showProgress),children:[e.jsx(pe,{className:"h-4 w-4 mr-1"}),t.showProgress?"Dölj":"Visa"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Översikt av klienter som har påbörjat eller fått videor upplåsta."}),t.showProgress&&e.jsx(e.Fragment,{children:t.clientsWithActivity.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"Inga klienter har påbörjat videorna i denna samling ännu."}):e.jsx("div",{className:"space-y-4",children:t.clientsWithActivity.map(s=>{const l=t.progressByClient[s.id]||{}
1,f=t.overridesByClient[s.id]||new Set,j=t.videos.length,y=t.videos.filter(c=>{var v;return(v=l[c.id])==null?void 0:v.completed}).length,w=j>0?Math.round(t.videos.reduce((c,v)=>{var k;return c+(((k=l[v.id])==null?void 0:k.pct)||0)},0)/j):0;return e.jsxs("div",{className:"rounded-lg border border-border p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-medium text-sm",children:[s.last_name,", ",s.first_name]}),y===j&&j>0&&e.jsxs(D,{className:"bg-primary/10 text-primary border-0 text-xs",children:[e.jsx(ie,{className:"h-3 w-3 mr-1"}),"Alla klara"]})]}),e.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums",children:[y,"/",j," klara · ",w,"%"]})]}),e.jsx("div",{className:"grid gap-2",children:t.videos.map(c=>{const v=l[c.id],k=(v==null?void 0:v.pct)||0,O=(v==null?void 0:v.completed)||!1,V=f.has(c.id);return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-5 flex items-center justify-center shrink-0",children:O?e.jsx(ie,{className:"h-3.5 w-3.5 text-primary"}):k>0?e.jsx(ue,{className:"h-3.5 w-3.5 text-muted-foreground"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-border"})}),e.jsx("span",{className:"text-xs text-foreground truncate min-w-0 flex-shrink-0 w-28 sm:w-40",children:c.title}),e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[e.jsx(Re,{value:O?100:k,className:"h-1.5 flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground w-10 text-right tabular-nums",children:O?"100%":k>0?`${k}%`:"—"})]}),V&&e.jsxs(Ke,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(he,{className:"h-3 w-3 text-primary shrink-0"})}),e.jsx(We,{children:"Manuellt upplåst"})]})]},c.id)})})]},s.id)})})})]})]}),e.jsx(ve,{open:!!t.playingVideo,onOpenChange:s=>!s&&t.setPlayingVideo(null),children:e.jsxs(fe,{className:"max-w-3xl p-0 overflow-hidden",children:[e.jsx(ge,{className:"p-4 pb-0",children:e.jsx(_e,{children:(u=t.playingVideo)==null?void 0:u.title})}),e.jsx("div",{className:"p-4 pt-2",children:t.therapistEmbedLoading?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:"Laddar video…"})}):t.therapistEmbedUrl?e.jsx(Je,{ratio:16/9,children:e.jsx("iframe",{src:t.therapistEmbedUrl,className:"w-full h-full rounded-lg",allow:"autoplay; fullscreen; picture-in-picture",allowFullScreen:!0})}):e.jsx("p",{className:"text-sm text-muted-foreground py-8 text-center",children:"Det gick inte att ladda videon."})})]})})]}):e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:"Videor"}),t.loading?e.jsx("p",{className:"text-muted-foreground",children:"Laddar…"}):t.collections.length===0?e.jsxs("div",{className:"text-center py-16 text-muted-foreground",children:[e.jsx(Ge,{className:"h-10 w-10 mx-auto mb-3 opacity-40"}),e.jsx("p",{children:"Din organisation har inga tillgängliga videosamlingar."})]}):e.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:t.collections.map(s=>e.jsxs("button",{onClick:()=>t.openCollection(s),className:"bg-card border border-border rounded-xl p-5 text-left hover:border-primary/40 transition-colors",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-2",children:[e.jsx("h2",{className:"font-semibold",children:s.name}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[(t.pen
1dingByCollection[s.id]??0)>0&&e.jsxs(D,{className:"bg-amber-100 text-amber-800 border-amber-200 hover:bg-amber-100",children:[e.jsx(me,{className:"h-3 w-3 mr-1"}),t.pendingByCollection[s.id]," att granska"]}),e.jsxs(D,{variant:"secondary",children:[s.videoCount," videor"]})]})]}),s.description&&e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:s.description})]},s.id))})]})}export{_t 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.