1import{c as se,h as Q,r as c,s as f,j as e,p as te,B as b,m as q,n as N,o as re,L as W,b as ae,G as ie,F as X,$ as ne}from"./index-pF_JbmLx.js";import{B as U}from"./badge-BYwfP_JE.js";import{P as le}from"./progress-LBf0_Ut1.js";import{d as oe}from"./certificateDownload-DFu11Q5J.js";import{T as ce}from"./textarea-C9MRzjTI.js";import{P as de}from"./pen-DGvjQ5L8.js";import{S as F}from"./star-ZfOxshu5.js";import{C as me}from"./chevron-left-gcbkjCEf.js";import{B as O}from"./book-open-B97Tf5yV.js";import{P as Y}from"./play-DIvS1sNo.js";import{A as V}from"./award-DEP4Af_c.js";import{D as ee}from"./download-Cnx95PLh.js";import{C as J}from"./circle-check-big-CDhD5xwO.js";import{C as ue}from"./chevron-up-BLOV3HLr.js";import{C as xe}from"./chevron-down-BVfCd5RY.js";import{L as fe}from"./lock-sN2e8Sgn.js";import{C as he}from"./circle-help-Dtb03V_M.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const pe=se("Printer",[["path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2",key:"143wyd"}],["path",{d:"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6",key:"1itne7"}],["rect",{x:"6",y:"14",width:"12",height:"8",rx:"1",key:"1ue0tg"}]]),G=({value:r,onChange:n,readonly:a=!1,size:d=20})=>e.jsx("div",{className:"flex gap-0.5",children:[1,2,3,4,5].map(h=>e.jsx("button",{type:"button",disabled:a,onClick:()=>n==null?void 0:n(h),className:`transition-colors ${a?"cursor-default":"cursor-pointer hover:scale-110"}`,children:e.jsx(F,{size:d,className:h<=r?"fill-amber-400 text-amber-400":"text-muted-foreground/30"})},h))}),ge=({courseId:r,isCompleted:n})=>{const{user:a}=Q(),[d,h]=c.useState([]),[w,j]=c.useState(null),[z,o]=c.useState(!1),[_,R]=c.useState(0),[B,L]=c.useState(""),[$,D]=c.useState(!1),[M,Z]=c.useState(!0);c.useEffect(()=>{E()},[r,a]);const E=async()=>{try{const{data:s}=await f.from("course_reviews").select("*").eq("course_id",r).order("created_at",{ascending:!1});if(s){const u=[...new Set(s.map(x=>x.user_id))],{data:y}=await f.from("profiles").select("user_id, display_name, first_name, last_name").in("user_id",u),v=Object.fromEntries((y||[]).map(x=>[x.user_id,x])),A=s.map(x=>({...x,profile:v[x.user_id]}));if(h(A),a){const x=A.find(t=>t.user_id===a.id);x&&(j(x),R(x.rating),L(x.review_text||""))}}}catch(s){console.error(s)}finally{Z(!1)}},I=async()=>{if(!a||_===0){N.error("Bitte wählen Sie eine Bewertung aus.");return}D(!0);try{if(w){const{error:s}=await f.from("course_reviews").update({rating:_,review_text:B.trim()||null}).eq("id",w.id);if(s)throw s;N.success("Bewertung aktualisiert!")}else{const{error:s}=await f.from("course_reviews").insert({course_id:r,user_id:a.id,rating:_,review_text:B.trim()||null});if(s)throw s;N.success("Bewertung abgegeben!")}o(!1),E()}catch{N.error("Fehler beim Speichern der Bewertung")}finally{D(!1)}},k=d.length>0?(d.reduce((s,u)=>s+u.rating,0)/d.length).toFixed(1):null,S=s=>{var u,y,v;return((u=s.profile)==null?void 0:u.display_name)||`${((y=s.profile)==null?void 0:y.first_name)||""} ${((v=s.profile)==null?void 0:v.last_name)||""}`.trim()||"Anonym"};return M?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h2",{className:"font-display text-xl font-bold text-foreground flex items-center gap-2",children:[e.jsx(te,{size:20,className:"text-primary"}),"Bewertungen",k&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground ml-2",children:["â ",k," · ",d.length," ",d.length===1?"Bewertung":"Bewertungen"]})]}),n&&a&&!z&&e.jsxs(b,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>o(!0),children:[w?e.jsx(de,{size:14}):e.jsx(F,{size:14}),w?"Bewertung bearbeiten":"Bewertung abgeben"]})]}),k&&e.jsxs("div",{className:"glass-card p-4 flex items-center gap-4",children:[e.jsx("div",{className:"text-3xl font-bold text-foreground",children:k}),e.jsxs("div",{children:[e.jsx(G,{value:Math.round(Number(k)),readonly:!0,size:18}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[d.length," ",d.length===1?"Bewertung":"Bewertungen"]})]}),e.jsx("div",{className:"flex-1 ml-4 space-y-1",children:[5,4,3,2,1].map(s=>{const u=d.filter(v=>v.rating===s).length,y=d.length>0?u/d.length*100:0;return e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"w-3 text-muted-foreground",children:s}),e.jsx("div",{className:"flex-1 h-1.5 bg-secondary rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-amber-400 rounded-full transition-all",style:{width:`${y}%`}})}),e.jsx("span",{className:"w-6 text-right text-muted-foreground",children:u})]},s)})})]}),z&&e.jsxs(q.div,{initial:{opacity:0,y:-10}
6,animate:{opacity:1,y:0},className:"glass-card p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-foreground mb-2 block",children:"Ihre Bewertung"}),e.jsx(G,{value:_,onChange:R,size:28})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-foreground mb-2 block",children:"Feedback (optional)"}),e.jsx(ce,{placeholder:"Was hat Ihnen gefallen? Was könnte verbessert werden?",value:B,onChange:s=>L(s.target.value),maxLength:1e3,rows:3}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 text-right",children:[B.length,"/1000"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(b,{onClick:I,disabled:$||_===0,className:"gap-2",children:[e.jsx(F,{size:14}),$?"Wird gespeichert...":w?"Aktualisieren":"Absenden"]}),e.jsx(b,{variant:"outline",onClick:()=>o(!1),children:"Abbrechen"})]})]}),d.length===0&&!z?e.jsxs("div",{className:"glass-card p-8 text-center",children:[e.jsx(F,{className:"mx-auto text-muted-foreground/30 mb-2",size:32}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Noch keine Bewertungen. Sei der Erste!"})]}):e.jsx("div",{className:"space-y-3",children:d.map(s=>e.jsxs(q.div,{initial:{opacity:0}
6,animate:{opacity:1},className:"glass-card p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center text-xs font-bold text-primary",children:S(s).charAt(0).toUpperCase()}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:S(s)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(s.created_at).toLocaleDateString("de-DE")})]})]}),e.jsx(G,{value:s.rating,readonly:!0,size:14})]}),s.review_text&&e.jsx("p",{className:"text-sm text-muted-foreground pl-10",children:s.review_text})]},s.id))})]})},je={video:Y,text:X,quiz:he,assignment:ne,resource:ee},ye={video:"Video",text:"Text",quiz:"Quiz",assignment:"Aufgabe",resource:"Ressource"},Ee=()=>{const{courseId:r}=re(),{user:n}=Q(),[a,d]=c.useState(null),[h,w]=c.useState([]),[j,z]=c.useState(!1),[o,_]=c.useState(null),[R,B]=c.useState(!0),[L,$]=c.useState(!1),[D,M]=c.useState(new Set),[Z,E]=c.useState("");c.useEffect(()=>{r&&I()},[r,n]);const I=async()=>{try{const{data:t}=await f.from("courses").select("*").eq("id",r).single();if(!t)return;d(t);const{data:m}=await f.from("course_modules").select("*").eq("course_id",r).order("sort_order");if(m){const i=await Promise.all(m.map(async p=>{const{data:g}=await f.from("lessons").select("*").eq("module_id",p.id).order("sort_order");let l=g||[];if(n&&(g!=null&&g.length)){const K=g.map(T=>T.id),{data:P}=await f.from("lesson_progress").select("lesson_id, completed").eq("user_id",n.id).in("lesson_id",K);l=g.map(T=>({...T,completed:(P==null?void 0:P.some(H=>H.lesson_id===T.id&&H.completed))||!1}))}return{...p,lessons:l}}));w(i);const C=i.find(p=>p.lessons.some(g=>!g.completed));C?M(new Set([C.id])):i.length&&M(new Set([i[0].id]))}if(n){const[i,C,p]=await Promise.all([f.from("course_enrollments").select("*").eq("user_id",n.id).eq("course_id",r).maybeSingle(),f.from("certificates").select("*").eq("user_id",n.id).eq("course_id",r).maybeSingle(),f.from("profiles").select("display_name, first_name, last_name").eq("user_id",n.id).maybeSingle()]);z(!!i.data),_(C.data),p.data&&E(p.data.display_name||`${p.data.first_name||""} ${p.data.last_name||""}`.trim()||n.email||"")}}catch(t){console.error(t)}finally{B(!1)}},k=async()=>{if(!n){N.error("Bitte melden Sie sich an.");return}const{error:t}=await f.from("course_enrollments").insert({user_id:n.id,course_id:r});if(t){N.error("Fehler bei der Einschreibung");return}N.success("Erfolgreich eingeschrieben!"),z(!0)},S=h.reduce((t,m)=>t+m.lessons.length,0),s=h.reduce((t,m)=>t+m.lessons.filter(i=>i.completed).length,0),u=S>0?Math.round(s/S*100):0,y=(()=>{var t;for(const m of h)for(const i of m.lessons)if(!i.completed)return i;return((t=h[0])==null?void 0:t.lessons[0])||null})(),v=async()=>{if(!(!n||!r)){$(!0);try{const{data:t,error:m}=await f.functions.invoke("generate-certificate",{body:{courseId:r,userId:n.id}});if(m)throw m;N.success("Zertifikat wurde generiert!"),I()}catch{N.error("Zertifikat konnte nicht generiert werden")}finally{$(!1)}}},A=t=>{M(m=>{const i=new Set(m);return i.has(t)?i.delete(t):i.add(t),i})},x=()=>{!o||!a||oe({certificate_number:o.certificate_number,score:o.score,ai_feedback:o.ai_feedback,issued_at:o.issued_at,courseTitle:a.title,userName:Z})};return R?e.jsx("div",{className:"p-6 md:p-8 lg:p-10 flex items-center justify-center min-h-[60vh]",children:e.jsx("div",{className:"animate-spin w-8 h-8 border-2 border-primary border-t-transparent rounded-full"})}):a?e.jsxs("div",{className:"p-6 md:p-8 lg:p-10 space-y-6",children:[e.jsxs(W,{to:"/dashboard/akademie",className:"inline-flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(me,{size:16}),"Zurück zur Akademie"]}),e.jsx(q.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"glass-card p-6 md:p-8",children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-6",children:[j&&e.jsx("div",{className:"flex-shrink-0 flex items-center justify-center",children:e.jsxs("div",{className:"relative w-28 h-28",children:[e.jsxs("svg",{className:"w-28 h-28 -rotate-90",viewBox:"0 0 100 100",children:[e.jsx("circle",{cx:"50",cy:"50",r:"42",fill:"none",className:"stroke-secondary",strokeWidth:"8"}),e.jsx("circle",{cx:"50",cy:"50",r:"42",fill:"none",className:"stroke-primary",strokeWidth:"8",strokeLinecap:"round",strokeDasharray:`${2*Math.PI*42}`,strokeDashoffset:`${2*Math.PI*42*(1-u/100)}`,style:{transition:"stroke-dashoffset 0.6s ease"}})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsxs("span",{className:"text-2xl font-bold text-foreground",children:[u,"%"]}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[s,"/",S]})]})]})}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx(U,{variant:"outline",children:a.category}),e.jsx(U,{variant:"outline",children:a.difficulty})]}),e.jsx("h1",{className:"font-display text-2xl md:text-3xl font-bold text-brand-green",children:a.title}),e.jsx("p",{className:"text-muted-foreground",children:a.description}),e.jsxs("div",{className:"flex items-center gap-6 text-sm text-muted-foreground",children:[a.estimated_hours&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ae,{size:14}),a.estimated_hours,"h"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(O,{size:14}),S," Lektionen"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ie,{size:14}),h.length," Module"]})]}),e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[!j&&e.jsxs(b,{onClick:k,className:"gap-2",children:[e.jsx(O,{size:16}),"Jetzt einschreiben"]}),j&&y&&u<100&&e.jsx(W,{to:`/dashboard/akademie/${r}/lektion/${y.id}`,children:e.jsxs(b,{className:"gap-2",children:[e.jsx(Y,{size:16}),s===0?"Kurs starten":"Weiterlernen"]})}),u===100&&!o&&e.jsxs(b,{onClick:v,disabled:L,className:"gap-2 bg-amber-500 hover:bg-amber-600 text-white",children:[e.jsx(V,{size:16}),L?"Wird generiert...":"KI-Zertifikat generieren"]}),o&&e.jsxs(b,{onClick:x,variant:"outline",className:"gap-2",children:[e.jsx(pe,{size:16}),"Zertifikat drucken / speichern"]})]})]}),o&&e.jsxs(q.div,{initial:{opacity:0,scale:.9}
6,animate:{opacity:1,scale:1},className:"w-full md:w-72 glass-card p-6 border-amber-500/30 text-center space-y-3",children:[e.jsx(V,{className:"mx-auto text-amber-500",size:40}),e.jsx("h3",{className:"font-display font-bold text-foreground",children:"Zertifikat erhalten"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["#",o.certificate_number]}),o.score&&e.jsxs("p",{className:"text-lg font-bold text-primary",children:[o.score,"%"]}),o.ai_feedback&&e.jsxs("p",{className:"text-sm text-muted-foreground italic",children:['"',o.ai_feedback,'"']}),e.jsxs(b,{onClick:x,variant:"outline",size:"sm",className:"gap-2 w-full mt-2",children:[e.jsx(ee,{size:14}),"Herunterladen"]})]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"font-display text-xl font-bold text-foreground",children:"Kursinhalt"}),h.map((t,m)=>{const i=t.lessons.every(l=>l.completed),C=t.lessons.filter(l=>l.completed).length,p=t.lessons.length>0?Math.round(C/t.lessons.length*100):0,g=D.has(t.id);return e.jsxs(q.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:m*.05},className:"glass-card overflow-hidden",children:[e.jsxs("button",{onClick:()=>A(t.id),className:"w-full p-5 flex items-center justify-between text-left hover:bg-secondary/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center text-sm font-bold ${i?"bg-green-500/10 text-green-500":"bg-primary/10 text-primary"}`,children:i?e.jsx(J,{size:16}):m+1}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-display font-bold text-foreground text-sm",children:t.title}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[C,"/",t.lessons.length," Lektionen · ",p,"%"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(le,{value:p,className:"w-24 h-2 hidden sm:block"}),g?e.jsx(ue,{size:16,className:"text-muted-foreground"}):e.jsx(xe,{size:16,className:"text-muted-foreground"})]})]}),g&&e.jsx("div",{className:"border-t border-border",children:t.lessons.map(l=>{const K=je[l.content_type]||X;return e.jsxs(W,{to:j?`/dashboard/akademie/${r}/lektion/${l.id}`:"#",className:`flex items-center gap-3 px-5 py-3 border-b border-border/50 last:border-0 transition-colors ${j?"hover:bg-secondary/30 cursor-pointer":"opacity-50 cursor-not-allowed"}`,onClick:P=>{j||P.preventDefault()},children:[e.jsx("div",{className:`w-7 h-7 rounded-md flex items-center justify-center ${l.completed?"bg-green-500/10 text-green-500":"bg-secondary text-muted-foreground"}`,children:l.completed?e.jsx(J,{size:14}):e.jsx(K,{size:14})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:`text-sm truncate ${l.completed?"text-muted-foreground line-through":"text-foreground"}`,children:l.title}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:ye[l.content_type]||l.content_type}),l.duration_minutes&&e.jsxs("span",{children:["· ",l.duration_minutes," Min."]})]})]}),!j&&e.jsx(fe,{size:14,className:"text-muted-foreground"})]},l.id)})})]},t.id)})]}),r&&e.jsx(ge,{courseId:r,isCompleted:u===100})]}):e.jsxs("div",{className:"p-6 md:p-8 lg:p-10 text-center",children:[e.jsx("p",{className:"text-muted-foreground",children:"Kurs nicht gefunden"}),e.jsx(W,{to:"/dashboard/akademie",children:e.jsx(b,{variant:"outline",className:"mt-4",children:"Zurück"})})]})};export{Ee 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.