"use client";

import { useEffect, useState } from "react";
import Link from "next/link";
import { useParams, useRouter } from "next/navigation";

type AboutStat = {
  id: number;
  label: string;
  value: string;
  icon: string | null;
  active: boolean;
  sortOrder: number;
};

export default function EditAboutStatPage() {
  const params = useParams();
  const router = useRouter();

  const id = params.id;

  const [form, setForm] = useState({
    label: "",
    value: "",
    icon: "",
    active: true,
    sortOrder: 1,
  });

  const [loading, setLoading] = useState(true);
  const [saving, setSaving] = useState(false);
  const [sidebarOpen, setSidebarOpen] = useState(false);

  // =========================================
  // GET STAT
  // BACKEND TIDAK DIUBAH
  // =========================================

  useEffect(() => {
    const getStat = async () => {
      try {
        const response = await fetch(`/api/about/stats?id=${id}`);
        const result = await response.json();

        if (!response.ok || !result.success) {
          alert(result.message || "Gagal mengambil data statistik");
          router.push("/secure-panel/about/stats");
          return;
        }

        const stat: AboutStat = result.data;

        setForm({
          label: stat.label,
          value: stat.value,
          icon: stat.icon || "",
          active: stat.active,
          sortOrder: stat.sortOrder,
        });
      } catch (error) {
        console.error("GET ABOUT STAT ERROR:", error);

        alert("Terjadi kesalahan saat mengambil data");

        router.push("/secure-panel/about/stats");
      } finally {
        setLoading(false);
      }
    };

    getStat();
  }, [id, router]);

  // =========================================
  // HANDLE CHANGE
  // =========================================

  const handleChange = (
    e: React.ChangeEvent<HTMLInputElement>
  ) => {
    const { name, value, type } = e.target;

    setForm((prev) => ({
      ...prev,
      [name]:
        type === "checkbox"
          ? (e.target as HTMLInputElement).checked
          : name === "sortOrder"
          ? Number(value)
          : value,
    }));
  };

  // =========================================
  // SUBMIT
  // BACKEND TIDAK DIUBAH
  // =========================================

  const handleSubmit = async (
    e: React.FormEvent<HTMLFormElement>
  ) => {
    e.preventDefault();

    setSaving(true);

    try {
      const response = await fetch("/api/about/stats", {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          id: Number(id),
          ...form,
        }),
      });

      const result = await response.json();

      if (!response.ok || !result.success) {
        alert(
          result.message || "Gagal memperbarui statistik"
        );

        return;
      }

      alert("Statistik berhasil diperbarui");

      router.push("/secure-panel/about/stats");
      router.refresh();
    } catch (error) {
      console.error("UPDATE ABOUT STAT ERROR:", error);

      alert("Terjadi kesalahan saat memperbarui statistik");
    } finally {
      setSaving(false);
    }
  };

  // =========================================
  // CLOSE SIDEBAR
  // =========================================

  const closeSidebar = () => {
    setSidebarOpen(false);
  };

  // =========================================
  // LOADING
  // =========================================

  if (loading) {
    return (
      <>
        <style>{`
          * {
            box-sizing: border-box;
          }

          html,
          body {
            max-width: 100%;
            overflow-x: hidden;
          }

          .loading-page {
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background: #f5f7fb;
            padding: 30px;
          }

          .loading-card {
            width: 100%;
            max-width: 420px;
            background: #ffffff;
            border: 1px solid #e8edf2;
            border-radius: 20px;
            padding: 42px 30px;
            text-align: center;
            box-shadow:
              0 12px 35px rgba(20, 30, 45, 0.05),
              0 2px 8px rgba(20, 30, 45, 0.025);
          }

          .loading-icon {
            width: 58px;
            height: 58px;
            margin: 0 auto 18px;
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: #eaf7f0;
            color: #198754;
            font-size: 23px;
          }

          .loading-title {
            margin: 0;
            color: #182230;
            font-size: 17px;
            font-weight: 800;
          }

          .loading-text {
            margin: 7px 0 0;
            color: #8a93a0;
            font-size: 12px;
          }

          .loading-spinner {
            width: 18px;
            height: 18px;
            margin-top: 20px;
            border: 2px solid #dcefe5;
            border-top-color: #198754;
            border-radius: 50%;
            animation: spin 0.7s linear infinite;
          }

          @keyframes spin {
            to {
              transform: rotate(360deg);
            }
          }
        `}</style>

        <main className="loading-page">
          <div className="loading-card">
            <div className="loading-icon">
              <i className="bi bi-bar-chart-line-fill"></i>
            </div>

            <h1 className="loading-title">
              Loading Statistics
            </h1>

            <p className="loading-text">
              Memuat data statistik About Me...
            </p>

            <div className="loading-spinner"></div>
          </div>
        </main>
      </>
    );
  }

  return (
    <>
      <style>{`
        * {
          box-sizing: border-box;
        }

        html,
        body {
          max-width: 100%;
          overflow-x: hidden;
        }

        /* ========================================
           ROOT
        ======================================== */

        .stats-edit-admin {
          min-height: 100vh;
          background: #f5f7fb;
          color: #1f2937;
        }

        .admin-layout {
          min-height: 100vh;
          display: flex;
          position: relative;
        }

        /* ========================================
           SIDEBAR
        ======================================== */

        .admin-sidebar {
          width: 270px;
          min-width: 270px;
          height: 100vh;
          position: fixed;
          top: 0;
          left: 0;
          z-index: 1050;
          background: #ffffff;
          border-right: 1px solid #e8ecf1;
          transition: transform 0.3s ease;
        }

        .sidebar-inner {
          height: 100%;
          display: flex;
          flex-direction: column;
          padding: 24px 16px;
          overflow-y: auto;
        }

        .sidebar-brand {
          display: flex;
          align-items: center;
          gap: 12px;
          padding: 4px 10px 28px;
          border-bottom: 1px solid #edf0f4;
          margin-bottom: 22px;
        }

        .brand-icon {
          width: 42px;
          height: 42px;
          border-radius: 12px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: linear-gradient(
            135deg,
            #198754,
            #20c997
          );
          color: white;
          font-size: 18px;
          box-shadow:
            0 8px 20px rgba(25, 135, 84, 0.2);
          flex-shrink: 0;
        }

        .brand-text {
          min-width: 0;
        }

        .brand-text strong {
          display: block;
          font-size: 16px;
          line-height: 1.2;
          color: #17202a;
        }

        .brand-text span {
          display: block;
          margin-top: 3px;
          font-size: 11px;
          color: #8b95a5;
          font-weight: 600;
          letter-spacing: 0.08em;
          text-transform: uppercase;
        }

        .sidebar-close {
          margin-left: auto;
          border: 0;
          background: transparent;
          color: #7b8492;
          font-size: 17px;
        }

        .sidebar-section-label {
          padding: 0 12px;
          margin-bottom: 8px;
          color: #9aa3af;
          font-size: 10px;
          font-weight: 700;
          letter-spacing: 0.1em;
        }

        .sidebar-nav {
          display: flex;
          flex-direction: column;
          gap: 4px;
        }

        .sidebar-link {
          display: flex;
          align-items: center;
          gap: 12px;
          min-height: 44px;
          padding: 10px 12px;
          border-radius: 11px;
          color: #697386;
          text-decoration: none;
          font-size: 14px;
          font-weight: 500;
          transition:
            background 0.2s ease,
            color 0.2s ease,
            transform 0.2s ease;
        }

        .sidebar-link:hover {
          background: #f0f8f4;
          color: #198754;
          transform: translateX(2px);
        }

        .sidebar-link.active {
          background: linear-gradient(
            90deg,
            rgba(25, 135, 84, 0.13),
            rgba(25, 135, 84, 0.055)
          );
          color: #198754;
          font-weight: 700;
        }

        .sidebar-link-icon {
          width: 23px;
          text-align: center;
          font-size: 16px;
          flex-shrink: 0;
        }

        .sidebar-bottom {
          margin-top: auto;
          padding-top: 18px;
          border-top: 1px solid #edf0f4;
        }

        .sidebar-bottom a {
          display: flex;
          align-items: center;
          gap: 10px;
          padding: 11px 12px;
          border-radius: 10px;
          color: #6b7280;
          text-decoration: none;
          font-size: 13px;
          transition: 0.2s ease;
        }

        .sidebar-bottom a:hover {
          background: #f5f7fa;
          color: #198754;
        }

        /* ========================================
           MAIN
        ======================================== */

        .admin-main {
          width: calc(100% - 270px);
          margin-left: 270px;
          min-width: 0;
        }

        /* ========================================
           TOPBAR
        ======================================== */

        .admin-topbar {
          height: 76px;
          background: rgba(255, 255, 255, 0.96);
          border-bottom: 1px solid #e9edf2;
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 0 34px;
          position: sticky;
          top: 0;
          z-index: 900;
          backdrop-filter: blur(12px);
        }

        .topbar-left {
          display: flex;
          align-items: center;
          gap: 14px;
          min-width: 0;
        }

        .mobile-menu-button {
          width: 40px;
          height: 40px;
          border: 1px solid #e2e7ed;
          background: #ffffff;
          border-radius: 10px;
          color: #344054;
          font-size: 18px;
        }

        .mobile-menu-button:hover {
          background: #f5f8f6;
          color: #198754;
        }

        .topbar-label {
          color: #9aa3af;
          font-size: 10px;
          font-weight: 700;
          letter-spacing: 0.1em;
          margin-bottom: 3px;
        }

        .topbar-title {
          color: #17202a;
          font-size: 15px;
          font-weight: 700;
        }

        .topbar-right {
          display: flex;
          align-items: center;
          gap: 10px;
          flex-shrink: 0;
        }

        .topbar-website,
        .topbar-logout {
          min-height: 40px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
          border-radius: 10px;
          padding: 8px 13px;
          text-decoration: none;
          font-size: 13px;
          font-weight: 600;
          transition: 0.2s ease;
        }

        .topbar-website {
          color: #667085;
          border: 1px solid #e4e8ed;
          background: #ffffff;
        }

        .topbar-website:hover {
          color: #198754;
          border-color: #b7ddca;
          background: #f4fbf7;
        }

        .topbar-logout {
          color: #dc3545;
          border: 1px solid #f1c4c9;
          background: #ffffff;
        }

        .topbar-logout:hover {
          background: #fff5f6;
          border-color: #e8aeb5;
        }

        /* ========================================
           CONTENT
        ======================================== */

        .admin-content {
          width: 100%;
          max-width: 1500px;
          margin: 0 auto;
          padding: 34px;
          animation: contentEnter 0.45s ease both;
        }

        @keyframes contentEnter {
          from {
            opacity: 0;
            transform: translateY(10px);
          }

          to {
            opacity: 1;
            transform: translateY(0);
          }
        }

        /* ========================================
           PAGE HEADER
        ======================================== */

        .page-heading {
          width: 100%;
          max-width: 1100px;
          margin: 0 auto 28px;
        }

        .back-link {
          display: inline-flex;
          align-items: center;
          gap: 7px;
          margin-bottom: 18px;
          color: #6b7280;
          font-size: 13px;
          font-weight: 600;
          text-decoration: none;
          transition: 0.2s ease;
        }

        .back-link:hover {
          color: #198754;
          transform: translateX(-2px);
        }

        .page-title-row {
          display: flex;
          align-items: flex-start;
          gap: 15px;
        }

        .page-title-icon {
          width: 54px;
          height: 54px;
          border-radius: 15px;
          background: linear-gradient(
            135deg,
            rgba(25, 135, 84, 0.13),
            rgba(32, 201, 151, 0.08)
          );
          color: #198754;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 22px;
          flex-shrink: 0;
        }

        .page-eyebrow {
          color: #198754;
          font-size: 10px;
          font-weight: 800;
          letter-spacing: 0.11em;
          margin-bottom: 4px;
        }

        .page-title {
          margin: 0;
          font-size: clamp(26px, 3vw, 34px);
          font-weight: 800;
          letter-spacing: -0.025em;
          color: #182230;
        }

        .page-description {
          margin: 7px 0 0;
          color: #7a8493;
          font-size: 14px;
          line-height: 1.7;
          max-width: 760px;
          text-align: justify;
          text-justify: inter-word;
        }

        /* ========================================
           FORM LAYOUT
        ======================================== */

        .form-wrapper {
          width: 100%;
          max-width: 1100px;
          margin: 0 auto;
        }

        .form-grid {
          display: grid;
          grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.8fr);
          gap: 22px;
          align-items: start;
        }

        /* ========================================
           CARD
        ======================================== */

        .form-card,
        .preview-card {
          background: #ffffff;
          border: 1px solid #e6ebef;
          border-radius: 20px;
          overflow: hidden;
          box-shadow:
            0 8px 30px rgba(20, 30, 45, 0.045),
            0 2px 8px rgba(20, 30, 45, 0.025);
        }

        .card-header-custom {
          padding: 23px 26px;
          border-bottom: 1px solid #edf0f3;
          display: flex;
          align-items: center;
          gap: 13px;
          background: linear-gradient(
            180deg,
            #ffffff 0%,
            #fcfdfd 100%
          );
        }

        .header-icon {
          width: 44px;
          height: 44px;
          border-radius: 12px;
          background: #eaf7f0;
          color: #198754;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 18px;
          flex-shrink: 0;
        }

        .card-header-title {
          margin: 0;
          color: #182230;
          font-size: 16px;
          font-weight: 800;
        }

        .card-header-description {
          margin: 4px 0 0;
          color: #8a93a0;
          font-size: 11px;
          line-height: 1.55;
        }

        .form-body {
          padding: 28px;
        }

        /* ========================================
           FORM GROUP
        ======================================== */

        .form-group {
          margin-bottom: 21px;
        }

        .form-group:last-child {
          margin-bottom: 0;
        }

        .form-label-custom {
          display: flex;
          align-items: center;
          gap: 6px;
          margin-bottom: 8px;
          color: #344054;
          font-size: 12px;
          font-weight: 700;
        }

        .label-icon {
          color: #198754;
          font-size: 12px;
        }

        .required-mark {
          color: #dc3545;
          font-size: 12px;
        }

        .form-control-custom {
          width: 100%;
          min-height: 47px;
          border: 1px solid #dfe5eb;
          border-radius: 10px;
          background: #ffffff;
          color: #344054;
          padding: 10px 13px;
          font-size: 13px;
          outline: none;
          transition:
            border-color 0.2s ease,
            box-shadow 0.2s ease,
            background 0.2s ease;
        }

        .form-control-custom::placeholder {
          color: #adb5bf;
        }

        .form-control-custom:hover {
          border-color: #c7d0d9;
        }

        .form-control-custom:focus {
          border-color: #198754;
          box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.1);
          background: #ffffff;
        }

        .field-help {
          margin-top: 6px;
          color: #9aa3af;
          font-size: 10px;
          line-height: 1.5;
          text-align: justify;
          text-justify: inter-word;
        }

        /* ========================================
           ICON INPUT
        ======================================== */

        .icon-input-wrapper {
          position: relative;
        }

        .icon-input {
          padding-right: 52px;
        }

        .icon-input-preview {
          position: absolute;
          top: 50%;
          right: 8px;
          transform: translateY(-50%);
          width: 33px;
          height: 33px;
          border-radius: 8px;
          background: #eaf7f0;
          color: #198754;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 15px;
          pointer-events: none;
        }

        /* ========================================
           FORM ROW
        ======================================== */

        .form-row {
          display: grid;
          grid-template-columns: minmax(0, 1fr) minmax(150px, 0.45fr);
          gap: 18px;
        }

        /* ========================================
           STATUS SWITCH
        ======================================== */

        .status-box {
          padding: 15px 16px;
          border: 1px solid #e2e8ed;
          border-radius: 12px;
          background: #fbfcfd;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
        }

        .status-content {
          min-width: 0;
        }

        .status-title {
          margin: 0;
          color: #344054;
          font-size: 12px;
          font-weight: 800;
        }

        .status-description {
          margin: 3px 0 0;
          color: #98a1ae;
          font-size: 10px;
          line-height: 1.45;
        }

        .switch {
          position: relative;
          width: 46px;
          height: 25px;
          flex-shrink: 0;
        }

        .switch input {
          opacity: 0;
          width: 0;
          height: 0;
        }

        .slider {
          position: absolute;
          cursor: pointer;
          inset: 0;
          background: #cbd3dc;
          border-radius: 30px;
          transition: 0.25s ease;
        }

        .slider::before {
          content: "";
          position: absolute;
          width: 19px;
          height: 19px;
          left: 3px;
          top: 3px;
          background: #ffffff;
          border-radius: 50%;
          box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
          transition: 0.25s ease;
        }

        .switch input:checked + .slider {
          background: #198754;
        }

        .switch input:checked + .slider::before {
          transform: translateX(21px);
        }

        /* ========================================
           ACTIONS
        ======================================== */

        .form-footer {
          margin-top: 28px;
          padding-top: 22px;
          border-top: 1px solid #edf0f3;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
        }

        .footer-note {
          display: flex;
          align-items: flex-start;
          gap: 8px;
          color: #98a1ae;
          font-size: 10px;
          line-height: 1.5;
          max-width: 430px;
          text-align: justify;
          text-justify: inter-word;
        }

        .footer-note i {
          color: #198754;
          font-size: 13px;
          margin-top: 1px;
          flex-shrink: 0;
        }

        .form-actions {
          display: flex;
          align-items: center;
          gap: 9px;
          flex-shrink: 0;
        }

        .cancel-button,
        .save-button {
          min-height: 43px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 7px;
          padding: 9px 16px;
          border-radius: 10px;
          font-size: 12px;
          font-weight: 700;
          text-decoration: none;
          transition: 0.2s ease;
          cursor: pointer;
        }

        .cancel-button {
          color: #667085;
          background: #ffffff;
          border: 1px solid #dfe4e9;
        }

        .cancel-button:hover {
          color: #344054;
          background: #f7f8fa;
          border-color: #cfd6dd;
        }

        .save-button {
          color: #ffffff;
          background: linear-gradient(
            135deg,
            #198754,
            #20a46c
          );
          border: 1px solid #198754;
          box-shadow:
            0 7px 16px rgba(25, 135, 84, 0.18);
        }

        .save-button:hover:not(:disabled) {
          color: #ffffff;
          transform: translateY(-1px);
          box-shadow:
            0 10px 22px rgba(25, 135, 84, 0.25);
        }

        .save-button:disabled {
          opacity: 0.65;
          cursor: not-allowed;
          box-shadow: none;
        }

        /* ========================================
           PREVIEW CARD
        ======================================== */

        .preview-card {
          position: sticky;
          top: 100px;
        }

        .preview-body {
          padding: 24px;
        }

        .preview-label {
          color: #9aa3af;
          font-size: 10px;
          font-weight: 800;
          letter-spacing: 0.09em;
          text-transform: uppercase;
          margin-bottom: 14px;
        }

        .stat-preview {
          border: 1px solid #e5ece8;
          border-radius: 16px;
          padding: 20px;
          background:
            linear-gradient(
              145deg,
              #ffffff 0%,
              #f8fcfa 100%
            );
        }

        .stat-preview-icon {
          width: 50px;
          height: 50px;
          border-radius: 13px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #eaf7f0;
          color: #198754;
          font-size: 20px;
          margin-bottom: 17px;
        }

        .stat-preview-value {
          margin: 0;
          color: #17202a;
          font-size: 27px;
          font-weight: 800;
          letter-spacing: -0.025em;
          word-break: break-word;
        }

        .stat-preview-label {
          margin: 5px 0 0;
          color: #7b8492;
          font-size: 12px;
          line-height: 1.5;
          word-break: break-word;
        }

        .preview-status {
          display: inline-flex;
          align-items: center;
          gap: 6px;
          margin-top: 17px;
          padding: 6px 9px;
          border-radius: 8px;
          font-size: 9px;
          font-weight: 700;
        }

        .preview-status.active {
          background: #eaf7f0;
          color: #198754;
        }

        .preview-status.inactive {
          background: #f0f2f4;
          color: #7b8492;
        }

        .status-dot {
          width: 6px;
          height: 6px;
          border-radius: 50%;
          background: currentColor;
        }

        .preview-info {
          margin-top: 18px;
          padding-top: 18px;
          border-top: 1px solid #edf0f3;
        }

        .preview-info-row {
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 10px;
          padding: 7px 0;
          font-size: 10px;
        }

        .preview-info-row span:first-child {
          color: #98a1ae;
        }

        .preview-info-row span:last-child {
          color: #344054;
          font-weight: 700;
        }

        /* ========================================
           PAGE FOOTER
        ======================================== */

        .admin-page-footer {
          width: 100%;
          max-width: 1100px;
          margin: 0 auto;
          padding: 20px 3px 5px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
          color: #9aa3af;
          font-size: 11px;
        }

        .admin-page-footer div {
          display: flex;
          align-items: center;
          gap: 7px;
        }

        .admin-page-footer i {
          color: #198754;
        }

        .admin-page-footer a {
          color: #7b8492;
          text-decoration: none;
          font-weight: 600;
        }

        .admin-page-footer a:hover {
          color: #198754;
        }

        /* ========================================
           OVERLAY
        ======================================== */

        .sidebar-overlay {
          display: none;
        }

        /* ========================================
           LARGE DESKTOP
        ======================================== */

        @media (max-width: 1399.98px) {
          .admin-content {
            padding: 30px;
          }
        }

        /* ========================================
           TABLET / LAPTOP
        ======================================== */

        @media (max-width: 1199.98px) {
          .admin-content {
            padding: 28px;
          }

          .page-heading,
          .form-wrapper,
          .admin-page-footer {
            max-width: 950px;
          }

          .form-grid {
            grid-template-columns:
              minmax(0, 1.5fr)
              minmax(260px, 0.75fr);
          }

          .form-body {
            padding: 25px;
          }
        }

        /* ========================================
           MOBILE SIDEBAR
        ======================================== */

        @media (max-width: 991.98px) {
          .admin-sidebar {
            transform: translateX(-100%);
            box-shadow:
              15px 0 40px rgba(20, 30, 45, 0.1);
          }

          .admin-sidebar.open {
            transform: translateX(0);
          }

          .admin-main {
            width: 100%;
            margin-left: 0;
          }

          .sidebar-overlay {
            position: fixed;
            inset: 0;
            z-index: 1040;
            display: block;
            background: rgba(15, 23, 42, 0.35);
            backdrop-filter: blur(2px);
          }

          .admin-topbar {
            padding: 0 24px;
          }

          .form-grid {
            grid-template-columns: 1fr;
          }

          .preview-card {
            position: static;
          }
        }

        /* ========================================
           MOBILE
        ======================================== */

        @media (max-width: 767.98px) {
          .admin-topbar {
            height: 68px;
            padding: 0 16px;
          }

          .topbar-title {
            font-size: 13px;
          }

          .admin-content {
            width: 100%;
            max-width: 100%;
            padding: 22px 16px;
          }

          .page-heading {
            max-width: 100%;
            margin-bottom: 22px;
          }

          .page-title-row {
            gap: 12px;
          }

          .page-title-icon {
            width: 47px;
            height: 47px;
            border-radius: 13px;
            font-size: 19px;
          }

          .page-title {
            font-size: 26px;
          }

          .page-description {
            font-size: 12px;
            line-height: 1.7;
          }

          .form-wrapper {
            max-width: 100%;
          }

          .form-card,
          .preview-card {
            border-radius: 15px;
          }

          .card-header-custom {
            padding: 19px;
          }

          .form-body {
            padding: 20px 18px;
          }

          .form-row {
            grid-template-columns: 1fr;
            gap: 0;
          }

          .form-footer {
            align-items: stretch;
            flex-direction: column;
          }

          .footer-note {
            max-width: 100%;
          }

          .form-actions {
            width: 100%;
            display: grid;
            grid-template-columns: 1fr 1fr;
          }

          .cancel-button,
          .save-button {
            width: 100%;
          }

          .admin-page-footer {
            max-width: 100%;
            flex-direction: column;
            align-items: flex-start;
          }
        }

        /* ========================================
           SMALL MOBILE
        ======================================== */

        @media (max-width: 575.98px) {
          .admin-content {
            padding: 19px 12px;
          }

          .page-title-row {
            align-items: flex-start;
          }

          .page-title-icon {
            width: 43px;
            height: 43px;
            border-radius: 11px;
            font-size: 17px;
          }

          .page-title {
            font-size: 23px;
          }

          .page-description {
            font-size: 11px;
          }

          .card-header-custom {
            padding: 17px;
          }

          .header-icon {
            width: 39px;
            height: 39px;
            border-radius: 10px;
            font-size: 16px;
          }

          .card-header-title {
            font-size: 14px;
          }

          .card-header-description {
            font-size: 10px;
          }

          .form-body {
            padding: 18px 15px;
          }

          .form-label-custom {
            font-size: 11px;
          }

          .form-control-custom {
            min-height: 44px;
            font-size: 12px;
            padding: 9px 11px;
          }

          .status-box {
            align-items: flex-start;
          }

          .form-actions {
            grid-template-columns: 1fr;
          }

          .cancel-button,
          .save-button {
            min-height: 42px;
          }

          .preview-body {
            padding: 19px;
          }

          .stat-preview {
            padding: 18px;
          }

          .stat-preview-value {
            font-size: 24px;
          }

          .admin-page-footer {
            padding-left: 2px;
            padding-right: 2px;
          }
        }

        /* ========================================
           EXTRA SMALL
        ======================================== */

        @media (max-width: 399.98px) {
          .topbar-right {
            gap: 6px;
          }

          .topbar-website,
          .topbar-logout {
            width: 38px;
            height: 38px;
            min-height: 38px;
            padding: 0;
            border-radius: 9px;
          }

          .topbar-title {
            max-width: 145px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }

          .page-title {
            font-size: 21px;
          }

          .page-title-row {
            gap: 10px;
          }

          .form-card,
          .preview-card {
            border-radius: 13px;
          }

          .form-body {
            padding: 16px 13px;
          }

          .stat-preview-value {
            font-size: 22px;
          }
        }

        /* ========================================
           REDUCED MOTION
        ======================================== */

        @media (prefers-reduced-motion: reduce) {
          .stats-edit-admin *,
          .stats-edit-admin *::before,
          .stats-edit-admin *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
          }
        }
      `}</style>

      <div className="stats-edit-admin">
        <div className="admin-layout">

          {/* ======================================
              MOBILE OVERLAY
          ====================================== */}

          {sidebarOpen && (
            <div
              className="sidebar-overlay"
              onClick={closeSidebar}
              aria-hidden="true"
            />
          )}

          {/* ======================================
              SIDEBAR
          ====================================== */}

          <aside
            className={`admin-sidebar ${
              sidebarOpen ? "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={closeSidebar}
                  aria-label="Close 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={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-speedometer2"></i>
                  </span>

                  <span>Dashboard</span>
                </Link>
              </nav>

              {/* CONTENT */}

              <div className="sidebar-section-label mt-4">
                CONTENT
              </div>

              <nav className="sidebar-nav">

                {/* HERO */}

                <Link
                  href="/secure-panel/hero"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-stars"></i>
                  </span>

                  <span>Hero</span>
                </Link>

                {/* ABOUT */}

                <Link
                  href="/secure-panel/about"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-person-vcard"></i>
                  </span>

                  <span>About</span>
                </Link>

                {/* STATS */}

                <Link
                  href="/secure-panel/about/stats"
                  className="sidebar-link active"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-bar-chart-line-fill"></i>
                  </span>

                  <span>About Stats</span>
                </Link>

                {/* EDUCATION */}

                <Link
                  href="/secure-panel/education"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-mortarboard"></i>
                  </span>

                  <span>Education</span>
                </Link>

                {/* SKILLS */}

                <Link
                  href="/secure-panel/skills"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-tools"></i>
                  </span>

                  <span>Skills</span>
                </Link>

                {/* EXPERIENCE */}

                <Link
                  href="/secure-panel/experience"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-briefcase"></i>
                  </span>

                  <span>Experience</span>
                </Link>

                {/* PROJECTS */}

                <Link
                  href="/secure-panel/projects"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-code-square"></i>
                  </span>

                  <span>Projects</span>
                </Link>

                {/* CERTIFICATION */}

                <Link
                  href="/secure-panel/certifications"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-patch-check"></i>
                  </span>

                  <span>Certification</span>
                </Link>

                {/* ACHIEVEMENT */}

                <Link
                  href="/secure-panel/achievements"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-trophy"></i>
                  </span>

                  <span>Achievement</span>
                </Link>

                {/* SERVICES */}

                <Link
                  href="/secure-panel/services"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-gear-wide-connected"></i>
                  </span>

                  <span>Services</span>
                </Link>

                {/* GALLERY */}

                <Link
                  href="/secure-panel/gallery"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-images"></i>
                  </span>

                  <span>Gallery</span>
                </Link>

                {/* CONTACT */}
                <Link
                  href="/secure-panel/contact-info"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-person-lines-fill"></i>
                  </span>

                  <span>Contact</span>
                </Link>

                {/* CONTACT SOCIAL MEDIA */}
                <Link
                  href="/secure-panel/contact-info/list"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-share-fill"></i>
                  </span>

                  <span>Contact Social Media</span>
                </Link>

                {/* ARTICLES */}

                <Link
                  href="/secure-panel/articles"
                  className="sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="sidebar-link-icon">
                    <i className="bi bi-journal-text"></i>
                  </span>

                  <span>Articles</span>
                </Link>


{/* CONTACT MESSAGES */}

<Link
  href="/secure-panel/contact-messages"
  className="sidebar-link"
  onClick={closeSidebar}
>
  <span className="sidebar-link-icon">
    <i className="bi bi-chat-left-text"></i>
  </span>

  <span>Contact Messages</span>
</Link>

{/* CONTACT USER */}

<Link
  href="/secure-panel/contact-users"
  className="sidebar-link"
  onClick={closeSidebar}
>
  <span className="sidebar-link-icon">
    <i className="bi bi-people-fill"></i>
  </span>

  <span>Contact User</span>
</Link>
              </nav>

              {/* SIDEBAR BOTTOM */}

              <div className="sidebar-bottom">
                <Link
                  href="/"
                  onClick={closeSidebar}
                >
                  <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="Open menu"
                >
                  <i className="bi bi-list"></i>
                </button>

                <div>
                  <div className="topbar-label">
                    ADMIN PANEL
                  </div>

                  <div className="topbar-title">
                    Edit About Statistics
                  </div>
                </div>

              </div>

              <div className="topbar-right">

                <Link
                  href="/"
                  className="topbar-website"
                  title="View Website"
                >
                  <i className="bi bi-globe2"></i>

                  <span className="d-none d-sm-inline">
                    Website
                  </span>
                </Link>

                <Link
                  href="/secure-panel/login"
                  className="topbar-logout"
                  title="Logout"
                >
                  <i className="bi bi-box-arrow-right"></i>

                  <span className="d-none d-sm-inline">
                    Logout
                  </span>
                </Link>

              </div>

            </header>

            {/* ====================================
                CONTENT
            ==================================== */}

            <main className="admin-content">

              {/* PAGE HEADER */}

              <section className="page-heading">

                <Link
                  href="/secure-panel/about/stats"
                  className="back-link"
                >
                  <i className="bi bi-arrow-left"></i>

                  Back to Statistics
                </Link>

                <div className="page-title-row">

                  <div className="page-title-icon">
                    <i className="bi bi-bar-chart-line-fill"></i>
                  </div>

                  <div>

                    <div className="page-eyebrow">
                      ABOUT STATISTICS MANAGEMENT
                    </div>

                    <h1 className="page-title">
                      Edit Statistics
                    </h1>

                    <p className="page-description">
                      Perbarui informasi statistik yang
                      ditampilkan pada bagian About Me.
                      Kamu dapat mengubah label, nilai,
                      Bootstrap Icon, urutan tampilan, dan
                      status statistik tanpa mengubah sistem
                      backend yang sudah tersedia.
                    </p>

                  </div>

                </div>

              </section>

              {/* FORM */}

              <section className="form-wrapper">

                <div className="form-grid">

                  {/* ==================================
                      FORM CARD
                  ================================== */}

                  <div className="form-card">

                    <div className="card-header-custom">

                      <div className="header-icon">
                        <i className="bi bi-pencil-square"></i>
                      </div>

                      <div>

                        <h2 className="card-header-title">
                          Statistic Information
                        </h2>

                        <p className="card-header-description">
                          Perbarui data statistik About Me
                          sesuai kebutuhan.
                        </p>

                      </div>

                    </div>

                    <div className="form-body">

                      <form onSubmit={handleSubmit}>

                        {/* LABEL + SORT ORDER */}

                        <div className="form-row">

                          {/* LABEL */}

                          <div className="form-group">

                            <label
                              htmlFor="label"
                              className="form-label-custom"
                            >
                              <i className="bi bi-tag label-icon"></i>

                              Label

                              <span className="required-mark">
                                *
                              </span>
                            </label>

                            <input
                              type="text"
                              id="label"
                              name="label"
                              className="form-control-custom"
                              placeholder="Example: Projects Completed"
                              value={form.label}
                              onChange={handleChange}
                              required
                            />

                            <div className="field-help">
                              Nama atau keterangan statistik
                              yang akan ditampilkan kepada
                              pengunjung.
                            </div>

                          </div>

                          {/* SORT ORDER */}

                          <div className="form-group">

                            <label
                              htmlFor="sortOrder"
                              className="form-label-custom"
                            >
                              <i className="bi bi-list-ol label-icon"></i>

                              Sort Order

                              <span className="required-mark">
                                *
                              </span>
                            </label>

                            <input
                              type="number"
                              id="sortOrder"
                              name="sortOrder"
                              min="1"
                              className="form-control-custom"
                              value={form.sortOrder}
                              onChange={handleChange}
                              required
                            />

                            <div className="field-help">
                              Menentukan urutan statistik.
                            </div>

                          </div>

                        </div>

                        {/* VALUE */}

                        <div className="form-group">

                          <label
                            htmlFor="value"
                            className="form-label-custom"
                          >
                            <i className="bi bi-123 label-icon"></i>

                            Value

                            <span className="required-mark">
                              *
                            </span>
                          </label>

                          <input
                            type="text"
                            id="value"
                            name="value"
                            className="form-control-custom"
                            placeholder="Example: 25+"
                            value={form.value}
                            onChange={handleChange}
                            required
                          />

                          <div className="field-help">
                            Nilai utama yang akan ditampilkan,
                            misalnya 25+, 3.50, 10+, atau nilai
                            lain sesuai kebutuhan.
                          </div>

                        </div>

                        {/* ICON */}

                        <div className="form-group">

                          <label
                            htmlFor="icon"
                            className="form-label-custom"
                          >
                            <i className="bi bi-bootstrap label-icon"></i>

                            Bootstrap Icon
                          </label>

                          <div className="icon-input-wrapper">

                            <input
                              type="text"
                              id="icon"
                              name="icon"
                              className="form-control-custom icon-input"
                              placeholder="bi bi-folder-check"
                              value={form.icon}
                              onChange={handleChange}
                            />

                            {form.icon && (
                              <div className="icon-input-preview">
                                <i
                                  className={form.icon}
                                ></i>
                              </div>
                            )}

                          </div>

                          <div className="field-help">
                            Gunakan class Bootstrap Icons,
                            contoh: bi bi-folder-check,
                            bi bi-code-slash, atau
                            bi bi-mortarboard.
                          </div>

                        </div>

                        {/* ACTIVE */}

                        <div className="form-group">

                          <div className="status-box">

                            <div className="status-content">

                              <h3 className="status-title">
                                Statistic Status
                              </h3>

                              <p className="status-description">
                                Aktifkan statistik agar dapat
                                ditampilkan pada halaman About
                                Me.
                              </p>

                            </div>

                            <label className="switch">
                              <input
                                type="checkbox"
                                id="active"
                                name="active"
                                checked={form.active}
                                onChange={handleChange}
                              />

                              <span className="slider"></span>
                            </label>

                          </div>

                        </div>

                        {/* ACTION */}

                        <div className="form-footer">

                          <div className="footer-note">

                            <i className="bi bi-shield-check"></i>

                            <span>
                              Perubahan akan disimpan melalui
                              sistem About Statistics yang
                              sudah tersedia.
                            </span>

                          </div>

                          <div className="form-actions">

                            <Link
                              href="/secure-panel/about/stats"
                              className="cancel-button"
                            >
                              <i className="bi bi-x-lg"></i>

                              Batal
                            </Link>

                            <button
                              type="submit"
                              className="save-button"
                              disabled={saving}
                            >

                              {saving ? (
                                <>
                                  <span
                                    className="spinner-border spinner-border-sm"
                                    role="status"
                                    style={{
                                      width: "13px",
                                      height: "13px",
                                      borderWidth: "2px",
                                    }}
                                  ></span>

                                  Menyimpan...
                                </>
                              ) : (
                                <>
                                  <i className="bi bi-check-lg"></i>

                                  Simpan Perubahan
                                </>
                              )}

                            </button>

                          </div>

                        </div>

                      </form>

                    </div>

                  </div>

                  {/* ==================================
                      LIVE PREVIEW
                  ================================== */}

                  <aside className="preview-card">

                    <div className="card-header-custom">

                      <div className="header-icon">
                        <i className="bi bi-eye"></i>
                      </div>

                      <div>

                        <h2 className="card-header-title">
                          Live Preview
                        </h2>

                        <p className="card-header-description">
                          Preview statistik secara langsung.
                        </p>

                      </div>

                    </div>

                    <div className="preview-body">

                      <div className="preview-label">
                        STATISTIC PREVIEW
                      </div>

                      <div className="stat-preview">

                        <div className="stat-preview-icon">

                          {form.icon ? (
                            <i className={form.icon}></i>
                          ) : (
                            <i className="bi bi-bar-chart"></i>
                          )}

                        </div>

                        <h3 className="stat-preview-value">
                          {form.value || "0"}
                        </h3>

                        <p className="stat-preview-label">
                          {form.label || "Statistic Label"}
                        </p>

                        <div
                          className={`preview-status ${
                            form.active
                              ? "active"
                              : "inactive"
                          }`}
                        >
                          <span className="status-dot"></span>

                          {form.active
                            ? "Active"
                            : "Inactive"}
                        </div>

                      </div>

                      {/* INFORMATION */}

                      <div className="preview-info">

                        <div className="preview-info-row">
                          <span>
                            Statistic ID
                          </span>

                          <span>
                            #{id}
                          </span>
                        </div>

                        <div className="preview-info-row">
                          <span>
                            Sort Order
                          </span>

                          <span>
                            {form.sortOrder}
                          </span>
                        </div>

                        <div className="preview-info-row">
                          <span>
                            Status
                          </span>

                          <span>
                            {form.active
                              ? "Published"
                              : "Hidden"}
                          </span>
                        </div>

                      </div>

                    </div>

                  </aside>

                </div>

              </section>

              {/* ==================================
                  FOOTER
              ================================== */}

              <footer className="admin-page-footer">

                <div>
                  <i className="bi bi-shield-check"></i>

                  <span>
                    Admin Content Management System
                  </span>
                </div>

                <Link href="/secure-panel/about/stats">
                  <i className="bi bi-bar-chart-line me-1"></i>

                  About Statistics
                </Link>

              </footer>

            </main>

          </div>

        </div>
      </div>
    </>
  );
}