"use client";

import { useEffect, useState } from "react";
import Link from "next/link";

type CertificationImage = {
  id: number;
  image: string;
  certificationId: number;
  createdAt: string;
};

type Certification = {
  id: number;
  name: string;
  issuer: string;
  credentialId: string | null;
  issueDate: string;
  expiryDate: string | null;
  image: string | null;
  description: string | null;

  // SESUAI DENGAN API / PRISMA
  certificationimage: CertificationImage[];
};

export default function CertificationsAdminPage() {
  const [certifications, setCertifications] = useState<
    Certification[]
  >([]);

  const [loading, setLoading] = useState(true);
  const [sidebarOpen, setSidebarOpen] = useState(false);
  const [deletingId, setDeletingId] = useState<number | null>(null);

  // =========================
  // GET CERTIFICATIONS
  // =========================

  const getCertifications = async () => {
    try {
      setLoading(true);

      const response = await fetch("/api/certifications", {
        cache: "no-store",
      });

      const result = await response.json();

      if (result.success) {
        setCertifications(result.data);
      } else {
        console.error(result.message);
      }
    } catch (error) {
      console.error("GET CERTIFICATIONS:", error);
    } finally {
      setLoading(false);
    }
  };

  useEffect(() => {
    getCertifications();
  }, []);

  // =========================
  // DELETE CERTIFICATION
  // =========================

  const deleteCertification = async (id: number) => {
    const confirmDelete = window.confirm(
      "Yakin ingin menghapus certification ini?"
    );

    if (!confirmDelete) return;

    try {
      setDeletingId(id);

      const response = await fetch(
        `/api/certifications?id=${id}`,
        {
          method: "DELETE",
        }
      );

      const result = await response.json();

      if (!response.ok || !result.success) {
        alert(
          result.message ||
            "Gagal menghapus certification"
        );
        return;
      }

      await getCertifications();
    } catch (error) {
      console.error(
        "DELETE CERTIFICATION:",
        error
      );

      alert(
        "Gagal menghapus certification"
      );
    } finally {
      setDeletingId(null);
    }
  };

  // =========================
  // STATISTICS
  // =========================

  const totalCertification =
    certifications.length;

  const certificationWithImage =
    certifications.filter((certification) => {
      const images =
        certification.certificationimage &&
        certification.certificationimage.length > 0
          ? certification.certificationimage
          : certification.image
          ? [certification.image]
          : [];

      return images.length > 0;
    }).length;

  const certificationWithoutImage =
    totalCertification -
    certificationWithImage;

  return (
    <>
      <style>{`
        * {
          box-sizing: border-box;
        }

        /* =====================================================
           LAYOUT
        ===================================================== */

        .admin-layout {
          min-height: 100vh;
          background: #f5f7f9;
          color: #1f2937;
        }

        /* =====================================================
           SIDEBAR
        ===================================================== */

        .admin-sidebar {
          position: fixed;
          top: 0;
          left: 0;
          width: 260px;
          height: 100vh;
          background: #ffffff;
          border-right: 1px solid #e9ecef;
          z-index: 1050;
          transition: transform 0.3s ease;
          overflow-y: auto;
        }

        .sidebar-inner {
          min-height: 100%;
          display: flex;
          flex-direction: column;
          padding: 22px 16px;
        }

        .sidebar-brand {
          display: flex;
          align-items: center;
          gap: 12px;
          padding: 4px 8px 24px;
          border-bottom: 1px solid #eef0f2;
        }

        .brand-icon {
          width: 42px;
          height: 42px;
          border-radius: 12px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #198754;
          color: #ffffff;
          font-size: 19px;
          box-shadow:
            0 8px 20px rgba(25, 135, 84, 0.18);
          flex-shrink: 0;
        }

        .brand-text {
          min-width: 0;
          line-height: 1.15;
        }

        .brand-text strong {
          display: block;
          font-size: 15px;
          font-weight: 700;
          color: #17202a;
        }

        .brand-text span {
          display: block;
          margin-top: 4px;
          font-size: 11px;
          color: #8a94a6;
          letter-spacing: 0.4px;
        }

        .sidebar-close {
          margin-left: auto;
          border: 0;
          background: transparent;
          color: #6c757d;
          font-size: 18px;
        }

        .sidebar-section-label {
          padding: 20px 10px 8px;
          font-size: 10px;
          font-weight: 700;
          color: #a0a8b3;
          letter-spacing: 1.1px;
        }

        .sidebar-nav {
          display: flex;
          flex-direction: column;
          gap: 3px;
        }

        .sidebar-link {
          display: flex;
          align-items: center;
          gap: 12px;
          min-height: 44px;
          padding: 9px 12px;
          border-radius: 10px;
          color: #667085;
          text-decoration: none;
          font-size: 13px;
          font-weight: 500;
          transition:
            background 0.2s ease,
            color 0.2s ease,
            transform 0.2s ease;
        }

        .sidebar-link:hover {
          background: #f0f9f4;
          color: #198754;
          transform: translateX(2px);
        }

        .sidebar-link.active {
          background: #e9f7ef;
          color: #198754;
          font-weight: 600;
        }

        .sidebar-link-icon {
          width: 20px;
          display: flex;
          justify-content: center;
          font-size: 16px;
          flex-shrink: 0;
        }

        .sidebar-bottom {
          margin-top: auto;
          padding-top: 20px;
          border-top: 1px solid #eef0f2;
        }

        .sidebar-website {
          display: flex;
          align-items: center;
          gap: 10px;
          padding: 11px 12px;
          border-radius: 10px;
          color: #667085;
          text-decoration: none;
          font-size: 13px;
          transition: all 0.2s ease;
        }

        .sidebar-website:hover {
          background: #f5f7f9;
          color: #198754;
        }

        /* =====================================================
           MAIN
        ===================================================== */

        .admin-main {
          margin-left: 260px;
          min-height: 100vh;
          width: calc(100% - 260px);
        }

        /* =====================================================
           TOPBAR
        ===================================================== */

        .admin-topbar {
          height: 76px;
          background: rgba(255, 255, 255, 0.96);
          border-bottom: 1px solid #e9ecef;
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 0 32px;
          position: sticky;
          top: 0;
          z-index: 1000;
          backdrop-filter: blur(12px);
        }

        .topbar-left,
        .topbar-right {
          display: flex;
          align-items: center;
        }

        .topbar-left {
          gap: 14px;
        }

        .topbar-right {
          gap: 10px;
        }

        .mobile-menu-button {
          width: 40px;
          height: 40px;
          border: 1px solid #e5e7eb;
          background: #ffffff;
          color: #475467;
          border-radius: 9px;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 20px;
        }

        .topbar-label {
          font-size: 10px;
          font-weight: 700;
          color: #98a2b3;
          letter-spacing: 1px;
          margin-bottom: 2px;
        }

        .topbar-title {
          font-size: 15px;
          font-weight: 700;
          color: #1d2939;
        }

        .topbar-website,
        .topbar-logout {
          min-height: 40px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
          padding: 8px 13px;
          border-radius: 9px;
          text-decoration: none;
          font-size: 13px;
          font-weight: 600;
          transition: all 0.2s ease;
          white-space: nowrap;
        }

        .topbar-website {
          color: #475467;
          border: 1px solid #e4e7ec;
          background: #ffffff;
        }

        .topbar-website:hover {
          color: #198754;
          border-color: #b7dfc9;
          background: #f4fbf7;
        }

        .topbar-logout {
          color: #dc3545;
          background: #fff5f5;
          border: 1px solid #ffd6d9;
        }

        .topbar-logout:hover {
          background: #dc3545;
          border-color: #dc3545;
          color: #ffffff;
        }

        /* =====================================================
           CONTENT
        ===================================================== */

        .admin-content {
          padding: 32px;
          max-width: 1600px;
          margin: 0 auto;
        }

        .page-heading {
          display: flex;
          align-items: flex-end;
          justify-content: space-between;
          gap: 25px;
          margin-bottom: 28px;
        }

        .page-heading-left {
          min-width: 0;
        }

        .back-dashboard {
          display: inline-flex;
          align-items: center;
          gap: 7px;
          color: #667085;
          text-decoration: none;
          font-size: 12px;
          font-weight: 600;
          margin-bottom: 17px;
          transition: color 0.2s ease;
        }

        .back-dashboard:hover {
          color: #198754;
        }

        .page-title-row {
          display: flex;
          align-items: center;
          gap: 14px;
        }

        .page-title-icon {
          width: 48px;
          height: 48px;
          border-radius: 13px;
          background: #e9f7ef;
          color: #198754;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 21px;
          flex-shrink: 0;
        }

        .page-eyebrow {
          color: #198754;
          font-size: 10px;
          font-weight: 700;
          letter-spacing: 1.2px;
          margin-bottom: 4px;
        }

        .page-title {
          margin: 0;
          font-size: clamp(24px, 3vw, 32px);
          line-height: 1.15;
          font-weight: 750;
          color: #101828;
        }

        .page-description {
          margin: 7px 0 0;
          color: #667085;
          font-size: 13px;
          line-height: 1.7;
          max-width: 700px;
          text-align: justify;
        }

        .page-heading-action {
          flex-shrink: 0;
        }

        .add-button {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
          min-height: 44px;
          padding: 10px 17px;
          border-radius: 10px;
          background: #198754;
          color: #ffffff;
          text-decoration: none;
          font-size: 13px;
          font-weight: 600;
          border: 0;
          box-shadow:
            0 7px 18px rgba(25, 135, 84, 0.16);
          transition: all 0.2s ease;
        }

        .add-button:hover {
          background: #157347;
          color: #ffffff;
          transform: translateY(-1px);
          box-shadow:
            0 10px 22px rgba(25, 135, 84, 0.2);
        }

        /* =====================================================
           STATISTICS
        ===================================================== */

        .stats-grid {
          display: grid;
          grid-template-columns:
            repeat(4, minmax(0, 1fr));
          gap: 16px;
          margin-bottom: 24px;
        }

        .stat-card {
          background: #ffffff;
          border: 1px solid #eaecf0;
          border-radius: 14px;
          padding: 18px;
          display: flex;
          align-items: center;
          gap: 14px;
          box-shadow:
            0 2px 7px rgba(16, 24, 40, 0.025);
          transition: all 0.25s ease;
        }

        .stat-card:hover {
          transform: translateY(-2px);
          box-shadow:
            0 9px 24px rgba(16, 24, 40, 0.07);
        }

        .stat-icon {
          width: 43px;
          height: 43px;
          border-radius: 11px;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 17px;
          flex-shrink: 0;
        }

        .stat-icon.green {
          background: #e9f7ef;
          color: #198754;
        }

        .stat-icon.success {
          background: #eaf8f0;
          color: #198754;
        }

        .stat-icon.secondary {
          background: #f2f4f7;
          color: #667085;
        }

        .stat-icon.blue {
          background: #eef4ff;
          color: #3b82f6;
        }

        .stat-label {
          font-size: 11px;
          color: #98a2b3;
          font-weight: 600;
          margin-bottom: 3px;
        }

        .stat-value {
          font-size: 21px;
          line-height: 1;
          font-weight: 750;
          color: #101828;
        }

        .stat-status {
          font-size: 13px;
          font-weight: 700;
          color: #198754;
        }

        /* =====================================================
           CONTENT CARD
        ===================================================== */

        .content-card {
          background: #ffffff;
          border: 1px solid #eaecf0;
          border-radius: 16px;
          overflow: hidden;
          box-shadow:
            0 3px 12px rgba(16, 24, 40, 0.035);
        }

        .content-card-header {
          padding: 21px 24px;
          border-bottom: 1px solid #eaecf0;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 20px;
        }

        .content-card-eyebrow {
          font-size: 10px;
          font-weight: 700;
          color: #198754;
          letter-spacing: 1px;
          margin-bottom: 4px;
        }

        .content-card-title {
          font-size: 17px;
          font-weight: 750;
          color: #101828;
          margin: 0;
        }

        .content-card-description {
          margin: 5px 0 0;
          color: #667085;
          font-size: 12px;
          line-height: 1.65;
          text-align: justify;
        }

        .content-card-count {
          min-width: 38px;
          height: 38px;
          padding: 0 10px;
          display: flex;
          align-items: center;
          justify-content: center;
          gap: 7px;
          border-radius: 10px;
          background: #f5f7f9;
          color: #667085;
          font-size: 12px;
          font-weight: 700;
          flex-shrink: 0;
        }

        /* =====================================================
           TABLE
        ===================================================== */

        .certification-table-wrapper {
          width: 100%;
          overflow-x: auto;
          -webkit-overflow-scrolling: touch;
        }

        .certification-table {
          width: 100%;
          min-width: 1050px;
          border-collapse: separate;
          border-spacing: 0;
          margin: 0;
        }

        .certification-table thead th {
          background: #f8fafc;
          color: #667085;
          font-size: 10px;
          font-weight: 700;
          letter-spacing: 0.55px;
          text-transform: uppercase;
          padding: 14px 18px;
          border-bottom: 1px solid #eaecf0;
          white-space: nowrap;
        }

        .certification-table tbody td {
          padding: 16px 18px;
          border-bottom: 1px solid #f0f2f4;
          color: #475467;
          font-size: 12px;
          vertical-align: middle;
        }

        .certification-table tbody tr:last-child td {
          border-bottom: 0;
        }

        .certification-table tbody tr {
          transition: background 0.2s ease;
        }

        .certification-table tbody tr:hover {
          background: #fcfffd;
        }

        /* =====================================================
           CERTIFICATION INFORMATION
        ===================================================== */

        .certification-info {
          display: flex;
          align-items: center;
          gap: 14px;
          min-width: 330px;
        }

        .certification-images {
          width: 132px;
          min-width: 132px;
          display: flex;
          align-items: center;
          gap: 4px;
        }

        .certification-image {
          width: 42px;
          height: 45px;
          border-radius: 7px;
          object-fit: cover;
          display: block;
          border: 1px solid #e8ecef;
          background: #f5f7f9;
        }

        .more-images {
          width: 42px;
          height: 45px;
          border-radius: 7px;
          background: #f2f4f7;
          color: #667085;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 10px;
          font-weight: 700;
          flex-shrink: 0;
        }

        .no-image-preview {
          width: 132px;
          min-width: 132px;
          height: 45px;
          border-radius: 8px;
          background: #f5f7f9;
          color: #98a2b3;
          display: flex;
          align-items: center;
          justify-content: center;
          border: 1px solid #eaecf0;
        }

        .certification-details {
          min-width: 0;
        }

        .certification-name {
          color: #101828;
          font-size: 13px;
          font-weight: 700;
          line-height: 1.45;
          word-break: break-word;
        }

        .certification-description {
          margin-top: 4px;
          max-width: 320px;
          color: #667085;
          font-size: 11px;
          line-height: 1.6;
          text-align: justify;
          word-break: break-word;
        }

        .image-count {
          display: inline-flex;
          align-items: center;
          gap: 5px;
          margin-top: 6px;
          color: #198754;
          font-size: 10px;
          font-weight: 600;
        }

        /* =====================================================
           ISSUER / CREDENTIAL
        ===================================================== */

        .issuer-text {
          color: #344054;
          font-size: 12px;
          font-weight: 600;
          line-height: 1.5;
          max-width: 180px;
          word-break: break-word;
        }

        .credential-text {
          display: inline-block;
          max-width: 180px;
          padding: 5px 8px;
          border-radius: 6px;
          background: #f5f7f9;
          color: #667085;
          font-family: monospace;
          font-size: 10px;
          line-height: 1.4;
          word-break: break-all;
        }

        .date-text {
          color: #475467;
          font-size: 11px;
          font-weight: 600;
          white-space: nowrap;
        }

        .date-expired {
          color: #dc3545;
        }

        .date-active {
          color: #198754;
        }

        .image-count-badge {
          display: inline-flex;
          align-items: center;
          gap: 5px;
          padding: 6px 9px;
          border-radius: 7px;
          background: #e9f7ef;
          color: #198754;
          font-size: 10px;
          font-weight: 700;
        }

        .no-image-text {
          color: #98a2b3;
          font-size: 11px;
        }

        /* =====================================================
           ACTION
        ===================================================== */

        .action-group {
          display: flex;
          align-items: center;
          justify-content: flex-end;
          gap: 7px;
          white-space: nowrap;
        }

        .action-button {
          min-height: 35px;
          padding: 7px 10px;
          border-radius: 8px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 5px;
          font-size: 11px;
          font-weight: 600;
          cursor: pointer;
          text-decoration: none;
          transition: all 0.2s ease;
        }

        .edit-button {
          color: #0d6efd;
          background: #f0f6ff;
          border: 1px solid #dbeafe;
        }

        .edit-button:hover {
          color: #ffffff;
          background: #0d6efd;
          border-color: #0d6efd;
        }

        .delete-button {
          color: #dc3545;
          background: #fff5f5;
          border: 1px solid #ffd9dc;
        }

        .delete-button:hover {
          color: #ffffff;
          background: #dc3545;
          border-color: #dc3545;
        }

        .delete-button:disabled {
          opacity: 0.6;
          cursor: not-allowed;
        }

        /* =====================================================
           MOBILE CERTIFICATION CARD
        ===================================================== */

        .mobile-certification-list {
          display: none;
        }

        .mobile-certification-card {
          border: 1px solid #edf0f2;
          border-radius: 13px;
          background: #ffffff;
          padding: 16px;
          transition: all 0.2s ease;
        }

        .mobile-certification-card:hover {
          border-color: #cfe8d9;
          background: #fcfffd;
          box-shadow:
            0 7px 20px rgba(25, 135, 84, 0.055);
        }

        .mobile-certification-top {
          display: flex;
          align-items: flex-start;
          gap: 13px;
        }

        .mobile-certification-main {
          flex: 1;
          min-width: 0;
        }

        .mobile-certification-name {
          color: #101828;
          font-size: 14px;
          font-weight: 700;
          line-height: 1.45;
          word-break: break-word;
        }

        .mobile-certification-issuer {
          margin-top: 4px;
          color: #667085;
          font-size: 11px;
          line-height: 1.5;
          word-break: break-word;
        }

        .mobile-certification-images {
          margin-top: 14px;
          display: flex;
          align-items: center;
          gap: 5px;
          overflow: hidden;
        }

        .mobile-certification-images
        .certification-image {
          width: 48px;
          height: 52px;
        }

        .mobile-certification-images
        .more-images {
          width: 48px;
          height: 52px;
        }

        .mobile-description {
          margin-top: 13px;
          padding-top: 13px;
          border-top: 1px solid #f0f2f4;
          color: #667085;
          font-size: 11px;
          line-height: 1.7;
          text-align: justify;
          word-break: break-word;
        }

        .mobile-info-grid {
          display: grid;
          grid-template-columns: repeat(2, minmax(0, 1fr));
          gap: 10px;
          margin-top: 14px;
        }

        .mobile-info-box {
          min-width: 0;
          padding: 10px;
          border-radius: 9px;
          background: #f8fafc;
          border: 1px solid #edf0f2;
        }

        .mobile-info-label {
          margin-bottom: 4px;
          color: #98a2b3;
          font-size: 9px;
          font-weight: 700;
          letter-spacing: 0.5px;
          text-transform: uppercase;
        }

        .mobile-info-value {
          color: #344054;
          font-size: 10px;
          font-weight: 600;
          line-height: 1.5;
          word-break: break-word;
        }

        .mobile-info-value.credential {
          font-family: monospace;
          word-break: break-all;
        }

        .mobile-actions {
          display: grid;
          grid-template-columns: 1fr 1fr;
          gap: 8px;
          margin-top: 14px;
        }

        .mobile-actions .action-button {
          width: 100%;
          min-height: 40px;
        }

        /* =====================================================
           LOADING
        ===================================================== */

        .loading-state {
          min-height: 300px;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          text-align: center;
          padding: 40px 20px;
        }

        .loading-spinner {
          width: 42px;
          height: 42px;
          border: 3px solid #dcefe4;
          border-top-color: #198754;
          border-radius: 50%;
          animation: spin 0.8s linear infinite;
          margin-bottom: 15px;
        }

        .loading-state h5 {
          font-size: 15px;
          font-weight: 700;
          color: #344054;
          margin-bottom: 5px;
        }

        .loading-state p {
          color: #98a2b3;
          font-size: 12px;
          margin: 0;
        }

        @keyframes spin {
          to {
            transform: rotate(360deg);
          }
        }

        /* =====================================================
           EMPTY
        ===================================================== */

        .empty-state {
          min-height: 330px;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          text-align: center;
          padding: 45px 20px;
        }

        .empty-icon {
          width: 66px;
          height: 66px;
          border-radius: 18px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #f2f4f7;
          color: #98a2b3;
          font-size: 27px;
          margin-bottom: 17px;
        }

        .empty-state h5 {
          font-size: 16px;
          font-weight: 750;
          color: #344054;
          margin-bottom: 6px;
        }

        .empty-state p {
          color: #98a2b3;
          font-size: 12px;
          max-width: 420px;
          line-height: 1.7;
          text-align: center;
          margin-bottom: 18px;
        }

        /* =====================================================
           FOOTER
        ===================================================== */

        .admin-page-footer {
          padding: 22px 2px 8px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
          color: #98a2b3;
          font-size: 11px;
        }

        .admin-page-footer-left {
          display: flex;
          align-items: center;
          gap: 7px;
        }

        .admin-page-footer a {
          color: #667085;
          text-decoration: none;
          font-weight: 600;
        }

        .admin-page-footer a:hover {
          color: #198754;
        }

        /* =====================================================
           OVERLAY
        ===================================================== */

        .sidebar-overlay {
          display: none;
          position: fixed;
          inset: 0;
          background: rgba(15, 23, 42, 0.38);
          z-index: 1040;
          backdrop-filter: blur(2px);
        }

        /* =====================================================
           TABLET
        ===================================================== */

        @media (max-width: 1199.98px) {
          .stats-grid {
            grid-template-columns:
              repeat(2, minmax(0, 1fr));
          }

          .admin-content {
            padding: 28px;
          }
        }

        /* =====================================================
           TABLET / MOBILE
        ===================================================== */

        @media (max-width: 991.98px) {
          .admin-sidebar {
            transform: translateX(-100%);
            box-shadow:
              12px 0 30px rgba(15, 23, 42, 0.1);
          }

          .admin-sidebar.sidebar-open {
            transform: translateX(0);
          }

          .sidebar-overlay.sidebar-overlay-show {
            display: block;
          }

          .admin-main {
            width: 100%;
            margin-left: 0;
          }

          .admin-topbar {
            padding: 0 20px;
          }

          .admin-content {
            padding: 25px 20px;
          }

          .page-heading {
            align-items: flex-start;
            flex-direction: column;
          }

          .page-heading-action {
            width: 100%;
          }

          .add-button {
            width: 100%;
          }

          .certification-table-wrapper {
            overflow-x: auto;
          }
        }

        /* =====================================================
           MOBILE
        ===================================================== */

        @media (max-width: 767.98px) {
          .certification-table-wrapper {
            display: none;
          }

          .mobile-certification-list {
            display: flex;
            flex-direction: column;
            gap: 12px;
            padding: 12px;
          }

          .content-card-header {
            padding: 18px;
          }

          .content-card-count {
            width: 38px;
          }

          .page-description {
            max-width: 100%;
          }
        }

        /* =====================================================
           SMALL MOBILE
        ===================================================== */

        @media (max-width: 575.98px) {
          .admin-topbar {
            height: 68px;
            padding: 0 14px;
          }

          .topbar-right {
            gap: 6px;
          }

          .topbar-website,
          .topbar-logout {
            width: 38px;
            height: 38px;
            min-height: 38px;
            padding: 0;
          }

          .topbar-website span,
          .topbar-logout span {
            display: none !important;
          }

          .admin-content {
            padding: 20px 14px;
          }

          .page-title-row {
            align-items: flex-start;
          }

          .page-title-icon {
            width: 43px;
            height: 43px;
            border-radius: 11px;
            font-size: 18px;
          }

          .page-title {
            font-size: 25px;
          }

          .page-description {
            font-size: 12px;
          }

          .stats-grid {
            grid-template-columns: 1fr 1fr;
            gap: 10px;
          }

          .stat-card {
            padding: 13px;
            gap: 10px;
          }

          .stat-icon {
            width: 36px;
            height: 36px;
            font-size: 14px;
          }

          .stat-label {
            font-size: 9px;
          }

          .stat-value {
            font-size: 17px;
          }

          .stat-status {
            font-size: 10px;
          }

          .content-card-header {
            padding: 17px;
          }

          .content-card-title {
            font-size: 15px;
          }

          .content-card-description {
            font-size: 11px;
          }

          .mobile-certification-card {
            padding: 14px;
          }

          .mobile-certification-name {
            font-size: 13px;
          }

          .mobile-info-grid {
            gap: 8px;
          }

          .mobile-info-box {
            padding: 9px;
          }

          .mobile-actions {
            grid-template-columns: 1fr 1fr;
          }

          .admin-page-footer {
            flex-direction: column;
            align-items: flex-start;
          }
        }

        /* =====================================================
           EXTRA SMALL
        ===================================================== */

        @media (max-width: 380px) {
          .stats-grid {
            grid-template-columns: 1fr;
          }

          .mobile-info-grid {
            grid-template-columns: 1fr;
          }

          .mobile-actions {
            grid-template-columns: 1fr;
          }

          .page-title {
            font-size: 23px;
          }
        }
      `}</style>

      <div className="admin-layout">

        {/* =====================================================
            MOBILE OVERLAY
        ===================================================== */}

        <div
          className={`sidebar-overlay ${
            sidebarOpen
              ? "sidebar-overlay-show"
              : ""
          }`}
          onClick={() =>
            setSidebarOpen(false)
          }
        />

        {/* =====================================================
            SIDEBAR
        ===================================================== */}

        <aside
          className={`admin-sidebar ${
            sidebarOpen
              ? "sidebar-open"
              : ""
          }`}
        >
          <div className="sidebar-inner">

            {/* BRAND */}

            <div className="sidebar-brand">

              <div className="brand-icon">
                <i className="bi bi-grid-1x2-fill"></i>
              </div>

              <div className="brand-text">
                <strong>
                  GloVaTech
                </strong>

                <span>
                  Admin Panel
                </span>
              </div>

              <button
                type="button"
                className="sidebar-close d-lg-none"
                onClick={() =>
                  setSidebarOpen(false)
                }
                aria-label="Tutup sidebar"
              >
                <i className="bi bi-x-lg"></i>
              </button>

            </div>

            {/* MAIN MENU */}

            <div className="sidebar-section-label">
              MAIN MENU
            </div>

            <nav className="sidebar-nav">

              <Link
                href="/secure-panel"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-speedometer2"></i>
                </span>

                <span>
                  Dashboard
                </span>
              </Link>

            </nav>

            {/* CONTENT */}

            <div className="sidebar-section-label">
              CONTENT
            </div>

            <nav className="sidebar-nav">

              <Link
                href="/secure-panel/hero"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-stars"></i>
                </span>

                <span>
                  Hero
                </span>
              </Link>

              <Link
                href="/secure-panel/about"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-person-vcard"></i>
                </span>

                <span>
                  About
                </span>
              </Link>

              <Link
                href="/secure-panel/about/stats"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-bar-chart"></i>
                </span>

                <span>
                  About Stats
                </span>
              </Link>

              <Link
                href="/secure-panel/education"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-mortarboard"></i>
                </span>

                <span>
                  Education
                </span>
              </Link>

              <Link
                href="/secure-panel/skills"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-tools"></i>
                </span>

                <span>
                  Skills
                </span>
              </Link>

              <Link
                href="/secure-panel/experience"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-briefcase"></i>
                </span>

                <span>
                  Experience
                </span>
              </Link>

              <Link
                href="/secure-panel/projects"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-code-square"></i>
                </span>

                <span>
                  Projects
                </span>
              </Link>

              <Link
                href="/secure-panel/certifications"
                className="sidebar-link active"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-patch-check"></i>
                </span>

                <span>
                  Certification
                </span>
              </Link>

              <Link
                href="/secure-panel/achievements"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-trophy"></i>
                </span>

                <span>
                  Achievement
                </span>
              </Link>

              <Link
                href="/secure-panel/services"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-gear-wide-connected"></i>
                </span>

                <span>
                  Services
                </span>
              </Link>

              <Link
                href="/secure-panel/gallery"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-images"></i>
                </span>

                <span>
                  Gallery
                </span>
              </Link>

              <Link
                href="/secure-panel/contact-info"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-person-lines-fill"></i>
                </span>

                <span>
                  Contact
                </span>
              </Link>

              <Link
  href="/secure-panel/contact-info/list"
  className="sidebar-link"
  onClick={() =>
    setSidebarOpen(false)
  }
>
  <span className="sidebar-link-icon">
    <i className="bi bi-share-fill"></i>
  </span>

  <span>Contact Social Media</span>
</Link>

              <Link
                href="/secure-panel/articles"
                className="sidebar-link"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-journal-text"></i>
                </span>

                <span>
                  Articles
                </span>
              </Link>

              <Link
  href="/secure-panel/contact-messages"
  className="sidebar-link"
  onClick={() =>
    setSidebarOpen(false)
  }
>
  <span className="sidebar-link-icon">
    <i className="bi bi-chat-left-text"></i>
  </span>

  <span>
    Contact Messages
  </span>
</Link>

<Link
  href="/secure-panel/contact-users"
  className="sidebar-link"
  onClick={() =>
    setSidebarOpen(false)
  }
>
  <span className="sidebar-link-icon">
    <i className="bi bi-people-fill"></i>
  </span>

  <span>
    Contact User
  </span>
</Link>

            </nav>

            {/* WEBSITE */}

            <div className="sidebar-bottom">

              <Link
                href="/"
                className="sidebar-website"
              >
                <i className="bi bi-globe2"></i>

                <span>
                  View Website
                </span>

                <i className="bi bi-arrow-up-right ms-auto"></i>
              </Link>

            </div>

          </div>
        </aside>

        {/* =====================================================
            MAIN
        ===================================================== */}

        <div className="admin-main">

          {/* ===================================================
              TOPBAR
          =================================================== */}

          <header className="admin-topbar">

            <div className="topbar-left">

              <button
                type="button"
                className="mobile-menu-button d-lg-none"
                onClick={() =>
                  setSidebarOpen(true)
                }
                aria-label="Buka menu"
              >
                <i className="bi bi-list"></i>
              </button>

              <div>

                <div className="topbar-label">
                  ADMIN PANEL
                </div>

                <h6 className="topbar-title mb-0">
                  Certification Management
                </h6>

              </div>

            </div>

            <div className="topbar-right">

              <Link
                href="/"
                className="topbar-website"
                title="Lihat Website"
              >
                <i className="bi bi-globe2"></i>

                <span>
                  Website
                </span>
              </Link>

              <Link
                href="/secure-panel/login"
                className="topbar-logout"
                title="Logout"
              >
                <i className="bi bi-box-arrow-right"></i>

                <span>
                  Logout
                </span>
              </Link>

            </div>

          </header>

          {/* ===================================================
              CONTENT
          =================================================== */}

          <main className="admin-content">

            {/* =================================================
                PAGE HEADING
            ================================================= */}

            <section className="page-heading">

              <div className="page-heading-left">

                <Link
                  href="/secure-panel"
                  className="back-dashboard"
                >
                  <i className="bi bi-arrow-left"></i>

                  <span>
                    Kembali ke Dashboard
                  </span>
                </Link>

                <div className="page-title-row">

                  <div className="page-title-icon">
                    <i className="bi bi-patch-check-fill"></i>
                  </div>

                  <div>

                    <div className="page-eyebrow">
                      WEBSITE CONTENT
                    </div>

                    <h1 className="page-title">
                      Certification
                    </h1>

                    <p className="page-description">
                      Kelola sertifikasi, credential,
                      penerbit, tanggal penerbitan,
                      dan dokumentasi sertifikat yang
                      ditampilkan pada website portfolio
                      GloVaTech.
                    </p>

                  </div>

                </div>

              </div>

              <div className="page-heading-action">

                <Link
                  href="/secure-panel/certifications/create"
                  className="add-button"
                >
                  <i className="bi bi-plus-lg"></i>

                  <span>
                    Tambah Certification
                  </span>
                </Link>

              </div>

            </section>

            {/* =================================================
                STATISTICS
            ================================================= */}

            <section className="stats-grid">

              {/* TOTAL */}

              <div className="stat-card">

                <div className="stat-icon green">
                  <i className="bi bi-patch-check"></i>
                </div>

                <div>

                  <div className="stat-label">
                    Total Certification
                  </div>

                  <div className="stat-value">
                    {loading
                      ? "—"
                      : totalCertification}
                  </div>

                </div>

              </div>

              {/* WITH IMAGE */}

              <div className="stat-card">

                <div className="stat-icon success">
                  <i className="bi bi-images"></i>
                </div>

                <div>

                  <div className="stat-label">
                    Dengan Gambar
                  </div>

                  <div className="stat-value">
                    {loading
                      ? "—"
                      : certificationWithImage}
                  </div>

                </div>

              </div>

              {/* WITHOUT IMAGE */}

              <div className="stat-card">

                <div className="stat-icon secondary">
                  <i className="bi bi-image"></i>
                </div>

                <div>

                  <div className="stat-label">
                    Tanpa Gambar
                  </div>

                  <div className="stat-value">
                    {loading
                      ? "—"
                      : certificationWithoutImage}
                  </div>

                </div>

              </div>

              {/* STATUS */}

              <div className="stat-card">

                <div className="stat-icon blue">
                  <i className="bi bi-database-check"></i>
                </div>

                <div>

                  <div className="stat-label">
                    Content Status
                  </div>

                  <div className="stat-status">
                    {loading
                      ? "Checking..."
                      : "Connected"}
                  </div>

                </div>

              </div>

            </section>

            {/* =================================================
                CONTENT CARD
            ================================================= */}

            <section className="content-card">

              {/* HEADER */}

              <div className="content-card-header">

                <div>

                  <div className="content-card-eyebrow">
                    CONTENT MANAGEMENT
                  </div>

                  <h2 className="content-card-title">
                    Certification & Credential
                  </h2>

                  <p className="content-card-description">
                    Daftar sertifikasi yang digunakan
                    pada halaman portfolio website.
                  </p>

                </div>

                <div className="content-card-count">

                  <i className="bi bi-award"></i>

                  <span>
                    {loading
                      ? "..."
                      : totalCertification}
                  </span>

                </div>

              </div>

              {/* =================================================
                  LOADING
              ================================================= */}

              {loading ? (

                <div className="loading-state">

                  <div className="loading-spinner"></div>

                  <h5>
                    Memuat data Certification
                  </h5>

                  <p>
                    Sedang mengambil informasi
                    certification dari database...
                  </p>

                </div>

              ) : certifications.length === 0 ? (

                /* =================================================
                   EMPTY
                ================================================= */

                <div className="empty-state">

                  <div className="empty-icon">
                    <i className="bi bi-patch-check"></i>
                  </div>

                  <h5>
                    Belum ada data Certification
                  </h5>

                  <p>
                    Belum terdapat sertifikasi.
                    Tambahkan data certification
                    untuk menampilkan credential
                    pada website utama.
                  </p>

                  <Link
                    href="/secure-panel/certifications/create"
                    className="add-button"
                  >
                    <i className="bi bi-plus-lg"></i>

                    <span>
                      Tambah Certification
                    </span>
                  </Link>

                </div>

              ) : (

                <>

                  {/* =================================================
                      DESKTOP TABLE
                  ================================================= */}

                  <div className="certification-table-wrapper">

                    <table className="certification-table">

                      <thead>

                        <tr>

                          <th>
                            Certification
                          </th>

                          <th>
                            Issuer
                          </th>

                          <th>
                            Credential ID
                          </th>

                          <th>
                            Issue Date
                          </th>

                          <th>
                            Gambar
                          </th>

                          <th className="text-end">
                            Action
                          </th>

                        </tr>

                      </thead>

                      <tbody>

                        {certifications.map(
                          (certification) => {

                            /* ============================
                               COMBINE IMAGES
                            ============================ */

                            const certificationImages =
                              certification.certificationimage &&
                              certification
                                .certificationimage
                                .length > 0
                                ? certification.certificationimage
                                : certification.image
                                ? [
                                    {
                                      id: 0,
                                      image:
                                        certification.image,
                                      certificationId:
                                        certification.id,
                                      createdAt:
                                        "",
                                    },
                                  ]
                                : [];

                            return (

                              <tr
                                key={
                                  certification.id
                                }
                              >

                                {/* ==========================
                                    CERTIFICATION
                                ========================== */}

                                <td>

                                  <div className="certification-info">

                                    {certificationImages.length >
                                    0 ? (

                                      <div className="certification-images">

                                        {certificationImages
                                          .slice(0, 3)
                                          .map(
                                            (
                                              item,
                                              index
                                            ) => (

                                              <img
                                                key={`${item.id}-${index}`}
                                                src={
                                                  item.image
                                                }
                                                alt={`${certification.name} ${
                                                  index +
                                                  1
                                                }`}
                                                className="certification-image"
                                              />

                                            )
                                          )}

                                        {certificationImages.length >
                                          3 && (

                                          <div className="more-images">

                                            +
                                            {certificationImages.length -
                                              3}

                                          </div>

                                        )}

                                      </div>

                                    ) : (

                                      <div className="no-image-preview">

                                        <i className="bi bi-award fs-5"></i>

                                      </div>

                                    )}

                                    <div className="certification-details">

                                      <div className="certification-name">
                                        {
                                          certification.name
                                        }
                                      </div>

                                      {certification.description && (

                                        <div className="certification-description">

                                          {certification
                                            .description
                                            .length >
                                          80
                                            ? `${certification.description.substring(
                                                0,
                                                80
                                              )}...`
                                            : certification.description}

                                        </div>

                                      )}

                                      {certificationImages.length >
                                        0 && (

                                        <div className="image-count">

                                          <i className="bi bi-images"></i>

                                          <span>
                                            {
                                              certificationImages.length
                                            }{" "}
                                            gambar
                                          </span>

                                        </div>

                                      )}

                                    </div>

                                  </div>

                                </td>

                                {/* ==========================
                                    ISSUER
                                ========================== */}

                                <td>

                                  <div className="issuer-text">
                                    {certification.issuer ||
                                      "-"}
                                  </div>

                                </td>

                                {/* ==========================
                                    CREDENTIAL
                                ========================== */}

                                <td>

                                  {certification.credentialId ? (

                                    <span className="credential-text">
                                      {
                                        certification.credentialId
                                      }
                                    </span>

                                  ) : (

                                    <span className="no-image-text">
                                      -
                                    </span>

                                  )}

                                </td>

                                {/* ==========================
                                    DATE
                                ========================== */}

                                <td>

                                  <div className="date-text">

                                    {certification.issueDate
                                      ? new Date(
                                          certification.issueDate
                                        ).toLocaleDateString(
                                          "id-ID",
                                          {
                                            day: "2-digit",
                                            month: "short",
                                            year: "numeric",
                                          }
                                        )
                                      : "-"}

                                  </div>

                                </td>

                                {/* ==========================
                                    IMAGE
                                ========================== */}

                                <td>

                                  {certificationImages.length >
                                  0 ? (

                                    <span className="image-count-badge">

                                      <i className="bi bi-images"></i>

                                      {
                                        certificationImages.length
                                      }

                                    </span>

                                  ) : (

                                    <span className="no-image-text">
                                      -
                                    </span>

                                  )}

                                </td>

                                {/* ==========================
                                    ACTION
                                ========================== */}

                                <td>

                                  <div className="action-group">

                                    <Link
                                      href={`/secure-panel/certifications/${certification.id}/edit`}
                                      className="action-button edit-button"
                                    >
                                      <i className="bi bi-pencil"></i>

                                      <span>
                                        Edit
                                      </span>
                                    </Link>

                                    <button
                                      type="button"
                                      className="action-button delete-button"
                                      disabled={
                                        deletingId ===
                                        certification.id
                                      }
                                      onClick={() =>
                                        deleteCertification(
                                          certification.id
                                        )
                                      }
                                    >

                                      {deletingId ===
                                      certification.id ? (
                                        <>
                                          <i className="bi bi-arrow-repeat"></i>

                                          <span>
                                            ...
                                          </span>
                                        </>
                                      ) : (
                                        <>
                                          <i className="bi bi-trash"></i>

                                          <span>
                                            Hapus
                                          </span>
                                        </>
                                      )}

                                    </button>

                                  </div>

                                </td>

                              </tr>

                            );
                          }
                        )}

                      </tbody>

                    </table>

                  </div>

                  {/* =================================================
                      MOBILE CARD LIST
                  ================================================= */}

                  <div className="mobile-certification-list">

                    {certifications.map(
                      (certification) => {

                        const certificationImages =
                          certification.certificationimage &&
                          certification
                            .certificationimage
                            .length > 0
                            ? certification.certificationimage
                            : certification.image
                            ? [
                                {
                                  id: 0,
                                  image:
                                    certification.image,
                                  certificationId:
                                    certification.id,
                                  createdAt:
                                    "",
                                },
                              ]
                            : [];

                        return (

                          <article
                            key={
                              certification.id
                            }
                            className="mobile-certification-card"
                          >

                            {/* ==========================
                                TOP
                            ========================== */}

                            <div className="mobile-certification-top">

                              <div className="mobile-certification-main">

                                <div className="mobile-certification-name">
                                  {
                                    certification.name
                                  }
                                </div>

                                <div className="mobile-certification-issuer">

                                  <i className="bi bi-building me-1"></i>

                                  {
                                    certification.issuer ||
                                    "-"
                                  }

                                </div>

                              </div>

                              <div className="image-count-badge">

                                <i className="bi bi-images"></i>

                                {
                                  certificationImages.length
                                }

                              </div>

                            </div>

                            {/* ==========================
                                IMAGES
                            ========================== */}

                            {certificationImages.length >
                              0 && (

                              <div className="mobile-certification-images">

                                {certificationImages
                                  .slice(0, 4)
                                  .map(
                                    (
                                      item,
                                      index
                                    ) => (

                                      <img
                                        key={`${item.id}-${index}`}
                                        src={
                                          item.image
                                        }
                                        alt={`${certification.name} ${
                                          index +
                                          1
                                        }`}
                                        className="certification-image"
                                      />

                                    )
                                  )}

                                {certificationImages.length >
                                  4 && (

                                  <div className="more-images">

                                    +
                                    {certificationImages.length -
                                      4}

                                  </div>

                                )}

                              </div>

                            )}

                            {/* ==========================
                                DESCRIPTION
                            ========================== */}

                            {certification.description && (

                              <div className="mobile-description">

                                {certification.description}

                              </div>

                            )}

                            {/* ==========================
                                INFORMATION
                            ========================== */}

                            <div className="mobile-info-grid">

                              {/* CREDENTIAL */}

                              <div className="mobile-info-box">

                                <div className="mobile-info-label">
                                  Credential ID
                                </div>

                                <div
                                  className={`mobile-info-value ${
                                    certification.credentialId
                                      ? "credential"
                                      : ""
                                  }`}
                                >
                                  {
                                    certification.credentialId ||
                                    "-"
                                  }
                                </div>

                              </div>

                              {/* ISSUE DATE */}

                              <div className="mobile-info-box">

                                <div className="mobile-info-label">
                                  Issue Date
                                </div>

                                <div className="mobile-info-value">

                                  {certification.issueDate
                                    ? new Date(
                                        certification.issueDate
                                      ).toLocaleDateString(
                                        "id-ID",
                                        {
                                          day: "2-digit",
                                          month: "short",
                                          year: "numeric",
                                        }
                                      )
                                    : "-"}

                                </div>

                              </div>

                              {/* EXPIRY */}

                              <div className="mobile-info-box">

                                <div className="mobile-info-label">
                                  Expiry Date
                                </div>

                                <div
                                  className={`mobile-info-value ${
                                    certification.expiryDate
                                      ? ""
                                      : ""
                                  }`}
                                >
                                  {certification.expiryDate
                                    ? new Date(
                                        certification.expiryDate
                                      ).toLocaleDateString(
                                        "id-ID",
                                        {
                                          day: "2-digit",
                                          month: "short",
                                          year: "numeric",
                                        }
                                      )
                                    : "Tidak ada"}

                                </div>

                              </div>

                              {/* IMAGE */}

                              <div className="mobile-info-box">

                                <div className="mobile-info-label">
                                  Dokumentasi
                                </div>

                                <div className="mobile-info-value">

                                  {certificationImages.length >
                                  0
                                    ? `${certificationImages.length} gambar`
                                    : "Tidak ada gambar"}

                                </div>

                              </div>

                            </div>

                            {/* ==========================
                                ACTION
                            ========================== */}

                            <div className="mobile-actions">

                              <Link
                                href={`/secure-panel/certifications/${certification.id}/edit`}
                                className="action-button edit-button"
                              >
                                <i className="bi bi-pencil"></i>

                                <span>
                                  Edit
                                </span>
                              </Link>

                              <button
                                type="button"
                                className="action-button delete-button"
                                disabled={
                                  deletingId ===
                                  certification.id
                                }
                                onClick={() =>
                                  deleteCertification(
                                    certification.id
                                  )
                                }
                              >

                                {deletingId ===
                                certification.id ? (
                                  <>
                                    <i className="bi bi-arrow-repeat"></i>

                                    <span>
                                      Menghapus...
                                    </span>
                                  </>
                                ) : (
                                  <>
                                    <i className="bi bi-trash"></i>

                                    <span>
                                      Hapus
                                    </span>
                                  </>
                                )}

                              </button>

                            </div>

                          </article>

                        );
                      }
                    )}

                  </div>

                </>

              )}

            </section>

            {/* =================================================
                FOOTER
            ================================================= */}

            <footer className="admin-page-footer">

              <div className="admin-page-footer-left">

                <i className="bi bi-shield-check"></i>

                <span>
                  Admin Content Management System
                </span>

              </div>

              <Link href="/secure-panel">

                <i className="bi bi-arrow-left me-1"></i>

                Dashboard

              </Link>

            </footer>

          </main>

        </div>

      </div>
    </>
  );
}