"use client";

import {
  ChangeEvent,
  FormEvent,
  useEffect,
  useState,
} from "react";
import Link from "next/link";
import { useParams, useRouter } from "next/navigation";

type GalleryImage = {
  id: number;
  image: string;
  galleryId: number;
  createdAt: string;
};

type Gallery = {
  id: number;
  title: string;
  description: string | null;
  image: string | null;
  category: string | null;

  images?: GalleryImage[];
  galleryimage?: GalleryImage[];
};

type UploadedImage = {
  url: string;
  fileName: string;
};

type SelectedImage = {
  file: File;
  preview: string;
};

export default function EditGalleryPage() {
  const router = useRouter();
  const params = useParams();

  const id = params.id as string;

  const [title, setTitle] = useState("");
  const [description, setDescription] = useState("");
  const [category, setCategory] = useState("");

  const [existingImages, setExistingImages] = useState<
    GalleryImage[]
  >([]);

  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 GALLERY DETAIL
  // =====================================================

  const getGallery = async () => {
    if (!id) return;

    try {
      setLoading(true);

      const response = await fetch(`/api/gallery/${id}`, {
        method: "GET",
        cache: "no-store",
      });

      const result = await response.json();

      console.log("GET GALLERY DETAIL:", result);

      if (!response.ok || !result.success) {
        alert(
          result.message ||
            "Gagal mengambil data Gallery."
        );

        router.push("/secure-panel/gallery");
        return;
      }

      const gallery: Gallery = result.data;

      setTitle(gallery.title || "");

      setDescription(
        gallery.description || ""
      );

      setCategory(
        gallery.category || ""
      );

      let galleryImages: GalleryImage[] = [];

      if (
        Array.isArray(gallery.galleryimage) &&
        gallery.galleryimage.length > 0
      ) {
        galleryImages =
          gallery.galleryimage;
      } else if (
        Array.isArray(gallery.images) &&
        gallery.images.length > 0
      ) {
        galleryImages =
          gallery.images;
      } else if (gallery.image) {
        galleryImages = [
          {
            id: 0,
            image: gallery.image,
            galleryId: gallery.id,
            createdAt: "",
          },
        ];
      }

      setExistingImages(galleryImages);
    } catch (error) {
      console.error(
        "GET GALLERY DETAIL ERROR:",
        error
      );

      alert(
        "Terjadi kesalahan saat mengambil data Gallery."
      );

      router.push("/secure-panel/gallery");
    } finally {
      setLoading(false);
    }
  };

  // =====================================================
  // LOAD DATA
  // =====================================================

  useEffect(() => {
    if (id) {
      getGallery();
    }
  }, [id]);

  // =====================================================
  // CLEANUP PREVIEW
  // =====================================================

  useEffect(() => {
    return () => {
      selectedFiles.forEach((item) => {
        URL.revokeObjectURL(item.preview);
      });
    };
  }, [selectedFiles]);

  // =====================================================
  // PILIH GAMBAR BARU
  // =====================================================

  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) => ({
        file,
        preview:
          URL.createObjectURL(file),
      }));

    setSelectedFiles(
      (previous) => [
        ...previous,
        ...newImages,
      ]
    );

    event.target.value = "";
  };

  // =====================================================
  // HAPUS GAMBAR LAMA
  // =====================================================

  const removeExistingImage = (
    imageId: number
  ) => {
    setExistingImages(
      (previous) =>
        previous.filter(
          (image) =>
            image.id !== imageId
        )
    );
  };

  // =====================================================
  // HAPUS GAMBAR BARU
  // =====================================================

  const removeSelectedImage = (
    index: number
  ) => {
    setSelectedFiles(
      (previous) => {
        const image =
          previous[index];

        if (image) {
          URL.revokeObjectURL(
            image.preview
          );
        }

        return previous.filter(
          (_, currentIndex) =>
            currentIndex !== index
        );
      }
    );
  };

  // =====================================================
  // UPLOAD GAMBAR BARU
  // =====================================================

  const uploadNewImages =
    async (): Promise<
      UploadedImage[] | null
    > => {
      if (
        selectedFiles.length === 0
      ) {
        return [];
      }

      setUploading(true);

      try {
        const formData =
          new FormData();

        selectedFiles.forEach(
          (item) => {
            formData.append(
              "files",
              item.file
            );
          }
        );

        const response =
          await fetch(
            "/api/gallery/upload",
            {
              method: "POST",
              body: formData,
            }
          );

        const result =
          await response.json();

        console.log(
          "UPLOAD GALLERY:",
          result
        );

        if (
          !response.ok ||
          !result.success
        ) {
          alert(
            result.message ||
              "Gagal mengupload gambar."
          );

          return null;
        }

        return Array.isArray(
          result.data
        )
          ? result.data
          : [];
      } catch (error) {
        console.error(
          "UPLOAD GALLERY IMAGES ERROR:",
          error
        );

        alert(
          "Terjadi kesalahan saat mengupload gambar."
        );

        return null;
      } finally {
        setUploading(false);
      }
    };

  // =====================================================
  // SIMPAN PERUBAHAN
  // =====================================================

  const handleSubmit = async (
    event: FormEvent
  ) => {
    event.preventDefault();

    if (!title.trim()) {
      alert(
        "Title wajib diisi."
      );
      return;
    }

    if (
      existingImages.length === 0 &&
      selectedFiles.length === 0
    ) {
      alert(
        "Minimal satu gambar harus tersedia."
      );
      return;
    }

    setSaving(true);

    try {
      let uploadedImages: UploadedImage[] =
        [];

      if (
        selectedFiles.length > 0
      ) {
        const uploaded =
          await uploadNewImages();

        if (uploaded === null) {
          return;
        }

        uploadedImages =
          uploaded;
      }

      const allImages = [
        ...existingImages.map(
          (image) =>
            image.image
        ),

        ...uploadedImages.map(
          (image) =>
            image.url
        ),
      ];

      if (
        allImages.length === 0
      ) {
        alert(
          "Minimal satu gambar harus tersedia."
        );

        return;
      }

      console.log(
        "UPDATE GALLERY IMAGES:",
        allImages
      );

      const response =
        await fetch(
          `/api/gallery/${id}`,
          {
            method: "PUT",

            headers: {
              "Content-Type":
                "application/json",
            },

            body: JSON.stringify({
              title:
                title.trim(),

              description:
                description.trim() ||
                null,

              category:
                category.trim() ||
                null,

              images:
                allImages,
            }),
          }
        );

      const result =
        await response.json();

      console.log(
        "UPDATE GALLERY:",
        result
      );

      if (
        !response.ok ||
        !result.success
      ) {
        alert(
          result.message ||
            "Gagal memperbarui Gallery."
        );

        return;
      }

      selectedFiles.forEach(
        (item) => {
          URL.revokeObjectURL(
            item.preview
          );
        }
      );

      setSelectedFiles([]);

      alert(
        "Gallery berhasil diperbarui."
      );

      router.push(
        "/secure-panel/gallery"
      );

      router.refresh();
    } catch (error) {
      console.error(
        "UPDATE GALLERY ERROR:",
        error
      );

      alert(
        "Terjadi kesalahan saat menyimpan Gallery."
      );
    } finally {
      setSaving(false);
    }
  };

  // =====================================================
  // LOADING PAGE
  // =====================================================

  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 {
            width: 100%;
            max-width: 420px;
            background: #ffffff;
            border: 1px solid #eaecf0;
            border-radius: 18px;
            padding: 45px 25px;
            text-align: center;
            box-shadow: 0 5px 20px rgba(16, 24, 40, 0.04);
          }

          .loading-spinner {
            width: 44px;
            height: 44px;
            border: 3px solid #dcefe4;
            border-top-color: #198754;
            border-radius: 50%;
            animation: spin 0.8s linear infinite;
            margin: 0 auto 18px;
          }

          .loading-box h5 {
            color: #344054;
            font-size: 16px;
            font-weight: 700;
            margin-bottom: 6px;
          }

          .loading-box p {
            color: #98a2b3;
            font-size: 12px;
            margin: 0;
          }

          @keyframes spin {
            to {
              transform: rotate(360deg);
            }
          }
        `}</style>

        <div className="loading-page">
          <div className="loading-box">
            <div className="loading-spinner"></div>

            <h5>
              Memuat Gallery
            </h5>

            <p>
              Sedang mengambil data Gallery...
            </p>
          </div>
        </div>
      </>
    );
  }

  // =====================================================
  // 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: 1500px;
          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;
        }

        .back-button {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
          min-height: 44px;
          padding: 10px 17px;
          border-radius: 10px;
          background: #ffffff;
          color: #475467;
          border: 1px solid #e4e7ec;
          text-decoration: none;
          font-size: 13px;
          font-weight: 600;
          transition: all 0.2s ease;
        }

        .back-button:hover {
          color: #198754;
          border-color: #b7dfc9;
          background: #f4fbf7;
        }

        /* =================================================
           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;
          max-width: 720px;
        }

        .gallery-id {
          min-width: 40px;
          height: 40px;
          padding: 0 10px;
          border-radius: 10px;
          background: #f5f7f9;
          color: #667085;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 11px;
          font-weight: 700;
          flex-shrink: 0;
        }

        .form-card-body {
          padding: 28px 24px;
        }

        /* =================================================
           FORM
        ================================================= */

        .form-section {
          margin-bottom: 26px;
        }

        .form-section:last-child {
          margin-bottom: 0;
        }

        .form-label-custom {
          display: flex;
          align-items: center;
          gap: 7px;
          margin-bottom: 8px;
          color: #344054;
          font-size: 12px;
          font-weight: 700;
        }

        .form-label-icon {
          color: #198754;
          font-size: 14px;
        }

        .required-mark {
          color: #dc3545;
        }

        .form-control-custom {
          width: 100%;
          min-height: 45px;
          padding: 10px 13px;
          border: 1px solid #d0d5dd;
          border-radius: 9px;
          background: #ffffff;
          color: #101828;
          font-size: 13px;
          outline: none;
          transition:
            border-color 0.2s ease,
            box-shadow 0.2s ease;
        }

        .form-control-custom::placeholder {
          color: #98a2b3;
        }

        .form-control-custom:focus {
          border-color: #198754;
          box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.1);
        }

        .form-control-custom:disabled {
          background: #f8fafc;
          cursor: not-allowed;
        }

        textarea.form-control-custom {
          min-height: 135px;
          resize: vertical;
          line-height: 1.7;
          text-align: justify;
        }

        .form-help {
          margin-top: 7px;
          color: #98a2b3;
          font-size: 10px;
          line-height: 1.6;
          text-align: justify;
        }

        .input-row {
          display: grid;
          grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
          gap: 18px;
        }

        /* =================================================
           IMAGE SECTION
        ================================================= */

        .section-divider {
          height: 1px;
          background: #eaecf0;
          margin: 28px 0;
        }

        .image-section-header {
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
          margin-bottom: 13px;
        }

        .image-section-title {
          display: flex;
          align-items: center;
          gap: 8px;
          color: #344054;
          font-size: 12px;
          font-weight: 700;
          margin: 0;
        }

        .image-section-title i {
          color: #198754;
          font-size: 15px;
        }

        .image-count-badge {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          min-height: 28px;
          padding: 5px 9px;
          border-radius: 7px;
          background: #e9f7ef;
          color: #198754;
          font-size: 10px;
          font-weight: 700;
        }

        /* =================================================
           EXISTING IMAGE GRID
        ================================================= */

        .image-grid {
          display: grid;
          grid-template-columns: repeat(4, minmax(0, 1fr));
          gap: 15px;
        }

        .image-card {
          border: 1px solid #eaecf0;
          border-radius: 12px;
          background: #ffffff;
          overflow: hidden;
          transition:
            transform 0.2s ease,
            box-shadow 0.2s ease;
        }

        .image-card:hover {
          transform: translateY(-2px);
          box-shadow: 0 8px 22px rgba(16, 24, 40, 0.07);
        }

        .image-preview-wrapper {
          position: relative;
          width: 100%;
          aspect-ratio: 16 / 10;
          background: #f2f4f7;
          overflow: hidden;
        }

        .image-preview {
          width: 100%;
          height: 100%;
          object-fit: cover;
          display: block;
        }

        .image-number {
          position: absolute;
          top: 9px;
          left: 9px;
          min-width: 27px;
          height: 27px;
          padding: 0 7px;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: 7px;
          background: rgba(16, 24, 40, 0.78);
          color: #ffffff;
          font-size: 10px;
          font-weight: 700;
          backdrop-filter: blur(5px);
        }

        .image-remove-button {
          position: absolute;
          top: 9px;
          right: 9px;
          width: 31px;
          height: 31px;
          border: 0;
          border-radius: 8px;
          background: rgba(220, 53, 69, 0.94);
          color: #ffffff;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
          font-size: 12px;
          transition: all 0.2s ease;
        }

        .image-remove-button:hover {
          background: #bb2d3b;
          transform: scale(1.04);
        }

        .image-remove-button:disabled {
          opacity: 0.55;
          cursor: not-allowed;
        }

        .image-card-footer {
          padding: 10px 11px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 8px;
        }

        .image-card-label {
          color: #667085;
          font-size: 10px;
          font-weight: 600;
        }

        .image-card-status {
          display: inline-flex;
          align-items: center;
          gap: 4px;
          color: #198754;
          font-size: 9px;
          font-weight: 700;
        }

        /* =================================================
           NO IMAGE
        ================================================= */

        .no-image-alert {
          padding: 15px;
          border: 1px solid #ffe69c;
          border-radius: 10px;
          background: #fff9e6;
          color: #8a6d1d;
          font-size: 11px;
          line-height: 1.6;
        }

        .no-image-alert i {
          margin-right: 7px;
        }

        /* =================================================
           FILE UPLOAD
        ================================================= */

        .upload-box {
          padding: 20px;
          border: 1px dashed #b7dfc9;
          border-radius: 13px;
          background: #f8fdf9;
        }

        .upload-input {
          width: 100%;
          min-height: 46px;
          padding: 8px 10px;
          border: 1px solid #d0d5dd;
          border-radius: 9px;
          background: #ffffff;
          color: #475467;
          font-size: 12px;
        }

        .upload-input:focus {
          outline: none;
          border-color: #198754;
          box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.1);
        }

        .upload-input:disabled {
          background: #f2f4f7;
          cursor: not-allowed;
        }

        .upload-help {
          margin-top: 9px;
          color: #667085;
          font-size: 10px;
          line-height: 1.6;
          text-align: justify;
        }

        /* =================================================
           NEW IMAGE PREVIEW
        ================================================= */

        .new-image-card {
          border-color: #b7dfc9;
          background: #fcfffd;
        }

        .new-image-label {
          color: #198754;
          font-size: 9px;
          font-weight: 700;
          letter-spacing: 0.4px;
        }

        .selected-file-name {
          color: #667085;
          font-size: 10px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }

        .selected-summary {
          margin-top: 11px;
          color: #667085;
          font-size: 10px;
          line-height: 1.6;
        }

        .selected-summary strong {
          color: #198754;
        }

        /* =================================================
           INFO
        ================================================= */

        .info-box {
          display: flex;
          align-items: flex-start;
          gap: 13px;
          padding: 16px 17px;
          border: 1px solid #ccebd8;
          border-radius: 12px;
          background: #f0faf4;
          color: #344054;
        }

        .info-icon {
          width: 36px;
          height: 36px;
          border-radius: 9px;
          background: #e0f4e8;
          color: #198754;
          display: flex;
          align-items: center;
          justify-content: center;
          flex-shrink: 0;
          font-size: 16px;
        }

        .info-content {
          min-width: 0;
        }

        .info-title {
          color: #198754;
          font-size: 12px;
          font-weight: 700;
          margin-bottom: 4px;
        }

        .info-text {
          color: #667085;
          font-size: 10px;
          line-height: 1.7;
          text-align: justify;
        }

        /* =================================================
           ACTIONS
        ================================================= */

        .form-actions {
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
          padding-top: 24px;
          margin-top: 25px;
          border-top: 1px solid #eaecf0;
        }

        .form-actions-left {
          color: #98a2b3;
          font-size: 10px;
          line-height: 1.6;
        }

        .form-actions-right {
          display: flex;
          align-items: center;
          gap: 9px;
        }

        .save-button,
        .cancel-button {
          min-height: 43px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
          padding: 9px 16px;
          border-radius: 9px;
          font-size: 12px;
          font-weight: 600;
          cursor: pointer;
          transition: all 0.2s ease;
        }

        .save-button {
          border: 1px solid #198754;
          background: #198754;
          color: #ffffff;
          box-shadow: 0 6px 16px rgba(25, 135, 84, 0.14);
        }

        .save-button:hover {
          background: #157347;
          border-color: #157347;
          transform: translateY(-1px);
          box-shadow: 0 9px 20px rgba(25, 135, 84, 0.18);
        }

        .cancel-button {
          border: 1px solid #d0d5dd;
          background: #ffffff;
          color: #475467;
        }

        .cancel-button:hover {
          background: #f8fafc;
          border-color: #98a2b3;
        }

        .save-button:disabled,
        .cancel-button: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);
        }

        /* =================================================
           LARGE TABLET
        ================================================= */

        @media (max-width: 1199.98px) {
          .admin-content {
            padding: 28px;
          }

          .image-grid {
            grid-template-columns: repeat(3, minmax(0, 1fr));
          }
        }

        /* =================================================
           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%;
          }

          .back-button {
            width: 100%;
          }

          .image-grid {
            grid-template-columns: repeat(2, minmax(0, 1fr));
          }
        }

        /* =================================================
           MOBILE
        ================================================= */

        @media (max-width: 767.98px) {
          .admin-topbar {
            height: 70px;
          }

          .form-card-header {
            padding: 18px;
          }

          .form-card-body {
            padding: 20px 18px;
          }

          .input-row {
            grid-template-columns: 1fr;
            gap: 20px;
          }

          .image-grid {
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 11px;
          }

          .image-card-footer {
            padding: 9px;
          }

          .image-card-label {
            font-size: 9px;
          }

          .image-card-status {
            font-size: 8px;
          }

          .upload-box {
            padding: 15px;
          }

          .form-actions {
            flex-direction: column;
            align-items: stretch;
          }

          .form-actions-left {
            text-align: center;
          }

          .form-actions-right {
            width: 100%;
          }

          .save-button,
          .cancel-button {
            flex: 1;
          }
        }

        /* =================================================
           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;
            line-height: 1.65;
          }

          .form-card {
            border-radius: 13px;
          }

          .form-card-header {
            padding: 16px;
          }

          .form-card-body {
            padding: 18px 15px;
          }

          .form-card-title {
            font-size: 15px;
          }

          .form-card-description {
            font-size: 10px;
          }

          .gallery-id {
            min-width: 34px;
            height: 34px;
            font-size: 9px;
          }

          .image-grid {
            grid-template-columns: 1fr 1fr;
            gap: 9px;
          }

          .image-number {
            top: 6px;
            left: 6px;
            min-width: 24px;
            height: 24px;
            font-size: 9px;
          }

          .image-remove-button {
            top: 6px;
            right: 6px;
            width: 27px;
            height: 27px;
            font-size: 10px;
          }

          .image-card-footer {
            display: block;
            padding: 8px;
          }

          .image-card-status {
            margin-top: 4px;
          }

          .image-section-header {
            align-items: flex-start;
          }

          .image-section-title {
            font-size: 11px;
          }

          .image-count-badge {
            min-height: 25px;
            font-size: 9px;
          }

          .form-label-custom {
            font-size: 11px;
          }

          .form-control-custom {
            min-height: 43px;
            font-size: 12px;
          }

          textarea.form-control-custom {
            min-height: 120px;
            font-size: 12px;
          }

          .form-help,
          .upload-help {
            font-size: 9px;
          }

          .info-box {
            gap: 10px;
            padding: 13px;
          }

          .info-icon {
            width: 32px;
            height: 32px;
            font-size: 14px;
          }

          .info-title {
            font-size: 11px;
          }

          .info-text {
            font-size: 9px;
          }

          .form-actions-right {
            gap: 7px;
          }

          .save-button,
          .cancel-button {
            min-height: 40px;
            padding: 8px 10px;
            font-size: 10px;
          }

          .admin-page-footer {
            flex-direction: column;
            align-items: flex-start;
          }
        }

        /* =================================================
           EXTRA SMALL
        ================================================= */

        @media (max-width: 380px) {
          .image-grid {
            grid-template-columns: 1fr;
          }

          .image-preview-wrapper {
            aspect-ratio: 16 / 9;
          }
        }
      `}</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"
                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 active"
                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"
                onClick={() =>
                  setSidebarOpen(false)
                }
              >
                <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">
                  Gallery 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 HEADER
            ================================================= */}

            <section className="page-heading">

              <div className="page-heading-left">

                <Link
                  href="/secure-panel/gallery"
                  className="back-dashboard"
                >
                  <i className="bi bi-arrow-left"></i>

                  <span>
                    Kembali ke Gallery
                  </span>
                </Link>

                <div className="page-title-row">

                  <div className="page-title-icon">
                    <i className="bi bi-pencil-square"></i>
                  </div>

                  <div>

                    <div className="page-eyebrow">
                      WEBSITE CONTENT
                    </div>

                    <h1 className="page-title">
                      Edit Gallery
                    </h1>

                    <p className="page-description">
                      Perbarui informasi Gallery,
                      kategori, gambar yang sudah
                      tersedia, atau tambahkan
                      dokumentasi baru untuk
                      ditampilkan pada website
                      portfolio GloVaTech.
                    </p>

                  </div>

                </div>

              </div>

              <div className="page-heading-action">

                <Link
                  href="/secure-panel/gallery"
                  className="back-button"
                >
                  <i className="bi bi-images"></i>

                  <span>
                    Gallery Collection
                  </span>
                </Link>

              </div>

            </section>

            {/* =================================================
                FORM CARD
            ================================================= */}

            <section className="form-card">

              <div className="form-card-header">

                <div>

                  <div className="form-card-eyebrow">
                    GALLERY MANAGEMENT
                  </div>

                  <h2 className="form-card-title">
                    Informasi Gallery
                  </h2>

                  <p className="form-card-description">
                    Periksa dan perbarui informasi
                    utama Gallery sebelum menyimpan
                    perubahan.
                  </p>

                </div>

                <div className="gallery-id">
                  #{id}
                </div>

              </div>

              <form
                onSubmit={handleSubmit}
              >

                <div className="form-card-body">

                  {/* =================================================
                      TITLE & CATEGORY
                  ================================================= */}

                  <div className="input-row">

                    <div className="form-section">

                      <label className="form-label-custom">
                        <i className="bi bi-type form-label-icon"></i>

                        <span>
                          Gallery Title
                        </span>

                        <span className="required-mark">
                          *
                        </span>
                      </label>

                      <input
                        type="text"
                        className="form-control-custom"
                        value={title}
                        onChange={(event) =>
                          setTitle(
                            event.target.value
                          )
                        }
                        placeholder="Contoh: Engineering Workshop"
                        disabled={
                          saving ||
                          uploading
                        }
                      />

                      <div className="form-help">
                        Gunakan judul yang singkat,
                        jelas, dan menggambarkan
                        isi dokumentasi Gallery.
                      </div>

                    </div>

                    <div className="form-section">

                      <label className="form-label-custom">
                        <i className="bi bi-tag form-label-icon"></i>

                        <span>
                          Category
                        </span>
                      </label>

                      <input
                        type="text"
                        className="form-control-custom"
                        value={category}
                        onChange={(event) =>
                          setCategory(
                            event.target.value
                          )
                        }
                        placeholder="Contoh: Electrical Maintenance"
                        disabled={
                          saving ||
                          uploading
                        }
                      />

                      <div className="form-help">
                        Masukkan kategori secara
                        manual untuk mengelompokkan
                        dokumentasi Gallery.
                      </div>

                    </div>

                  </div>

                  {/* =================================================
                      DESCRIPTION
                  ================================================= */}

                  <div className="form-section">

                    <label className="form-label-custom">
                      <i className="bi bi-card-text form-label-icon"></i>

                      <span>
                        Description
                      </span>
                    </label>

                    <textarea
                      className="form-control-custom"
                      rows={5}
                      value={description}
                      onChange={(event) =>
                        setDescription(
                          event.target.value
                        )
                      }
                      placeholder="Deskripsikan dokumentasi Gallery..."
                      disabled={
                        saving ||
                        uploading
                      }
                    />

                    <div className="form-help">
                      Jelaskan secara singkat konteks
                      atau kegiatan yang terdapat pada
                      dokumentasi Gallery. Teks akan
                      ditampilkan sebagai informasi
                      pendukung pada website.
                    </div>

                  </div>

                  <div className="section-divider"></div>

                  {/* =================================================
                      EXISTING IMAGES
                  ================================================= */}

                  <div className="form-section">

                    <div className="image-section-header">

                      <h3 className="image-section-title">
                        <i className="bi bi-images"></i>

                        <span>
                          Gambar Saat Ini
                        </span>
                      </h3>

                      <span className="image-count-badge">
                        {existingImages.length} gambar
                      </span>

                    </div>

                    {existingImages.length ===
                    0 ? (

                      <div className="no-image-alert">
                        <i className="bi bi-exclamation-triangle"></i>

                        Semua gambar lama telah
                        dihapus. Tambahkan minimal
                        satu gambar baru sebelum
                        menyimpan perubahan.
                      </div>

                    ) : (

                      <div className="image-grid">

                        {existingImages.map(
                          (image, index) => (

                            <div
                              key={image.id}
                              className="image-card"
                            >

                              <div className="image-preview-wrapper">

                                <img
                                  src={image.image}
                                  alt={`${title} ${
                                    index + 1
                                  }`}
                                  className="image-preview"
                                />

                                <span className="image-number">
                                  {index + 1}
                                </span>

                                <button
                                  type="button"
                                  className="image-remove-button"
                                  onClick={() =>
                                    removeExistingImage(
                                      image.id
                                    )
                                  }
                                  disabled={
                                    saving ||
                                    uploading
                                  }
                                  title="Hapus gambar"
                                  aria-label={`Hapus gambar ${
                                    index + 1
                                  }`}
                                >
                                  <i className="bi bi-trash"></i>
                                </button>

                              </div>

                              <div className="image-card-footer">

                                <span className="image-card-label">
                                  Gambar{" "}
                                  {index + 1}
                                </span>

                                <span className="image-card-status">
                                  <i className="bi bi-check-circle-fill"></i>
                                  Tersimpan
                                </span>

                              </div>

                            </div>

                          )
                        )}

                      </div>

                    )}

                  </div>

                  {/* =================================================
                      UPLOAD NEW IMAGES
                  ================================================= */}

                  <div className="form-section">

                    <div className="image-section-header">

                      <h3 className="image-section-title">
                        <i className="bi bi-cloud-arrow-up"></i>

                        <span>
                          Tambah Gambar Baru
                        </span>
                      </h3>

                    </div>

                    <div className="upload-box">

                      <input
                        type="file"
                        className="upload-input"
                        accept="image/jpeg,image/jpg,image/png,image/webp,image/gif"
                        multiple
                        onChange={
                          handleFileChange
                        }
                        disabled={
                          saving ||
                          uploading
                        }
                      />

                      <div className="upload-help">
                        Anda dapat memilih satu atau
                        beberapa gambar sekaligus.
                        Format yang didukung: JPG,
                        JPEG, PNG, WEBP, dan GIF.
                        Maksimal ukuran setiap gambar
                        adalah 5 MB.
                      </div>

                    </div>

                  </div>

                  {/* =================================================
                      NEW IMAGE PREVIEW
                  ================================================= */}

                  {selectedFiles.length > 0 && (

                    <div className="form-section">

                      <div className="image-section-header">

                        <h3 className="image-section-title">
                          <i className="bi bi-eye"></i>

                          <span>
                            Preview Gambar Baru
                          </span>
                        </h3>

                        <span className="image-count-badge">
                          {selectedFiles.length} file
                        </span>

                      </div>

                      <div className="image-grid">

                        {selectedFiles.map(
                          (item, index) => (

                            <div
                              key={`${item.file.name}-${item.file.lastModified}-${index}`}
                              className="image-card new-image-card"
                            >

                              <div className="image-preview-wrapper">

                                <img
                                  src={item.preview}
                                  alt={
                                    item.file.name
                                  }
                                  className="image-preview"
                                />

                                <span className="image-number">
                                  {index + 1}
                                </span>

                                <button
                                  type="button"
                                  className="image-remove-button"
                                  onClick={() =>
                                    removeSelectedImage(
                                      index
                                    )
                                  }
                                  disabled={
                                    saving ||
                                    uploading
                                  }
                                  title="Hapus gambar baru"
                                  aria-label={`Hapus gambar baru ${
                                    index + 1
                                  }`}
                                >
                                  <i className="bi bi-trash"></i>
                                </button>

                              </div>

                              <div className="image-card-footer">

                                <div
                                  className="selected-file-name"
                                  title={
                                    item.file.name
                                  }
                                >
                                  {item.file.name}
                                </div>

                                <div className="new-image-label">
                                  BARU
                                </div>

                              </div>

                            </div>

                          )
                        )}

                      </div>

                      <div className="selected-summary">
                        <strong>
                          {selectedFiles.length}
                        </strong>{" "}
                        file baru siap ditambahkan
                        ke Gallery ketika perubahan
                        disimpan.
                      </div>

                    </div>

                  )}

                  {/* =================================================
                      INFORMATION
                  ================================================= */}

                  <div className="info-box">

                    <div className="info-icon">
                      <i className="bi bi-images"></i>
                    </div>

                    <div className="info-content">

                      <div className="info-title">
                        Multiple Images Gallery
                      </div>

                      <div className="info-text">
                        Gambar lama yang tidak dihapus
                        akan tetap dipertahankan.
                        Gambar baru yang dipilih akan
                        diupload dan digabungkan dengan
                        gambar yang masih tersedia.
                        Seluruh gambar tersebut akan
                        menjadi satu koleksi Gallery.
                      </div>

                    </div>

                  </div>

                  {/* =================================================
                      ACTIONS
                  ================================================= */}

                  <div className="form-actions">

                    <div className="form-actions-left">
                      <i className="bi bi-shield-check me-1"></i>

                      Perubahan akan disimpan ke
                      database Gallery.
                    </div>

                    <div className="form-actions-right">

                      <button
                        type="button"
                        className="cancel-button"
                        onClick={() =>
                          router.push(
                            "/secure-panel/gallery"
                          )
                        }
                        disabled={
                          saving ||
                          uploading
                        }
                      >
                        <i className="bi bi-x-lg"></i>

                        <span>
                          Batal
                        </span>
                      </button>

                      <button
                        type="submit"
                        className="save-button"
                        disabled={
                          saving ||
                          uploading
                        }
                      >

                        {uploading ? (
                          <>
                            <span className="spinner-border spinner-border-sm"></span>

                            <span>
                              Mengupload gambar...
                            </span>
                          </>
                        ) : saving ? (
                          <>
                            <span className="spinner-border spinner-border-sm"></span>

                            <span>
                              Menyimpan...
                            </span>
                          </>
                        ) : (
                          <>
                            <i className="bi bi-check-lg"></i>

                            <span>
                              Simpan Perubahan
                            </span>
                          </>
                        )}

                      </button>

                    </div>

                  </div>

                </div>

              </form>

            </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/gallery">

                <i className="bi bi-arrow-left me-1"></i>

                Gallery

              </Link>

            </footer>

          </main>

        </div>

      </div>
    </>
  );
}