import{u as F,q as P,s as W,r as v,j as t,A as E,C as $,t as A,F as G,v as U}from"./vendor-BKmmeuxg.js";import{B as I}from"./button-BpNwv2aE.js";import{C as z}from"./card-D9_SJYq6.js";import{L as y}from"./label-HmIcv5Yx.js";import{R as B,a as _}from"./radio-group-C0C2vfl-.js";import{E as M}from"./jspdf.es.min-BFMcGtlR.js";import{t as C}from"./index-D9-QKOod.js";import"./index-WW_1X1qx.js";import"./utils-DxSsnXxD.js";const te=()=>{const{props:h}=F(),{translate:T}=h,{frontend:s}=T,m=h.course.title,f=h.auth.user.name,b=P(W(h.watchHistory.completion_date),"MMM d, yyyy"),[u,S]=v.useState("png"),j=v.useRef(null),i={width:900,height:600},R=()=>{j.current&&(u==="pdf"?D():k())},k=()=>{const e=document.createElement("canvas"),a=e.getContext("2d");a&&(e.width=i.width,e.height=i.height,N(a,i),e.toBlob(r=>{if(!r)return;const o=URL.createObjectURL(r),l=document.createElement("a");l.href=o,l.download=`${f}_${m}_Certificate.png`,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(o),C.success(s.png_certificate_saved)},"image/png"))},D=()=>{const e=i.width>i.height,a=new M({orientation:e?"landscape":"portrait",unit:"px",format:[i.width,i.height]}),r=document.createElement("canvas"),o=r.getContext("2d");if(!o)return;r.width=i.width,r.height=i.height,N(o,i);const l=r.toDataURL("image/png");a.addImage(l,"PNG",0,0,i.width,i.height),a.save(`${f}_${m}_Certificate.pdf`),C.success(s.pdf_certificate_saved)},L=(e,a,r,o,l,x)=>{const n=a.split(" ");let c="",p="";const g=[];for(let d=0;dl&&d>0?(g.push({text:c.trim(),width:e.measureText(c).width}),p=`${n[d]} `,c=`${n[d]} `):c=p;g.push({text:c.trim(),width:e.measureText(c).width});let w=o;return g.forEach(d=>{e.fillText(d.text,r,w),w+=x}),w},N=(e,a)=>{const r=e.createLinearGradient(0,0,a.width,a.height);r.addColorStop(0,"#dbeafe"),r.addColorStop(1,"#e0e7ff"),e.fillStyle=r,e.fillRect(0,0,a.width,a.height),e.strokeStyle="#f59e0b",e.lineWidth=8,e.strokeRect(20,20,a.width-40,a.height-40),e.strokeStyle="#3730a3",e.lineWidth=2,e.strokeRect(40,40,a.width-80,a.height-80),e.fillStyle="#1f2937",e.textAlign="center",e.font="bold 42px serif",e.fillText(s.certificate_of_completion,a.width/2,120),e.strokeStyle="#f59e0b",e.lineWidth=3,e.beginPath(),e.moveTo(a.width/2-150,140),e.lineTo(a.width/2+150,140),e.stroke(),e.font="22px serif",e.fillStyle="#4b5563",e.textAlign="center";const o=s.certificate_description,l=30,x=a.width-100;L(e,o,a.width/2,190,x,l),e.font="bold 36px serif",e.fillStyle="#3730a3",e.fillText(f,a.width/2,310);const n=e.measureText(f).width;e.strokeStyle="#f59e0b",e.lineWidth=3,e.beginPath(),e.moveTo((a.width-n)/2-20,330),e.lineTo((a.width+n)/2+20,330),e.stroke(),e.font="22px serif",e.fillStyle="#4b5563",e.fillText(s.has_successfully_completed,a.width/2,380),e.font="bold 28px serif",e.fillStyle="#3730a3",e.fillText(m,a.width/2,430),e.font="18px serif",e.fillStyle="#6b7280",e.fillText(s.completed_on.replace(":date",b),a.width/2,490),e.font="16px serif",e.fillStyle="#9ca3af",e.fillText(s.authorized_certificate,a.width/2,a.height-60)};return t.jsxs("div",{className:"mx-auto max-w-[800px] space-y-8 pt-10 pb-16",children:[t.jsxs("div",{className:"text-center",children:[t.jsx("h1",{className:"mb-4 text-4xl font-bold text-gray-800",children:s.course_certificate_download}),t.jsx("p",{className:"text-muted-foreground text-lg",children:s.download_official_certificate})]}),t.jsxs(z,{className:"space-y-7 p-6",children:[t.jsxs("div",{ref:j,className:"relative flex flex-col justify-center rounded-lg border-4 border-amber-400 bg-gradient-to-br from-blue-50 to-indigo-100 p-6 text-center",children:[t.jsx("div",{className:"absolute inset-4 rounded border-2 border-indigo-700"}),t.jsxs("div",{className:"relative z-10",children:[t.jsxs("div",{className:"mb-6",children:[t.jsx(E,{className:"mx-auto mb-3 h-12 w-12 text-amber-600"}),t.jsx("h2",{className:"mb-2 font-serif text-2xl font-bold text-gray-800",children:s.certificate_of_completion}),t.jsx("div",{className:"mx-auto h-0.5 w-32 bg-amber-400"})]}),t.jsxs("div",{className:"space-y-4 text-gray-700",children:[t.jsx("p",{className:"font-serif text-lg",children:s.certificate_description}),t.jsxs("div",{className:"relative",children:[t.jsx("p",{className:"mx-8 pb-2 font-serif text-2xl font-bold text-indigo-800",children:f||"Student Name"}),t.jsx("div",{className:"absolute bottom-0 left-1/2 h-0.5 w-48 -translate-x-1/2 transform bg-amber-400"})]}),t.jsx("p",{className:"font-serif text-lg",children:s.has_successfully_completed}),t.jsx("p",{className:"font-serif text-xl font-semibold text-indigo-700",children:m||"Course Name"}),t.jsxs("div",{className:"mt-6 flex items-center justify-center gap-2",children:[t.jsx($,{className:"text-muted-foreground h-4 w-4"}),t.jsx("p",{className:"text-muted-foreground font-serif text-sm",children:s.completed_on.replace(":date",b||"Date")})]})]}),t.jsx("div",{className:"mt-6 border-t border-amber-400 pt-4",children:t.jsx("p",{className:"font-serif text-sm text-gray-500",children:s.authorized_certificate})})]})]}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs(B,{value:u,onValueChange:S,className:"flex justify-center space-x-6",children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx(_,{className:"cursor-pointer",value:"png",id:"png"}),t.jsxs(y,{htmlFor:"png",className:"flex cursor-pointer items-center gap-2",children:[t.jsx(A,{className:"h-4 w-4"}),"PNG Image"]})]}),t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx(_,{className:"cursor-pointer",value:"pdf",id:"pdf"}),t.jsxs(y,{htmlFor:"pdf",className:"flex cursor-pointer items-center gap-2",children:[t.jsx(G,{className:"h-4 w-4"}),"PDF Document"]})]})]}),t.jsxs(I,{variant:"outline",className:"w-full",onClick:R,children:[t.jsx(U,{className:"mr-2 h-4 w-4"}),"Download as ",u.toUpperCase()]})]})]})]})};export{te as default};