"use client";

import { useState } from "react";
import Link from "next/link";
import { useRouter } from "next/navigation";

export default function CreateAboutStatPage() {
  const router = useRouter();

  const [form, setForm] = useState({
    label: "",
    value: "",
    icon: "",
    active: true,
    sortOrder: 1,
  });

  const [loading, setLoading] = useState(false);
  const [sidebarOpen, setSidebarOpen] = useState(false);

  // =========================================
  // HANDLE CHANGE
  // =========================================

  const handleChange = (
    e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>
  ) => {
    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();

    setLoading(true);

    try {
      const response = await fetch("/api/about/stats", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify(form),
      });

      const result = await response.json();

      if (!response.ok || !result.success) {
        alert(
          result.message ||
            "Gagal menambahkan statistik"
        );
        return;
      }

      alert("Statistik berhasil ditambahkan");

      router.push("/secure-panel/about/stats");
      router.refresh();
    } catch (error) {
      console.error(
        "CREATE ABOUT STAT ERROR:",
        error
      );

      alert(
        "Terjadi kesalahan saat menambahkan statistik"
      );
    } finally {
      setLoading(false);
    }
  };

  // =========================================
  // CLOSE SIDEBAR
  // =========================================

  const closeSidebar = () => {
    setSidebarOpen(false);
  };

  // =========================================
  // RENDER
  // =========================================

  return (
    <>
      <style>{`
        * {
          box-sizing: border-box;
        }

        html,
        body {
          max-width: 100%;
          overflow-x: hidden;
        }

        /* ========================================
           MAIN
        ======================================== */

        .stats-create-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-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.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
        ======================================== */

        .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 HEADING
        ======================================== */

        .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: 720px;
          text-align: justify;
          text-justify: inter-word;
        }

        /* ========================================
           FORM WRAPPER
        ======================================== */

        .form-wrapper {
          width: 100%;
          max-width: 1100px;
          margin: 0 auto;
        }

        .form-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
        ======================================== */

        .form-card-header {
          padding: 24px 28px;
          border-bottom: 1px solid #edf0f3;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 20px;
          background: linear-gradient(
            180deg,
            #ffffff 0%,
            #fcfdfd 100%
          );
        }

        .form-header-left {
          display: flex;
          align-items: center;
          gap: 13px;
          min-width: 0;
        }

        .form-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;
        }

        .form-header-title {
          margin: 0;
          color: #182230;
          font-size: 17px;
          font-weight: 800;
        }

        .form-header-description {
          margin: 4px 0 0;
          color: #8a93a0;
          font-size: 12px;
          line-height: 1.55;
          text-align: justify;
          text-justify: inter-word;
        }

        .new-record {
          display: inline-flex;
          align-items: center;
          gap: 6px;
          padding: 7px 10px;
          border-radius: 8px;
          background: #f1f8f4;
          color: #198754;
          font-size: 10px;
          font-weight: 700;
          white-space: nowrap;
          flex-shrink: 0;
        }

        .new-record-dot {
          width: 6px;
          height: 6px;
          border-radius: 50%;
          background: #198754;
        }

        /* ========================================
           FORM BODY
        ======================================== */

        .form-card-body {
          padding: 30px;
        }

        .form-inner {
          width: 100%;
          max-width: 900px;
          margin: 0 auto;
        }

        .form-section {
          margin-bottom: 30px;
        }

        .form-section:last-of-type {
          margin-bottom: 0;
        }

        .section-heading {
          display: flex;
          align-items: center;
          gap: 10px;
          margin-bottom: 18px;
          padding-bottom: 11px;
          border-bottom: 1px solid #edf0f3;
        }

        .section-number {
          width: 28px;
          height: 28px;
          border-radius: 8px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #eaf7f0;
          color: #198754;
          font-size: 11px;
          font-weight: 800;
          flex-shrink: 0;
        }

        .section-title {
          margin: 0;
          color: #263241;
          font-size: 13px;
          font-weight: 800;
        }

        .section-description {
          margin: 2px 0 0;
          color: #9aa3af;
          font-size: 10px;
          line-height: 1.5;
          text-align: justify;
          text-justify: inter-word;
        }

        /* ========================================
           FORM GROUP
        ======================================== */

        .form-group {
          margin-bottom: 21px;
        }

        .form-group:last-child {
          margin-bottom: 0;
        }

        .form-label-custom {
          display: flex;
          align-items: center;
          gap: 5px;
          margin-bottom: 8px;
          color: #344054;
          font-size: 12px;
          font-weight: 700;
        }

        .required {
          color: #dc3545;
        }

        .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);
        }

        .help-text {
          margin-top: 6px;
          color: #98a1ae;
          font-size: 10px;
          line-height: 1.55;
          text-align: justify;
          text-justify: inter-word;
        }

        code {
          color: #198754;
          background: #f0f8f4;
          padding: 2px 5px;
          border-radius: 4px;
        }

        /* ========================================
           ICON PREVIEW
        ======================================== */

        .icon-preview {
          margin-top: 13px;
          padding: 14px;
          border: 1px solid #edf0f3;
          border-radius: 12px;
          background: #fafcfb;
          display: flex;
          align-items: center;
          gap: 12px;
        }

        .icon-preview-box {
          width: 48px;
          height: 48px;
          border-radius: 12px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #eaf7f0;
          color: #198754;
          font-size: 21px;
          flex-shrink: 0;
        }

        .icon-preview-text {
          min-width: 0;
        }

        .icon-preview-label {
          color: #344054;
          font-size: 11px;
          font-weight: 700;
        }

        .icon-preview-value {
          margin-top: 2px;
          color: #98a1ae;
          font-size: 10px;
          word-break: break-word;
        }

        /* ========================================
           PREVIEW STAT
        ======================================== */

        .stat-preview {
          margin-top: 24px;
          padding: 20px;
          border: 1px dashed #cfe4d8;
          border-radius: 14px;
          background: #f8fcfa;
        }

        .stat-preview-label {
          color: #8a93a0;
          font-size: 10px;
          font-weight: 700;
          letter-spacing: 0.08em;
          text-transform: uppercase;
          margin-bottom: 12px;
        }

        .stat-preview-card {
          display: flex;
          align-items: center;
          gap: 14px;
        }

        .stat-preview-icon {
          width: 52px;
          height: 52px;
          border-radius: 14px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #eaf7f0;
          color: #198754;
          font-size: 21px;
          flex-shrink: 0;
        }

        .stat-preview-value {
          color: #17202a;
          font-size: 23px;
          font-weight: 800;
          line-height: 1.1;
        }

        .stat-preview-name {
          margin-top: 4px;
          color: #7a8493;
          font-size: 11px;
        }

        /* ========================================
           SWITCH
        ======================================== */

        .status-box {
          padding: 16px;
          border: 1px solid #edf0f3;
          border-radius: 12px;
          background: #fafbfc;
        }

        .status-row {
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
        }

        .status-info {
          display: flex;
          align-items: center;
          gap: 11px;
          min-width: 0;
        }

        .status-icon {
          width: 40px;
          height: 40px;
          border-radius: 10px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #eaf7f0;
          color: #198754;
          flex-shrink: 0;
        }

        .status-title {
          color: #344054;
          font-size: 12px;
          font-weight: 700;
        }

        .status-description {
          margin-top: 3px;
          color: #98a1ae;
          font-size: 10px;
          line-height: 1.5;
        }

        .custom-switch {
          width: 46px;
          height: 24px;
          position: relative;
          flex-shrink: 0;
        }

        .custom-switch input {
          opacity: 0;
          width: 0;
          height: 0;
        }

        .switch-slider {
          position: absolute;
          cursor: pointer;
          inset: 0;
          border-radius: 30px;
          background: #cbd2d9;
          transition: 0.25s ease;
        }

        .switch-slider::before {
          content: "";
          position: absolute;
          width: 18px;
          height: 18px;
          left: 3px;
          top: 3px;
          background: #ffffff;
          border-radius: 50%;
          box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
          transition: 0.25s ease;
        }

        .custom-switch input:checked + .switch-slider {
          background: #198754;
        }

        .custom-switch input:checked + .switch-slider::before {
          transform: translateX(22px);
        }

        /* ========================================
           FORM FOOTER
        ======================================== */

        .form-footer {
          margin-top: 30px;
          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: 410px;
          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;
          justify-content: flex-end;
          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;
        }

        /* ========================================
           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;
        }

        /* ========================================
           TABLET
        ======================================== */

        @media (max-width: 1199.98px) {
          .admin-content {
            padding: 28px;
          }

          .page-heading,
          .form-wrapper,
          .admin-page-footer {
            max-width: 950px;
          }
        }

        /* ========================================
           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;
          }
        }

        /* ========================================
           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 {
            border-radius: 15px;
          }

          .form-card-header {
            padding: 19px;
            align-items: flex-start;
          }

          .form-header-title {
            font-size: 15px;
          }

          .form-header-description {
            font-size: 11px;
          }

          .new-record {
            font-size: 9px;
            padding: 6px 8px;
          }

          .new-record span:last-child {
            display: none;
          }

          .form-card-body {
            padding: 20px 18px;
          }

          .form-inner {
            max-width: 100%;
          }

          .form-section {
            margin-bottom: 25px;
          }

          .status-row {
            align-items: flex-start;
          }

          .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-icon {
            width: 43px;
            height: 43px;
            border-radius: 11px;
            font-size: 17px;
          }

          .page-title {
            font-size: 23px;
          }

          .page-description {
            font-size: 11px;
          }

          .form-card-header {
            padding: 17px;
          }

          .form-header-icon {
            width: 39px;
            height: 39px;
            border-radius: 10px;
            font-size: 16px;
          }

          .form-header-title {
            font-size: 14px;
          }

          .form-header-description {
            font-size: 10px;
          }

          .form-card-body {
            padding: 18px 15px;
          }

          .section-heading {
            margin-bottom: 15px;
          }

          .section-title {
            font-size: 12px;
          }

          .form-label-custom {
            font-size: 11px;
          }

          .form-control-custom {
            min-height: 44px;
            font-size: 12px;
            padding: 9px 11px;
          }

          .stat-preview {
            padding: 15px;
          }

          .stat-preview-icon {
            width: 45px;
            height: 45px;
            border-radius: 12px;
          }

          .stat-preview-value {
            font-size: 20px;
          }

          .form-actions {
            grid-template-columns: 1fr;
          }

          .cancel-button,
          .save-button {
            min-height: 42px;
          }

          .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 {
            border-radius: 13px;
          }

          .form-card-body {
            padding: 16px 13px;
          }
        }

        /* ========================================
           REDUCED MOTION
        ======================================== */

        @media (prefers-reduced-motion: reduce) {
          .stats-create-admin *,
          .stats-create-admin *::before,
          .stats-create-admin *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
          }
        }
      `}</style>

      <div className="stats-create-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>

                {/* ABOUT 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 AREA
          ====================================== */}

          <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">
                    Create About Statistic
                  </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 About 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">
                      Add Statistic
                    </h1>

                    <p className="page-description">
                      Tambahkan statistik baru yang akan
                      ditampilkan pada bagian About Me.
                      Kelola label, nilai, icon, urutan,
                      dan status statistik secara terstruktur
                      melalui halaman administrasi GloVaTech.
                    </p>

                  </div>

                </div>

              </section>

              {/* FORM */}

              <section className="form-wrapper">

                <div className="form-card">

                  {/* CARD HEADER */}

                  <div className="form-card-header">

                    <div className="form-header-left">

                      <div className="form-header-icon">
                        <i className="bi bi-pencil-square"></i>
                      </div>

                      <div>

                        <h2 className="form-header-title">
                          Statistic Information
                        </h2>

                        <p className="form-header-description">
                          Masukkan informasi statistik yang
                          ingin ditampilkan pada halaman
                          About Me.
                        </p>

                      </div>

                    </div>

                    <div className="new-record">
                      <span className="new-record-dot"></span>
                      <span>New Record</span>
                    </div>

                  </div>

                  {/* CARD BODY */}

                  <div className="form-card-body">

                    <form
                      onSubmit={handleSubmit}
                      className="form-inner"
                    >

                      {/* ==================================
                          BASIC INFORMATION
                      ================================== */}

                      <section className="form-section">

                        <div className="section-heading">

                          <div className="section-number">
                            01
                          </div>

                          <div>

                            <h3 className="section-title">
                              Basic Information
                            </h3>

                            <p className="section-description">
                              Tentukan nama dan nilai statistik
                              yang akan ditampilkan.
                            </p>

                          </div>

                        </div>

                        {/* LABEL */}

                        <div className="form-group">

                          <label
                            htmlFor="label"
                            className="form-label-custom"
                          >
                            Statistic Label

                            <span className="required">
                              *
                            </span>
                          </label>

                          <input
                            type="text"
                            id="label"
                            name="label"
                            className="form-control-custom"
                            placeholder="Contoh: Projects Completed"
                            value={form.label}
                            onChange={handleChange}
                            required
                          />

                          <div className="help-text">
                            Nama atau keterangan statistik
                            yang akan terlihat oleh pengunjung.
                          </div>

                        </div>

                        {/* VALUE */}

                        <div className="form-group">

                          <label
                            htmlFor="value"
                            className="form-label-custom"
                          >
                            Statistic Value

                            <span className="required">
                              *
                            </span>
                          </label>

                          <input
                            type="text"
                            id="value"
                            name="value"
                            className="form-control-custom"
                            placeholder="Contoh: 10+"
                            value={form.value}
                            onChange={handleChange}
                            required
                          />

                          <div className="help-text">
                            Nilai statistik, misalnya
                            <strong> 10+</strong>,
                            <strong> 5+</strong>, atau
                            <strong> 3 Years</strong>.
                          </div>

                        </div>

                      </section>

                      {/* ==================================
                          ICON
                      ================================== */}

                      <section className="form-section">

                        <div className="section-heading">

                          <div className="section-number">
                            02
                          </div>

                          <div>

                            <h3 className="section-title">
                              Visual Identity
                            </h3>

                            <p className="section-description">
                              Tambahkan Bootstrap Icon sebagai
                              identitas visual statistik.
                            </p>

                          </div>

                        </div>

                        <div className="form-group">

                          <label
                            htmlFor="icon"
                            className="form-label-custom"
                          >
                            Bootstrap Icon
                          </label>

                          <input
                            type="text"
                            id="icon"
                            name="icon"
                            className="form-control-custom"
                            placeholder="Contoh: bi bi-folder-check"
                            value={form.icon}
                            onChange={handleChange}
                          />

                          <div className="help-text">
                            Gunakan class dari Bootstrap Icons.
                            Contoh:
                            <code className="ms-1">
                              bi bi-folder-check
                            </code>
                          </div>

                          {form.icon && (
                            <div className="icon-preview">

                              <div className="icon-preview-box">
                                <i
                                  className={form.icon}
                                ></i>
                              </div>

                              <div className="icon-preview-text">

                                <div className="icon-preview-label">
                                  Icon Preview
                                </div>

                                <div className="icon-preview-value">
                                  {form.icon}
                                </div>

                              </div>

                            </div>
                          )}

                        </div>

                      </section>

                      {/* ==================================
                          DISPLAY SETTINGS
                      ================================== */}

                      <section className="form-section">

                        <div className="section-heading">

                          <div className="section-number">
                            03
                          </div>

                          <div>

                            <h3 className="section-title">
                              Display Settings
                            </h3>

                            <p className="section-description">
                              Atur posisi dan status tampilan
                              statistik pada website.
                            </p>

                          </div>

                        </div>

                        {/* SORT ORDER */}

                        <div className="form-group">

                          <label
                            htmlFor="sortOrder"
                            className="form-label-custom"
                          >
                            Display Order

                            <span className="required">
                              *
                            </span>
                          </label>

                          <input
                            type="number"
                            id="sortOrder"
                            name="sortOrder"
                            className="form-control-custom"
                            min="1"
                            value={form.sortOrder}
                            onChange={handleChange}
                            required
                          />

                          <div className="help-text">
                            Menentukan posisi statistik pada
                            bagian About. Angka yang lebih kecil
                            akan ditampilkan lebih dahulu.
                          </div>

                        </div>

                        {/* ACTIVE */}

                        <div className="form-group">

                          <div className="status-box">

                            <div className="status-row">

                              <div className="status-info">

                                <div className="status-icon">
                                  <i className="bi bi-eye-fill"></i>
                                </div>

                                <div>

                                  <div className="status-title">
                                    Statistic Active
                                  </div>

                                  <div className="status-description">
                                    Jika aktif, statistik akan
                                    ditampilkan pada website.
                                  </div>

                                </div>

                              </div>

                              <label className="custom-switch">
                                <input
                                  type="checkbox"
                                  id="active"
                                  name="active"
                                  checked={form.active}
                                  onChange={handleChange}
                                />

                                <span className="switch-slider"></span>
                              </label>

                            </div>

                          </div>

                        </div>

                      </section>

                      {/* ==================================
                          LIVE PREVIEW
                      ================================== */}

                      {(form.label || form.value || form.icon) && (
                        <section className="form-section">

                          <div className="stat-preview">

                            <div className="stat-preview-label">
                              Live Preview
                            </div>

                            <div className="stat-preview-card">

                              <div className="stat-preview-icon">

                                {form.icon ? (
                                  <i className={form.icon}></i>
                                ) : (
                                  <i className="bi bi-bar-chart-fill"></i>
                                )}

                              </div>

                              <div>

                                <div className="stat-preview-value">
                                  {form.value || "0"}
                                </div>

                                <div className="stat-preview-name">
                                  {form.label || "Statistic Label"}
                                </div>

                              </div>

                            </div>

                          </div>

                        </section>
                      )}

                      {/* ==================================
                          FORM FOOTER
                      ================================== */}

                      <div className="form-footer">

                        <div className="footer-note">

                          <i className="bi bi-shield-check"></i>

                          <span>
                            Data akan disimpan melalui sistem
                            About Statistics Management yang
                            sudah tersedia. Backend dan API
                            tidak mengalami perubahan.
                          </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={loading}
                          >

                            {loading ? (
                              <>
                                <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 Statistik
                              </>
                            )}

                          </button>

                        </div>

                      </div>

                    </form>

                  </div>

                </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>
    </>
  );
}

