"use client";

import {
  ChangeEvent,
  FormEvent,
  useEffect,
  useState,
} from "react";
import Link from "next/link";
import { useParams, useRouter } from "next/navigation";

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;
  images: CertificationImage[];
};

type SelectedImage = {
  id: string;
  file: File;
  preview: string;
};

export default function EditCertificationPage() {
  const router = useRouter();
  const params = useParams();

  const id = params.id as string;

  const [name, setName] = useState("");
  const [issuer, setIssuer] = useState("");
  const [credentialId, setCredentialId] = useState("");
  const [issueDate, setIssueDate] = useState("");
  const [expiryDate, setExpiryDate] = useState("");
  const [description, setDescription] = useState("");

  const [existingImages, setExistingImages] = useState<
    CertificationImage[]
  >([]);

  const [selectedFiles, setSelectedFiles] = useState<
    SelectedImage[]
  >([]);

  const [loading, setLoading] = useState(true);
  const [uploading, setUploading] = useState(false);
  const [saving, setSaving] = useState(false);
  const [sidebarOpen, setSidebarOpen] = useState(false);

  // =====================================================
  // GET CERTIFICATION
  // =====================================================

  const getCertification = async () => {
    try {
      setLoading(true);

      const response = await fetch(
        `/api/certifications/${id}`,
        {
          method: "GET",
          cache: "no-store",
        }
      );

      const result = await response.json();

      console.log(
        "GET CERTIFICATION RESULT:",
        result
      );

      if (!response.ok || !result.success) {
        alert(
          result.message ||
            "Certification tidak ditemukan."
        );

        router.push(
          "/secure-panel/certifications"
        );

        return;
      }

      const certification: Certification =
        result.data;

      setName(certification.name || "");
      setIssuer(certification.issuer || "");
      setCredentialId(
        certification.credentialId || ""
      );

      setIssueDate(
        certification.issueDate
          ? certification.issueDate.substring(
              0,
              10
            )
          : ""
      );

      setExpiryDate(
        certification.expiryDate
          ? certification.expiryDate.substring(
              0,
              10
            )
          : ""
      );

      setDescription(
        certification.description || ""
      );

      // =================================================
      // LOAD EXISTING IMAGES
      // =================================================

      if (
        Array.isArray(certification.images) &&
        certification.images.length > 0
      ) {
        setExistingImages(
          certification.images
        );
      } else if (certification.image) {
        setExistingImages([
          {
            id: 0,
            image: certification.image,
            certificationId:
              certification.id,
            createdAt: "",
          },
        ]);
      } else {
        setExistingImages([]);
      }
    } catch (error) {
      console.error(
        "GET CERTIFICATION DETAIL ERROR:",
        error
      );

      alert(
        "Gagal mengambil data Certification."
      );

      router.push(
        "/secure-panel/certifications"
      );
    } finally {
      setLoading(false);
    }
  };

  useEffect(() => {
    if (id) {
      getCertification();
    }
  }, [id]);

  // =====================================================
  // SELECT MULTIPLE FILES
  // =====================================================

  const handleFileChange = (
    event: ChangeEvent<HTMLInputElement>
  ) => {
    const files = Array.from(
      event.target.files || []
    );

    if (files.length === 0) {
      return;
    }

    const allowedTypes = [
      "image/jpeg",
      "image/jpg",
      "image/png",
      "image/webp",
      "image/gif",
    ];

    const maxSize = 5 * 1024 * 1024;

    for (const file of files) {
      if (!allowedTypes.includes(file.type)) {
        alert(
          `Format file ${file.name} tidak didukung.`
        );

        event.target.value = "";

        return;
      }

      if (file.size > maxSize) {
        alert(
          `Ukuran ${file.name} terlalu besar. Maksimal 5 MB.`
        );

        event.target.value = "";

        return;
      }
    }

    const newImages: SelectedImage[] =
      files.map((file) => ({
        id: `${file.name}-${file.size}-${file.lastModified}-${Math.random()}`,
        file,
        preview:
          URL.createObjectURL(file),
      }));

    setSelectedFiles((previous) => [
      ...previous,
      ...newImages,
    ]);

    event.target.value = "";
  };

  // =====================================================
  // REMOVE EXISTING IMAGE
  // =====================================================

  const removeExistingImage = (
    imageId: number
  ) => {
    if (existingImages.length <= 1) {
      alert(
        "Minimal satu gambar harus tersedia."
      );

      return;
    }

    setExistingImages((previous) =>
      previous.filter(
        (image) => image.id !== imageId
      )
    );
  };

  // =====================================================
  // REMOVE NEW IMAGE
  // =====================================================

  const removeSelectedImage = (
    imageId: string
  ) => {
    setSelectedFiles((previous) => {
      const image = previous.find(
        (item) => item.id === imageId
      );

      if (image) {
        URL.revokeObjectURL(
          image.preview
        );
      }

      return previous.filter(
        (item) => item.id !== imageId
      );
    });
  };

  // =====================================================
  // UPLOAD MULTIPLE NEW IMAGES
  // =====================================================

  const uploadNewImages = async (): Promise<
    string[] | null
  > => {
    if (selectedFiles.length === 0) {
      return [];
    }

    setUploading(true);

    try {
      const formData = new FormData();

      selectedFiles.forEach((item) => {
        formData.append(
          "files",
          item.file
        );
      });

      console.log(
        "FILE YANG AKAN DIUPLOAD:",
        selectedFiles.map(
          (item) => item.file.name
        )
      );

      const response = await fetch(
        "/api/certifications/upload",
        {
          method: "POST",
          body: formData,
        }
      );

      const result =
        await response.json();

      console.log(
        "UPLOAD RESULT:",
        result
      );

      if (
        !response.ok ||
        !result.success
      ) {
        alert(
          result.message ||
            "Gagal mengupload gambar."
        );

        return null;
      }

      if (
        !Array.isArray(result.data)
      ) {
        console.error(
          "FORMAT DATA UPLOAD SALAH:",
          result.data
        );

        alert(
          "Format data gambar dari server tidak valid."
        );

        return null;
      }

      const uploadedImages =
        result.data.filter(
          (
            image: unknown
          ): image is string =>
            typeof image === "string" &&
            image.trim() !== ""
        );

      console.log(
        "GAMBAR BERHASIL DIUPLOAD:",
        uploadedImages
      );

      return uploadedImages;
    } catch (error) {
      console.error(
        "UPLOAD CERTIFICATION IMAGES ERROR:",
        error
      );

      alert(
        "Terjadi kesalahan saat mengupload gambar."
      );

      return null;
    } finally {
      setUploading(false);
    }
  };

  // =====================================================
  // SUBMIT
  // =====================================================

  const handleSubmit = async (
    event: FormEvent
  ) => {
    event.preventDefault();

    if (!name.trim()) {
      alert(
        "Nama Certification wajib diisi."
      );

      return;
    }

    if (!issuer.trim()) {
      alert(
        "Penerbit wajib diisi."
      );

      return;
    }

    if (!issueDate) {
      alert(
        "Tanggal Terbit wajib diisi."
      );

      return;
    }

    if (
      existingImages.length === 0 &&
      selectedFiles.length === 0
    ) {
      alert(
        "Minimal satu gambar harus tersedia."
      );

      return;
    }

    setSaving(true);

    try {
      // =================================================
      // UPLOAD GAMBAR BARU
      // =================================================

      let uploadedImages: string[] = [];

      if (selectedFiles.length > 0) {
        const uploaded =
          await uploadNewImages();

        if (uploaded === null) {
          return;
        }

        uploadedImages = uploaded;
      }

      // =================================================
      // GAMBAR LAMA
      // =================================================

      const oldImages =
        existingImages.map(
          (image) => image.image
        );

      // =================================================
      // GABUNG SEMUA GAMBAR
      // =================================================

      const allImages = [
        ...oldImages,
        ...uploadedImages,
      ];

      console.log(
        "OLD IMAGES:",
        oldImages
      );

      console.log(
        "UPLOADED IMAGES:",
        uploadedImages
      );

      console.log(
        "ALL IMAGES:",
        allImages
      );

      if (allImages.length === 0) {
        alert(
          "Minimal satu gambar harus tersedia."
        );

        return;
      }

      // =================================================
      // UPDATE CERTIFICATION
      // =================================================

      const response = await fetch(
        `/api/certifications/${id}`,
        {
          method: "PUT",

          headers: {
            "Content-Type":
              "application/json",
          },

          body: JSON.stringify({
            name: name.trim(),

            issuer: issuer.trim(),

            credentialId:
              credentialId.trim() ||
              null,

            issueDate,

            expiryDate:
              expiryDate || null,

            description:
              description.trim() ||
              null,

            // BACKEND TETAP
            images: allImages,
          }),
        }
      );

      const result =
        await response.json();

      console.log(
        "UPDATE CERTIFICATION RESULT:",
        result
      );

      if (
        !response.ok ||
        !result.success
      ) {
        alert(
          result.message ||
            "Gagal memperbarui Certification."
        );

        return;
      }

      // =================================================
      // CLEANUP PREVIEW
      // =================================================

      selectedFiles.forEach((item) => {
        URL.revokeObjectURL(
          item.preview
        );
      });

      setSelectedFiles([]);

      // =================================================
      // SUCCESS
      // =================================================

      alert(
        "Certification berhasil diperbarui."
      );

      router.push(
        "/secure-panel/certifications"
      );

      router.refresh();
    } catch (error) {
      console.error(
        "UPDATE CERTIFICATION ERROR:",
        error
      );

      alert(
        "Terjadi kesalahan saat menyimpan Certification."
      );
    } finally {
      setSaving(false);
    }
  };

  // =====================================================
  // LOADING
  // =====================================================

  if (loading) {
    return (
      <>
        <style>{`
          * {
            box-sizing: border-box;
          }

          .loading-page {
            min-height: 100vh;
            background: #f5f7f9;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 30px;
          }

          .loading-box {
            text-align: center;
          }

          .loading-spinner {
            width: 42px;
            height: 42px;
            border: 3px solid #dcefe4;
            border-top-color: #198754;
            border-radius: 50%;
            animation: spin 0.8s linear infinite;
            margin: 0 auto 15px;
          }

          .loading-title {
            font-size: 15px;
            font-weight: 700;
            color: #344054;
            margin-bottom: 5px;
          }

          .loading-text {
            color: #98a2b3;
            font-size: 12px;
            margin: 0;
          }

          @keyframes spin {
            to {
              transform: rotate(360deg);
            }
          }
        `}</style>

        <main className="loading-page">
          <div className="loading-box">
            <div className="loading-spinner"></div>

            <div className="loading-title">
              Memuat Certification
            </div>

            <p className="loading-text">
              Sedang mengambil data dari database...
            </p>
          </div>
        </main>
      </>
    );
  }

  // =====================================================
  // PAGE
  // =====================================================

  return (
    <>
      <style>{`
        * {
          box-sizing: border-box;
        }

        .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: 680px;
          text-align: justify;
        }

        /* =================================================
           FORM CARD
        ================================================= */

        .form-card {
          background: #ffffff;
          border: 1px solid #eaecf0;
          border-radius: 16px;
          overflow: hidden;
          box-shadow:
            0 3px 12px
            rgba(16, 24, 40, 0.035);
        }

        .form-card-header {
          padding: 21px 24px;
          border-bottom: 1px solid #eaecf0;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 20px;
        }

        .form-card-eyebrow {
          font-size: 10px;
          font-weight: 700;
          color: #198754;
          letter-spacing: 1px;
          margin-bottom: 4px;
        }

        .form-card-title {
          font-size: 17px;
          font-weight: 750;
          color: #101828;
          margin: 0;
        }

        .form-card-description {
          margin: 5px 0 0;
          color: #667085;
          font-size: 12px;
          line-height: 1.65;
          text-align: justify;
        }

        .form-card-icon {
          width: 40px;
          height: 40px;
          border-radius: 10px;
          background: #e9f7ef;
          color: #198754;
          display: flex;
          align-items: center;
          justify-content: center;
          flex-shrink: 0;
          font-size: 17px;
        }

        .form-card-body {
          padding: 24px;
        }

        /* =================================================
           FORM
        ================================================= */

        .form-section {
          margin-bottom: 26px;
        }

        .form-section:last-child {
          margin-bottom: 0;
        }

        .section-heading {
          display: flex;
          align-items: center;
          gap: 10px;
          margin-bottom: 16px;
        }

        .section-heading-icon {
          width: 32px;
          height: 32px;
          border-radius: 9px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #f0f9f4;
          color: #198754;
          font-size: 14px;
          flex-shrink: 0;
        }

        .section-heading-text {
          min-width: 0;
        }

        .section-heading-title {
          margin: 0;
          font-size: 13px;
          font-weight: 750;
          color: #344054;
        }

        .section-heading-description {
          margin: 2px 0 0;
          color: #98a2b3;
          font-size: 11px;
          line-height: 1.5;
        }

        .form-label-custom {
          display: block;
          margin-bottom: 7px;
          color: #344054;
          font-size: 12px;
          font-weight: 700;
        }

        .required-mark {
          color: #dc3545;
          margin-left: 2px;
        }

        .form-control-custom {
          width: 100%;
          min-height: 43px;
          padding: 10px 12px;
          border: 1px solid #d0d5dd;
          border-radius: 9px;
          background: #ffffff;
          color: #344054;
          font-size: 13px;
          outline: none;
          transition:
            border-color 0.2s ease,
            box-shadow 0.2s ease;
        }

        .form-control-custom:focus {
          border-color: #198754;
          box-shadow:
            0 0 0 3px
            rgba(25, 135, 84, 0.1);
        }

        .form-control-custom:disabled {
          background: #f5f7f9;
          cursor: not-allowed;
          opacity: 0.7;
        }

        textarea.form-control-custom {
          min-height: 135px;
          resize: vertical;
          line-height: 1.7;
          text-align: justify;
        }

        .form-help {
          display: block;
          margin-top: 6px;
          color: #98a2b3;
          font-size: 10px;
          line-height: 1.6;
        }

        /* =================================================
           IMAGE MANAGEMENT
        ================================================= */

        .image-summary {
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
          padding: 12px 14px;
          margin-bottom: 15px;
          border: 1px solid #e8edf0;
          border-radius: 10px;
          background: #fafbfc;
        }

        .image-summary-left {
          display: flex;
          align-items: center;
          gap: 9px;
          min-width: 0;
        }

        .image-summary-icon {
          width: 32px;
          height: 32px;
          border-radius: 8px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #e9f7ef;
          color: #198754;
          flex-shrink: 0;
        }

        .image-summary-title {
          color: #344054;
          font-size: 12px;
          font-weight: 700;
        }

        .image-summary-text {
          color: #98a2b3;
          font-size: 10px;
          margin-top: 2px;
        }

        .image-count {
          min-width: 34px;
          height: 30px;
          padding: 0 9px;
          border-radius: 8px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          background: #e9f7ef;
          color: #198754;
          font-size: 11px;
          font-weight: 700;
        }

        .image-grid {
          display: grid;
          grid-template-columns:
            repeat(3, minmax(0, 1fr));
          gap: 14px;
        }

        .image-card {
          min-width: 0;
          border: 1px solid #eaecf0;
          border-radius: 12px;
          background: #ffffff;
          overflow: hidden;
          transition:
            transform 0.2s ease,
            box-shadow 0.2s ease,
            border-color 0.2s ease;
        }

        .image-card:hover {
          transform: translateY(-2px);
          border-color: #cfe8d9;
          box-shadow:
            0 8px 22px
            rgba(25, 135, 84, 0.07);
        }

        .image-preview {
          position: relative;
          width: 100%;
          height: 220px;
          background: #f5f7f9;
          overflow: hidden;
        }

        .image-preview img {
          width: 100%;
          height: 100%;
          display: block;
          object-fit: cover;
        }

        .image-badge {
          position: absolute;
          top: 10px;
          left: 10px;
          min-height: 25px;
          display: inline-flex;
          align-items: center;
          padding: 4px 8px;
          border-radius: 6px;
          background: #198754;
          color: #ffffff;
          font-size: 9px;
          font-weight: 700;
          box-shadow:
            0 4px 10px
            rgba(0, 0, 0, 0.12);
        }

        .image-badge.new {
          background: #0d6efd;
        }

        .image-delete {
          position: absolute;
          top: 10px;
          right: 10px;
          width: 31px;
          height: 31px;
          border: 1px solid
            rgba(255, 255, 255, 0.7);
          border-radius: 8px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #dc3545;
          color: #ffffff;
          cursor: pointer;
          font-size: 12px;
          transition: all 0.2s ease;
          box-shadow:
            0 4px 10px
            rgba(0, 0, 0, 0.12);
        }

        .image-delete:hover {
          background: #b02a37;
          transform: scale(1.04);
        }

        .image-delete:disabled {
          opacity: 0.55;
          cursor: not-allowed;
        }

        .image-card-body {
          padding: 10px 11px;
        }

        .image-name {
          display: block;
          color: #667085;
          font-size: 10px;
          line-height: 1.5;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .image-empty {
          min-height: 150px;
          border: 1px dashed #d0d5dd;
          border-radius: 11px;
          background: #fafbfc;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          text-align: center;
          padding: 25px 15px;
        }

        .image-empty-icon {
          width: 46px;
          height: 46px;
          border-radius: 12px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #fff7e6;
          color: #d89b00;
          font-size: 19px;
          margin-bottom: 9px;
        }

        .image-empty-title {
          color: #475467;
          font-size: 12px;
          font-weight: 700;
          margin-bottom: 3px;
        }

        .image-empty-text {
          color: #98a2b3;
          font-size: 10px;
          line-height: 1.5;
        }

        /* =================================================
           UPLOAD BOX
        ================================================= */

        .upload-box {
          border: 1px dashed #b7dfc9;
          border-radius: 12px;
          background: #f8fcf9;
          padding: 16px;
        }

        .upload-box .form-control-custom {
          background: #ffffff;
        }

        .upload-info {
          display: flex;
          align-items: flex-start;
          gap: 9px;
          margin-top: 9px;
          color: #667085;
          font-size: 10px;
          line-height: 1.6;
        }

        .upload-info i {
          color: #198754;
          margin-top: 1px;
        }

        /* =================================================
           FORM FOOTER
        ================================================= */

        .form-footer {
          margin-top: 28px;
          padding-top: 21px;
          border-top: 1px solid #eaecf0;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
        }

        .form-footer-note {
          display: flex;
          align-items: center;
          gap: 7px;
          color: #98a2b3;
          font-size: 10px;
        }

        .form-footer-note i {
          color: #198754;
          font-size: 13px;
        }

        .button-group {
          display: flex;
          align-items: center;
          justify-content: flex-end;
          gap: 8px;
        }

        .button-custom {
          min-height: 42px;
          padding: 9px 15px;
          border-radius: 9px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 7px;
          font-size: 12px;
          font-weight: 700;
          text-decoration: none;
          cursor: pointer;
          transition: all 0.2s ease;
        }

        .button-cancel {
          color: #667085;
          background: #ffffff;
          border: 1px solid #d0d5dd;
        }

        .button-cancel:hover {
          color: #344054;
          background: #f9fafb;
          border-color: #98a2b3;
        }

        .button-save {
          color: #ffffff;
          background: #198754;
          border: 1px solid #198754;
          box-shadow:
            0 7px 18px
            rgba(25, 135, 84, 0.15);
        }

        .button-save:hover {
          color: #ffffff;
          background: #157347;
          border-color: #157347;
          transform: translateY(-1px);
        }

        .button-save:disabled,
        .button-cancel:disabled {
          opacity: 0.6;
          cursor: not-allowed;
          transform: none;
        }

        /* =================================================
           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) {
          .image-grid {
            grid-template-columns:
              repeat(2, minmax(0, 1fr));
          }
        }

        /* =================================================
           MOBILE / TABLET SIDEBAR
        ================================================= */

        @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-left {
            width: 100%;
          }

          .form-card-body {
            padding: 20px;
          }

          .form-footer {
            align-items: flex-start;
            flex-direction: column;
          }

          .form-footer-note {
            width: 100%;
          }

          .button-group {
            width: 100%;
            justify-content: flex-end;
          }
        }

        /* =================================================
           MOBILE
        ================================================= */

        @media (max-width: 767.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;
            text-align: justify;
          }

          .form-card-header {
            padding: 17px;
          }

          .form-card-title {
            font-size: 15px;
          }

          .form-card-description {
            font-size: 11px;
          }

          .form-card-body {
            padding: 17px;
          }

          .section-heading {
            margin-bottom: 13px;
          }

          .image-grid {
            grid-template-columns: 1fr;
          }

          .image-preview {
            height: 230px;
          }

          .image-summary {
            align-items: flex-start;
          }

          .form-footer {
            margin-top: 22px;
          }

          .button-group {
            flex-direction: column-reverse;
            width: 100%;
          }

          .button-custom {
            width: 100%;
          }

          .admin-page-footer {
            flex-direction: column;
            align-items: flex-start;
          }
        }

        /* =================================================
           SMALL MOBILE
        ================================================= */

        @media (max-width: 575.98px) {
          .page-title-row {
            gap: 11px;
          }

          .page-title-icon {
            width: 40px;
            height: 40px;
            font-size: 17px;
          }

          .page-title {
            font-size: 23px;
          }

          .page-eyebrow {
            font-size: 9px;
          }

          .page-description {
            font-size: 11px;
            line-height: 1.65;
          }

          .form-card-header {
            align-items: flex-start;
          }

          .form-card-icon {
            width: 36px;
            height: 36px;
            font-size: 15px;
          }

          .form-card-body {
            padding: 14px;
          }

          .section-heading-icon {
            width: 30px;
            height: 30px;
          }

          .form-control-custom {
            min-height: 42px;
            font-size: 12px;
          }

          textarea.form-control-custom {
            min-height: 130px;
          }

          .image-preview {
            height: 210px;
          }

          .upload-box {
            padding: 13px;
          }

          .admin-page-footer {
            font-size: 10px;
          }
        }
      `}</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">
            <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>

            {/* BOTTOM */}

            <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/certifications"
                  className="back-dashboard"
                >
                  <i className="bi bi-arrow-left"></i>

                  <span>
                    Kembali ke Certifications
                  </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">
                      Edit Certification
                    </h1>

                    <p className="page-description">
                      Perbarui informasi,
                      credential, tanggal,
                      deskripsi, dan gambar
                      certification yang
                      ditampilkan pada
                      portfolio GloVaTech.
                    </p>
                  </div>
                </div>
              </div>
            </section>

            {/* =================================================
                FORM CARD
            ================================================= */}

            <form
              onSubmit={handleSubmit}
              className="form-card"
            >
              {/* CARD HEADER */}

              <div className="form-card-header">
                <div>
                  <div className="form-card-eyebrow">
                    CERTIFICATION MANAGEMENT
                  </div>

                  <h2 className="form-card-title">
                    Informasi Certification
                  </h2>

                  <p className="form-card-description">
                    Kelola detail sertifikasi
                    dan seluruh gambar yang
                    terhubung dengan data ini.
                  </p>
                </div>

                <div className="form-card-icon">
                  <i className="bi bi-award-fill"></i>
                </div>
              </div>

              {/* CARD BODY */}

              <div className="form-card-body">
                {/* =================================================
                    BASIC INFORMATION
                ================================================= */}

                <section className="form-section">
                  <div className="section-heading">
                    <div className="section-heading-icon">
                      <i className="bi bi-info-circle"></i>
                    </div>

                    <div className="section-heading-text">
                      <h3 className="section-heading-title">
                        Informasi Dasar
                      </h3>

                      <p className="section-heading-description">
                        Informasi utama mengenai
                        certification.
                      </p>
                    </div>
                  </div>

                  <div className="row g-3">
                    {/* NAME */}

                    <div className="col-12 col-lg-8">
                      <label className="form-label-custom">
                        Nama Certification
                        <span className="required-mark">
                          *
                        </span>
                      </label>

                      <input
                        type="text"
                        className="form-control-custom"
                        value={name}
                        onChange={(event) =>
                          setName(
                            event.target.value
                          )
                        }
                        placeholder="Contoh: Microsoft Certified: Azure Fundamentals"
                        disabled={
                          saving ||
                          uploading
                        }
                        required
                      />
                    </div>

                    {/* ISSUER */}

                    <div className="col-12 col-lg-4">
                      <label className="form-label-custom">
                        Penerbit / Issuer
                        <span className="required-mark">
                          *
                        </span>
                      </label>

                      <input
                        type="text"
                        className="form-control-custom"
                        value={issuer}
                        onChange={(event) =>
                          setIssuer(
                            event.target.value
                          )
                        }
                        placeholder="Contoh: Microsoft"
                        disabled={
                          saving ||
                          uploading
                        }
                        required
                      />
                    </div>

                    {/* CREDENTIAL */}

                    <div className="col-12 col-lg-6">
                      <label className="form-label-custom">
                        Credential ID
                      </label>

                      <input
                        type="text"
                        className="form-control-custom"
                        value={
                          credentialId
                        }
                        onChange={(event) =>
                          setCredentialId(
                            event.target
                              .value
                          )
                        }
                        placeholder="Contoh: ABC123XYZ"
                        disabled={
                          saving ||
                          uploading
                        }
                      />

                      <small className="form-help">
                        Kosongkan jika
                        certification tidak
                        memiliki Credential ID.
                      </small>
                    </div>

                    {/* ISSUE DATE */}

                    <div className="col-12 col-sm-6 col-lg-3">
                      <label className="form-label-custom">
                        Tanggal Terbit
                        <span className="required-mark">
                          *
                        </span>
                      </label>

                      <input
                        type="date"
                        className="form-control-custom"
                        value={
                          issueDate
                        }
                        onChange={(event) =>
                          setIssueDate(
                            event.target
                              .value
                          )
                        }
                        disabled={
                          saving ||
                          uploading
                        }
                        required
                      />
                    </div>

                    {/* EXPIRY DATE */}

                    <div className="col-12 col-sm-6 col-lg-3">
                      <label className="form-label-custom">
                        Tanggal Kedaluwarsa
                      </label>

                      <input
                        type="date"
                        className="form-control-custom"
                        value={
                          expiryDate
                        }
                        onChange={(event) =>
                          setExpiryDate(
                            event.target
                              .value
                          )
                        }
                        disabled={
                          saving ||
                          uploading
                        }
                      />

                      <small className="form-help">
                        Kosongkan jika tidak
                        memiliki masa berlaku.
                      </small>
                    </div>
                  </div>
                </section>

                {/* =================================================
                    EXISTING IMAGES
                ================================================= */}

                <section className="form-section">
                  <div className="section-heading">
                    <div className="section-heading-icon">
                      <i className="bi bi-images"></i>
                    </div>

                    <div className="section-heading-text">
                      <h3 className="section-heading-title">
                        Gambar Certification
                      </h3>

                      <p className="section-heading-description">
                        Kelola gambar yang sudah
                        tersimpan pada certification.
                      </p>
                    </div>
                  </div>

                  <div className="image-summary">
                    <div className="image-summary-left">
                      <div className="image-summary-icon">
                        <i className="bi bi-images"></i>
                      </div>

                      <div>
                        <div className="image-summary-title">
                          Gambar Tersimpan
                        </div>

                        <div className="image-summary-text">
                          Gambar pertama digunakan
                          sebagai gambar utama.
                        </div>
                      </div>
                    </div>

                    <div className="image-count">
                      {existingImages.length}
                    </div>
                  </div>

                  {existingImages.length >
                  0 ? (
                    <div className="image-grid">
                      {existingImages.map(
                        (item, index) => (
                          <article
                            className="image-card"
                            key={`${item.id}-${item.image}-${index}`}
                          >
                            <div className="image-preview">
                              <img
                                src={
                                  item.image
                                }
                                alt={`${name} ${
                                  index +
                                  1
                                }`}
                              />

                              <span className="image-badge">
                                {index ===
                                0
                                  ? "Gambar Utama"
                                  : `Gambar ${
                                      index +
                                      1
                                    }`}
                              </span>

                              <button
                                type="button"
                                className="image-delete"
                                onClick={() =>
                                  removeExistingImage(
                                    item.id
                                  )
                                }
                                disabled={
                                  saving ||
                                  uploading
                                }
                                title={
                                  existingImages.length <=
                                  1
                                    ? "Minimal satu gambar harus tersedia"
                                    : "Hapus gambar"
                                }
                              >
                                <i className="bi bi-trash"></i>
                              </button>
                            </div>

                            <div className="image-card-body">
                              <span
                                className="image-name"
                                title={
                                  item.image
                                }
                              >
                                {item.image}
                              </span>
                            </div>
                          </article>
                        )
                      )}
                    </div>
                  ) : (
                    <div className="image-empty">
                      <div className="image-empty-icon">
                        <i className="bi bi-image"></i>
                      </div>

                      <div className="image-empty-title">
                        Belum ada gambar
                      </div>

                      <div className="image-empty-text">
                        Tambahkan minimal satu
                        gambar melalui bagian
                        upload di bawah.
                      </div>
                    </div>
                  )}
                </section>

                {/* =================================================
                    UPLOAD NEW IMAGES
                ================================================= */}

                <section className="form-section">
                  <div className="section-heading">
                    <div className="section-heading-icon">
                      <i className="bi bi-cloud-arrow-up"></i>
                    </div>

                    <div className="section-heading-text">
                      <h3 className="section-heading-title">
                        Tambah Gambar
                      </h3>

                      <p className="section-heading-description">
                        Upload gambar baru tanpa
                        mengubah gambar yang masih
                        tersimpan.
                      </p>
                    </div>
                  </div>

                  <div className="upload-box">
                    <label className="form-label-custom">
                      Pilih Gambar Certification
                    </label>

                    <input
                      type="file"
                      className="form-control-custom"
                      accept="image/jpeg,image/jpg,image/png,image/webp,image/gif"
                      multiple
                      onChange={
                        handleFileChange
                      }
                      disabled={
                        saving ||
                        uploading
                      }
                    />

                    <div className="upload-info">
                      <i className="bi bi-info-circle-fill"></i>

                      <span>
                        Pilih satu atau beberapa
                        gambar. Format yang
                        didukung JPG, JPEG, PNG,
                        WEBP, dan GIF. Maksimal
                        5 MB untuk setiap gambar.
                      </span>
                    </div>
                  </div>
                </section>

                {/* =================================================
                    NEW IMAGE PREVIEW
                ================================================= */}

                {selectedFiles.length >
                  0 && (
                  <section className="form-section">
                    <div className="section-heading">
                      <div className="section-heading-icon">
                        <i className="bi bi-eye"></i>
                      </div>

                      <div className="section-heading-text">
                        <h3 className="section-heading-title">
                          Preview Gambar Baru
                        </h3>

                        <p className="section-heading-description">
                          Gambar berikut akan
                          ditambahkan ketika Anda
                          menyimpan perubahan.
                        </p>
                      </div>
                    </div>

                    <div className="image-summary">
                      <div className="image-summary-left">
                        <div className="image-summary-icon">
                          <i className="bi bi-file-earmark-image"></i>
                        </div>

                        <div>
                          <div className="image-summary-title">
                            File Siap Ditambahkan
                          </div>

                          <div className="image-summary-text">
                            Hapus file yang tidak
                            ingin digunakan sebelum
                            menyimpan.
                          </div>
                        </div>
                      </div>

                      <div className="image-count">
                        {selectedFiles.length}
                      </div>
                    </div>

                    <div className="image-grid">
                      {selectedFiles.map(
                        (
                          item,
                          index
                        ) => (
                          <article
                            className="image-card"
                            key={item.id}
                          >
                            <div className="image-preview">
                              <img
                                src={
                                  item.preview
                                }
                                alt={
                                  item.file
                                    .name
                                }
                              />

                              <span className="image-badge new">
                                Gambar Baru
                              </span>

                              <button
                                type="button"
                                className="image-delete"
                                onClick={() =>
                                  removeSelectedImage(
                                    item.id
                                  )
                                }
                                disabled={
                                  saving ||
                                  uploading
                                }
                                title="Hapus gambar baru"
                              >
                                <i className="bi bi-trash"></i>
                              </button>
                            </div>

                            <div className="image-card-body">
                              <span
                                className="image-name"
                                title={
                                  item.file
                                    .name
                                }
                              >
                                {item.file
                                  .name}
                              </span>
                            </div>
                          </article>
                        )
                      )}
                    </div>
                  </section>
                )}

                {/* =================================================
                    DESCRIPTION
                ================================================= */}

                <section className="form-section">
                  <div className="section-heading">
                    <div className="section-heading-icon">
                      <i className="bi bi-card-text"></i>
                    </div>

                    <div className="section-heading-text">
                      <h3 className="section-heading-title">
                        Deskripsi
                      </h3>

                      <p className="section-heading-description">
                        Jelaskan detail atau
                        informasi tambahan mengenai
                        certification.
                      </p>
                    </div>
                  </div>

                  <label className="form-label-custom">
                    Deskripsi Certification
                  </label>

                  <textarea
                    className="form-control-custom"
                    rows={5}
                    value={description}
                    onChange={(event) =>
                      setDescription(
                        event.target
                          .value
                      )
                    }
                    placeholder="Jelaskan certification ini..."
                    disabled={
                      saving ||
                      uploading
                    }
                  />

                  <small className="form-help">
                    Gunakan deskripsi yang jelas
                    dan profesional.
                  </small>
                </section>

                {/* =================================================
                    FOOTER
                ================================================= */}

                <div className="form-footer">
                  <div className="form-footer-note">
                    <i className="bi bi-shield-check"></i>

                    <span>
                      Perubahan akan disimpan
                      ke database certification.
                    </span>
                  </div>

                  <div className="button-group">
                    <button
                      type="button"
                      className="button-custom button-cancel"
                      onClick={() =>
                        router.push(
                          "/secure-panel/certifications"
                        )
                      }
                      disabled={
                        saving ||
                        uploading
                      }
                    >
                      <i className="bi bi-x-lg"></i>

                      <span>
                        Batal
                      </span>
                    </button>

                    <button
                      type="submit"
                      className="button-custom button-save"
                      disabled={
                        saving ||
                        uploading
                      }
                    >
                      {uploading ? (
                        <>
                          <span
                            className="spinner-border spinner-border-sm"
                            role="status"
                          ></span>

                          <span>
                            Mengupload gambar...
                          </span>
                        </>
                      ) : saving ? (
                        <>
                          <span
                            className="spinner-border spinner-border-sm"
                            role="status"
                          ></span>

                          <span>
                            Menyimpan...
                          </span>
                        </>
                      ) : (
                        <>
                          <i className="bi bi-check-lg"></i>

                          <span>
                            Simpan Perubahan
                          </span>
                        </>
                      )}
                    </button>
                  </div>
                </div>
              </div>
            </form>

            {/* =================================================
                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/certifications"
              >
                <i className="bi bi-arrow-left me-1"></i>

                Certifications
              </Link>
            </footer>
          </main>
        </div>
      </div>
    </>
  );
}

