"use client";

import Link from "next/link";
import { useEffect, useState } from "react";

type AboutStat = {
  id: number;
  label: string;
  value: string;
  icon: string | null;
  active: boolean;
  sortOrder: number;
};

export default function AboutStatsAdminPage() {
  const [stats, setStats] = useState<AboutStat[]>([]);
  const [loading, setLoading] = useState(true);
  const [sidebarOpen, setSidebarOpen] = useState(false);
  const [deletingId, setDeletingId] = useState<number | null>(null);

  // =========================================
  // GET STATS
  // =========================================

  const getStats = async () => {
    try {
      setLoading(true);

      const response = await fetch("/api/about/stats", {
        cache: "no-store",
      });

      const result = await response.json();

      if (result.success) {
        setStats(result.data);
      } else {
        console.error(
          "GET ABOUT STATS ERROR:",
          result.message
        );
      }
    } catch (error) {
      console.error(
        "Gagal mengambil statistik About:",
        error
      );
    } finally {
      setLoading(false);
    }
  };

  useEffect(() => {
    getStats();
  }, []);

  // =========================================
  // DELETE STAT
  // =========================================

  const deleteStat = async (id: number) => {
    const confirmed = window.confirm(
      "Apakah Anda yakin ingin menghapus statistik ini?"
    );

    if (!confirmed) return;

    setDeletingId(id);

    try {
      const response = await fetch(
        `/api/about/stats?id=${id}`,
        {
          method: "DELETE",
        }
      );

      const result = await response.json();

      if (!response.ok || !result.success) {
        alert(
          result.message ||
            "Gagal menghapus statistik."
        );

        return;
      }

      setStats((prev) =>
        prev.filter((stat) => stat.id !== id)
      );

      alert("Statistik berhasil dihapus.");
    } catch (error) {
      console.error(
        "DELETE ABOUT STAT ERROR:",
        error
      );

      alert(
        "Terjadi kesalahan saat menghapus statistik."
      );
    } finally {
      setDeletingId(null);
    }
  };

  // =========================================
  // CLOSE SIDEBAR
  // =========================================

  const closeSidebar = () => {
    setSidebarOpen(false);
  };

  // =========================================
  // STAT SUMMARY
  // =========================================

  const activeCount = stats.filter(
    (stat) => stat.active
  ).length;

  const inactiveCount = stats.filter(
    (stat) => !stat.active
  ).length;

  return (
    <>
      <style>{`
        * {
          box-sizing: border-box;
        }

        html,
        body {
          max-width: 100%;
          overflow-x: hidden;
        }

        /* ========================================
           MAIN
        ======================================== */

        .stats-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: #ffffff;
          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-close:hover {
          color: #198754;
        }

        .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.12),
            rgba(25, 135, 84, 0.06)
          );
          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 AREA
        ======================================== */

        .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;
          transition: 0.2s ease;
        }

        .mobile-menu-button:hover {
          background: #f5f8f6;
          color: #198754;
          border-color: #b7ddca;
        }

        .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-header {
          margin-bottom: 28px;
        }

        .page-header-top {
          display: flex;
          align-items: flex-start;
          justify-content: space-between;
          gap: 24px;
        }

        .page-heading-left {
          min-width: 0;
        }

        .page-eyebrow {
          color: #198754;
          font-size: 10px;
          font-weight: 800;
          letter-spacing: 0.12em;
          margin-bottom: 7px;
        }

        .page-title-row {
          display: flex;
          align-items: flex-start;
          gap: 15px;
        }

        .page-title-icon {
          width: 56px;
          height: 56px;
          border-radius: 16px;
          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-title {
          margin: 0;
          font-size: clamp(27px, 3vw, 36px);
          font-weight: 800;
          letter-spacing: -0.025em;
          color: #182230;
        }

        .page-description {
          margin: 8px 0 0;
          max-width: 720px;
          color: #7a8493;
          font-size: 13px;
          line-height: 1.75;
          text-align: justify;
          text-justify: inter-word;
        }

        .add-button {
          min-height: 45px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
          padding: 10px 17px;
          border-radius: 11px;
          color: #ffffff;
          background: linear-gradient(
            135deg,
            #198754,
            #20a46c
          );
          border: 1px solid #198754;
          text-decoration: none;
          font-size: 12px;
          font-weight: 700;
          box-shadow:
            0 7px 18px rgba(25, 135, 84, 0.17);
          transition: 0.2s ease;
          flex-shrink: 0;
        }

        .add-button:hover {
          color: #ffffff;
          transform: translateY(-1px);
          box-shadow:
            0 10px 24px rgba(25, 135, 84, 0.24);
        }

        .back-link {
          display: inline-flex;
          align-items: center;
          gap: 7px;
          margin-bottom: 18px;
          color: #6b7280;
          font-size: 12px;
          font-weight: 600;
          text-decoration: none;
          transition: 0.2s ease;
        }

        .back-link:hover {
          color: #198754;
          transform: translateX(-2px);
        }

        /* ========================================
           SUMMARY CARDS
        ======================================== */

        .summary-grid {
          display: grid;
          grid-template-columns: repeat(3, minmax(0, 1fr));
          gap: 16px;
          margin-bottom: 24px;
        }

        .summary-card {
          background: #ffffff;
          border: 1px solid #e6ebef;
          border-radius: 15px;
          padding: 18px;
          display: flex;
          align-items: center;
          gap: 13px;
          box-shadow:
            0 5px 20px rgba(20, 30, 45, 0.035);
          transition:
            transform 0.2s ease,
            box-shadow 0.2s ease;
        }

        .summary-card:hover {
          transform: translateY(-2px);
          box-shadow:
            0 9px 25px rgba(20, 30, 45, 0.06);
        }

        .summary-icon {
          width: 44px;
          height: 44px;
          border-radius: 12px;
          display: flex;
          align-items: center;
          justify-content: center;
          flex-shrink: 0;
          font-size: 17px;
        }

        .summary-icon.total {
          background: #eef5ff;
          color: #0d6efd;
        }

        .summary-icon.active {
          background: #eaf7f0;
          color: #198754;
        }

        .summary-icon.inactive {
          background: #f1f3f5;
          color: #6c757d;
        }

        .summary-label {
          color: #8a93a0;
          font-size: 10px;
          font-weight: 700;
          letter-spacing: 0.05em;
          text-transform: uppercase;
          margin-bottom: 3px;
        }

        .summary-value {
          color: #182230;
          font-size: 21px;
          font-weight: 800;
          line-height: 1;
        }

        /* ========================================
           TABLE CARD
        ======================================== */

        .table-card {
          width: 100%;
          background: #ffffff;
          border: 1px solid #e6ebef;
          border-radius: 18px;
          overflow: hidden;
          box-shadow:
            0 8px 30px rgba(20, 30, 45, 0.045),
            0 2px 8px rgba(20, 30, 45, 0.025);
        }

        .table-card-header {
          padding: 20px 22px;
          border-bottom: 1px solid #edf0f3;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
          background: linear-gradient(
            180deg,
            #ffffff 0%,
            #fcfdfd 100%
          );
        }

        .table-heading {
          display: flex;
          align-items: center;
          gap: 11px;
          min-width: 0;
        }

        .table-heading-icon {
          width: 40px;
          height: 40px;
          border-radius: 11px;
          background: #eaf7f0;
          color: #198754;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 16px;
          flex-shrink: 0;
        }

        .table-heading-title {
          margin: 0;
          color: #182230;
          font-size: 15px;
          font-weight: 800;
        }

        .table-heading-description {
          margin: 3px 0 0;
          color: #929aa6;
          font-size: 11px;
          line-height: 1.5;
        }

        .record-badge {
          display: inline-flex;
          align-items: center;
          gap: 6px;
          padding: 7px 10px;
          border-radius: 8px;
          background: #f4f7f5;
          color: #6d7784;
          font-size: 10px;
          font-weight: 700;
          white-space: nowrap;
        }

        /* ========================================
           TABLE
        ======================================== */

        .table-wrapper {
          width: 100%;
          overflow-x: auto;
        }

        .stats-table {
          width: 100%;
          min-width: 850px;
          border-collapse: separate;
          border-spacing: 0;
          margin: 0;
        }

        .stats-table thead th {
          padding: 14px 18px;
          background: #f9fafb;
          border-bottom: 1px solid #e8edf1;
          color: #7c8795;
          font-size: 10px;
          font-weight: 800;
          letter-spacing: 0.06em;
          text-transform: uppercase;
          white-space: nowrap;
        }

        .stats-table tbody td {
          padding: 15px 18px;
          border-bottom: 1px solid #eef1f4;
          color: #4b5563;
          font-size: 12px;
          vertical-align: middle;
        }

        .stats-table tbody tr {
          transition: background 0.18s ease;
        }

        .stats-table tbody tr:hover {
          background: #fbfdfc;
        }

        .stats-table tbody tr:last-child td {
          border-bottom: 0;
        }

        .id-badge {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          min-width: 34px;
          height: 27px;
          padding: 0 8px;
          border-radius: 7px;
          background: #f3f5f7;
          color: #737d8a;
          font-size: 10px;
          font-weight: 700;
        }

        .stat-icon-box {
          width: 42px;
          height: 42px;
          border-radius: 11px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #eaf7f0;
          color: #198754;
          font-size: 17px;
        }

        .stat-icon-empty {
          width: 42px;
          height: 42px;
          border-radius: 11px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #f5f6f8;
          color: #a0a7b1;
          font-size: 14px;
        }

        .stat-label {
          color: #263241;
          font-size: 13px;
          font-weight: 700;
        }

        .stat-value {
          display: inline-flex;
          align-items: center;
          min-height: 30px;
          padding: 5px 10px;
          border-radius: 8px;
          background: #eaf7f0;
          color: #198754;
          font-size: 12px;
          font-weight: 800;
        }

        .sort-value {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          min-width: 30px;
          height: 30px;
          border-radius: 8px;
          background: #f5f7f9;
          color: #687382;
          font-size: 11px;
          font-weight: 700;
        }

        .status-badge {
          display: inline-flex;
          align-items: center;
          gap: 6px;
          min-height: 28px;
          padding: 5px 9px;
          border-radius: 8px;
          font-size: 10px;
          font-weight: 700;
        }

        .status-badge.active {
          background: #eaf7f0;
          color: #198754;
        }

        .status-badge.inactive {
          background: #f1f3f5;
          color: #6c757d;
        }

        .status-dot {
          width: 6px;
          height: 6px;
          border-radius: 50%;
          background: currentColor;
        }

        .action-group {
          display: flex;
          justify-content: flex-end;
          align-items: center;
          gap: 7px;
        }

        .action-button {
          min-height: 34px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 6px;
          padding: 6px 10px;
          border-radius: 8px;
          background: #ffffff;
          font-size: 10px;
          font-weight: 700;
          text-decoration: none;
          transition: 0.2s ease;
        }

        .edit-button {
          color: #0d6efd;
          border: 1px solid #cddffb;
        }

        .edit-button:hover {
          color: #ffffff;
          background: #0d6efd;
          border-color: #0d6efd;
        }

        .delete-button {
          color: #dc3545;
          border: 1px solid #f1c8cd;
          cursor: pointer;
        }

        .delete-button:hover:not(:disabled) {
          color: #ffffff;
          background: #dc3545;
          border-color: #dc3545;
        }

        .delete-button:disabled {
          opacity: 0.6;
          cursor: not-allowed;
        }

        /* ========================================
           LOADING
        ======================================== */

        .loading-state {
          padding: 75px 20px;
          text-align: center;
        }

        .loading-spinner {
          width: 38px;
          height: 38px;
          border-width: 3px;
        }

        .loading-title {
          margin: 15px 0 3px;
          color: #4b5563;
          font-size: 13px;
          font-weight: 700;
        }

        .loading-description {
          margin: 0;
          color: #9aa3af;
          font-size: 11px;
        }

        /* ========================================
           EMPTY STATE
        ======================================== */

        .empty-state {
          padding: 65px 25px;
          text-align: center;
        }

        .empty-icon {
          width: 68px;
          height: 68px;
          margin: 0 auto 17px;
          border-radius: 18px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #fff7e6;
          color: #f0ad00;
          font-size: 27px;
        }

        .empty-title {
          margin: 0 0 7px;
          color: #263241;
          font-size: 17px;
          font-weight: 800;
        }

        .empty-description {
          max-width: 460px;
          margin: 0 auto 20px;
          color: #8a93a0;
          font-size: 12px;
          line-height: 1.7;
        }

        .empty-button {
          min-height: 40px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 7px;
          padding: 8px 14px;
          border-radius: 9px;
          background: #198754;
          border: 1px solid #198754;
          color: #ffffff;
          text-decoration: none;
          font-size: 11px;
          font-weight: 700;
          transition: 0.2s ease;
        }

        .empty-button:hover {
          color: #ffffff;
          background: #157347;
          transform: translateY(-1px);
        }

        /* ========================================
           PAGE FOOTER
        ======================================== */

        .admin-page-footer {
          width: 100%;
          padding: 20px 3px 5px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
          color: #9aa3af;
          font-size: 10px;
        }

        .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
        ======================================== */

        @media (max-width: 1199.98px) {
          .admin-content {
            padding: 28px;
          }

          .page-header-top {
            gap: 18px;
          }

          .summary-grid {
            gap: 13px;
          }

          .summary-card {
            padding: 15px;
          }
        }

        /* ========================================
           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;
          }

          .page-header-top {
            flex-direction: column;
          }

          .add-button {
            align-self: flex-start;
          }

          .summary-grid {
            grid-template-columns: repeat(3, minmax(0, 1fr));
          }
        }

        /* ========================================
           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-header {
            margin-bottom: 22px;
          }

          .back-link {
            margin-bottom: 15px;
          }

          .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: 11px;
            line-height: 1.7;
          }

          .add-button {
            width: 100%;
          }

          .summary-grid {
            grid-template-columns: 1fr;
            gap: 10px;
            margin-bottom: 18px;
          }

          .summary-card {
            padding: 14px;
          }

          .table-card {
            border-radius: 15px;
          }

          .table-card-header {
            padding: 17px;
            align-items: flex-start;
          }

          .table-heading-title {
            font-size: 14px;
          }

          .table-heading-description {
            font-size: 10px;
          }

          .record-badge {
            display: none;
          }

          .admin-page-footer {
            flex-direction: column;
            align-items: flex-start;
            padding-top: 18px;
          }
        }

        /* ========================================
           SMALL MOBILE
        ======================================== */

        @media (max-width: 575.98px) {
          .admin-content {
            padding: 19px 12px;
          }

          .page-title-icon {
            width: 43px;
            height: 43px;
            border-radius: 11px;
            font-size: 17px;
          }

          .page-title {
            font-size: 23px;
          }

          .page-description {
            font-size: 10.5px;
          }

          .table-card-header {
            padding: 15px;
          }

          .table-heading-icon {
            width: 37px;
            height: 37px;
            border-radius: 10px;
            font-size: 15px;
          }

          .table-heading-title {
            font-size: 13px;
          }

          .table-heading-description {
            font-size: 9.5px;
          }

          .loading-state {
            padding: 55px 15px;
          }

          .empty-state {
            padding: 50px 18px;
          }

          .empty-icon {
            width: 58px;
            height: 58px;
            border-radius: 15px;
            font-size: 23px;
          }

          .empty-title {
            font-size: 15px;
          }

          .empty-description {
            font-size: 11px;
          }
        }

        /* ========================================
           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;
          }

          .summary-card {
            padding: 13px;
          }

          .summary-icon {
            width: 40px;
            height: 40px;
          }
        }

        /* ========================================
           REDUCED MOTION
        ======================================== */

        @media (prefers-reduced-motion: reduce) {
          .stats-admin *,
          .stats-admin *::before,
          .stats-admin *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
          }
        }
      `}</style>

      <div className="stats-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"></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">
                    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-header">

                <Link
                  href="/secure-panel"
                  className="back-link"
                >
                  <i className="bi bi-arrow-left"></i>

                  Back to Dashboard
                </Link>

                <div className="page-header-top">

                  <div className="page-heading-left">

                    <div className="page-title-row">

                      <div className="page-title-icon">
                        <i className="bi bi-bar-chart-fill"></i>
                      </div>

                      <div>

                        <div className="page-eyebrow">
                          ABOUT MANAGEMENT
                        </div>

                        <h1 className="page-title">
                          About Statistics
                        </h1>

                        <p className="page-description">
                          Kelola statistik yang ditampilkan
                          pada bagian About Me di website
                          portfolio GloVaTech. Atur label,
                          nilai, icon, status, dan urutan
                          tampilan statistik secara terstruktur.
                        </p>

                      </div>

                    </div>

                  </div>

                  <Link
                    href="/secure-panel/about/stats/create"
                    className="add-button"
                  >
                    <i className="bi bi-plus-lg"></i>

                    Tambah Statistik
                  </Link>

                </div>

              </section>

              {/* ==================================
                  SUMMARY
              ================================== */}

              <section className="summary-grid">

                {/* TOTAL */}

                <div className="summary-card">

                  <div className="summary-icon total">
                    <i className="bi bi-bar-chart-fill"></i>
                  </div>

                  <div>
                    <div className="summary-label">
                      Total Statistics
                    </div>

                    <div className="summary-value">
                      {stats.length}
                    </div>
                  </div>

                </div>

                {/* ACTIVE */}

                <div className="summary-card">

                  <div className="summary-icon active">
                    <i className="bi bi-check-circle-fill"></i>
                  </div>

                  <div>
                    <div className="summary-label">
                      Active
                    </div>

                    <div className="summary-value">
                      {activeCount}
                    </div>
                  </div>

                </div>

                {/* INACTIVE */}

                <div className="summary-card">

                  <div className="summary-icon inactive">
                    <i className="bi bi-dash-circle-fill"></i>
                  </div>

                  <div>
                    <div className="summary-label">
                      Inactive
                    </div>

                    <div className="summary-value">
                      {inactiveCount}
                    </div>
                  </div>

                </div>

              </section>

              {/* ==================================
                  TABLE CARD
              ================================== */}

              <section className="table-card">

                {/* TABLE HEADER */}

                <div className="table-card-header">

                  <div className="table-heading">

                    <div className="table-heading-icon">
                      <i className="bi bi-list-columns-reverse"></i>
                    </div>

                    <div>

                      <h2 className="table-heading-title">
                        Statistics Records
                      </h2>

                      <p className="table-heading-description">
                        Daftar statistik About Me yang
                        tersimpan di database.
                      </p>

                    </div>

                  </div>

                  <div className="record-badge">
                    <i className="bi bi-database"></i>

                    {stats.length} Records
                  </div>

                </div>

                {/* LOADING */}

                {loading ? (

                  <div className="loading-state">

                    <div
                      className="spinner-border text-success loading-spinner"
                      role="status"
                      aria-label="Loading"
                    ></div>

                    <div className="loading-title">
                      Memuat statistik...
                    </div>

                    <p className="loading-description">
                      Sistem sedang mengambil data
                      About Statistics.
                    </p>

                  </div>

                ) : stats.length === 0 ? (

                  /* EMPTY */

                  <div className="empty-state">

                    <div className="empty-icon">
                      <i className="bi bi-bar-chart"></i>
                    </div>

                    <h3 className="empty-title">
                      Belum Ada Statistik
                    </h3>

                    <p className="empty-description">
                      Belum ada statistik About yang
                      tersimpan. Tambahkan statistik
                      pertama untuk ditampilkan pada
                      bagian About Me.
                    </p>

                    <Link
                      href="/secure-panel/about/stats/create"
                      className="empty-button"
                    >
                      <i className="bi bi-plus-lg"></i>

                      Tambah Statistik
                    </Link>

                  </div>

                ) : (

                  /* TABLE */

                  <div className="table-wrapper">

                    <table className="stats-table">

                      <thead>
                        <tr>

                          <th>ID</th>

                          <th>Icon</th>

                          <th>Label</th>

                          <th>Value</th>

                          <th>Urutan</th>

                          <th>Status</th>

                          <th className="text-end">
                            Aksi
                          </th>

                        </tr>
                      </thead>

                      <tbody>

                        {stats.map((stat) => (

                          <tr key={stat.id}>

                            {/* ID */}

                            <td>
                              <span className="id-badge">
                                #{stat.id}
                              </span>
                            </td>

                            {/* ICON */}

                            <td>

                              {stat.icon ? (

                                <div className="stat-icon-box">
                                  <i
                                    className={stat.icon}
                                  ></i>
                                </div>

                              ) : (

                                <div className="stat-icon-empty">
                                  <i className="bi bi-dash"></i>
                                </div>

                              )}

                            </td>

                            {/* LABEL */}

                            <td>

                              <div className="stat-label">
                                {stat.label}
                              </div>

                            </td>

                            {/* VALUE */}

                            <td>

                              <span className="stat-value">
                                {stat.value}
                              </span>

                            </td>

                            {/* SORT */}

                            <td>

                              <span className="sort-value">
                                {stat.sortOrder}
                              </span>

                            </td>

                            {/* STATUS */}

                            <td>

                              {stat.active ? (

                                <span className="status-badge active">

                                  <span className="status-dot"></span>

                                  Active

                                </span>

                              ) : (

                                <span className="status-badge inactive">

                                  <span className="status-dot"></span>

                                  Inactive

                                </span>

                              )}

                            </td>

                            {/* ACTION */}

                            <td>

                              <div className="action-group">

                                <Link
                                  href={`/secure-panel/about/stats/${stat.id}/edit`}
                                  className="action-button edit-button"
                                  title="Edit Statistik"
                                >
                                  <i className="bi bi-pencil"></i>

                                  <span className="d-none d-xl-inline">
                                    Edit
                                  </span>
                                </Link>

                                <button
                                  type="button"
                                  className="action-button delete-button"
                                  onClick={() =>
                                    deleteStat(stat.id)
                                  }
                                  disabled={
                                    deletingId === stat.id
                                  }
                                  title="Hapus Statistik"
                                >

                                  {deletingId === stat.id ? (

                                    <span
                                      className="spinner-border spinner-border-sm"
                                      role="status"
                                      style={{
                                        width: "12px",
                                        height: "12px",
                                        borderWidth: "2px",
                                      }}
                                    ></span>

                                  ) : (

                                    <i className="bi bi-trash3"></i>

                                  )}

                                  <span className="d-none d-xl-inline">
                                    {deletingId === stat.id
                                      ? "Deleting..."
                                      : "Hapus"}
                                  </span>

                                </button>

                              </div>

                            </td>

                          </tr>

                        ))}

                      </tbody>

                    </table>

                  </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">
                  <i className="bi bi-arrow-left me-1"></i>

                  About
                </Link>

              </footer>

            </main>

          </div>

        </div>
      </div>
    </>
  );
}

