"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { useQuery } from "@tanstack/react-query"; import { Award, Clock, Copy, ExternalLink, Loader2, Lock } from "lucide-react"; import { http, toUserError } from "@/lib/api"; import type { Certificate } from "@/lib/types"; import { Button } from "@/components/ui/button"; import { toast } from "@/components/providers"; import { cn } from "@/lib/utils"; type MineCertificateResponse = { certificate: Certificate | null; eligible: boolean; }; export function ProfileCertificateSlot() { const router = useRouter(); const { data, isLoading, isError, error, refetch } = useQuery({ queryKey: ["me", "certificate"], queryFn: () => http.get("/api/me/certificate"), }); const cert = data?.certificate ?? null; const eligible = !!data?.eligible; const copyLink = async () => { if (!cert?.publicId) return; const url = `${window.location.origin}/c/${cert.publicId}`; try { await navigator.clipboard.writeText(url); toast.success("لینک گواهینامه کپی شد"); } catch { toast.error("کپی ممکن نشد"); } }; const openCert = () => { if (!cert?.publicId) return; router.push(`/c/${cert.publicId}`); }; return (

گواهینامه پایان دوره

جایگاه ثابت گواهی شما در پروفایل

{isError ? (

{toUserError(error)}

) : isLoading ? (
در حال بارگذاری…
) : cert?.status === "pending" ? (

در انتظار تأیید

درخواست گواهینامه ثبت شد و پس از بررسی توسط تیم آموزش صادر می‌شود.

) : cert?.status === "issued" && cert.publicId ? (

{cert.fullName}

صادر شده در {new Date(cert.issuedAt).toLocaleDateString("fa-IR")}

{cert.publicId}

) : eligible ? (

در انتظار تأیید

درخواست گواهینامه ثبت شد و پس از بررسی توسط تیم آموزش صادر می‌شود.

) : (

هنوز صادر نشده

با پاس کردن همه درس‌های فعال، گواهینامه همین‌جا نمایش داده می‌شود.

)}
); }