"use client";

import { FormEvent, useState } from "react";
import Link from "next/link";
import { useRouter } from "next/navigation";

export default function CreateServicePage() {
  const router = useRouter();

  const [title, setTitle] = useState("");
  const [slug, setSlug] = useState("");
  const [description, setDescription] = useState("");
  const [icon, setIcon] = useState("");
  const [image, setImage] = useState("");
  const [featured, setFeatured] = useState(false);
  const [active, setActive] = useState(true);

  const [loading, setLoading] = useState(false);
  const [sidebarOpen, setSidebarOpen] = useState(false);

  const generateSlug = (value: string) => {
    return value
      .toLowerCase()
      .trim()
      .replace(/[^a-z0-9\s-]/g, "")
      .replace(/\s+/g, "-")
      .replace(/-+/g, "-");
  };

  const handleTitleChange = (value: string) => {
    setTitle(value);
    setSlug(generateSlug(value));
  };

  const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
    event.preventDefault();

    if (!title.trim()) {
      alert("Title wajib diisi.");
      return;
    }

    if (!slug.trim()) {
      alert("Slug wajib diisi.");
      return;
    }

    setLoading(true);

    try {
      const response = await fetch("/api/services", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          title,
          slug,
          description: description || null,
          icon: icon || null,
          image: image || null,
          featured,
          active,
        }),
      });

      const result = await response.json();

      if (result.success) {
        alert("Service berhasil ditambahkan.");

        router.push("/secure-panel/services");
        router.refresh();
      } else {
        alert(
          result.message || "Gagal menambahkan Service."
        );
      }
    } catch (error) {
      console.error("CREATE SERVICE:", error);

      alert(
        "Terjadi kesalahan saat menyimpan Service."
      );
    } finally {
      setLoading(false);
    }
  };

  return (
    <>
      <style>{`
        * {
          box-sizing: border-box;
        }

        .admin-layout {
          min-height: 100vh;
          background: #f5f7f9;
          color: #1f2937;
        }

        /* =========================
           SIDEBAR
        ========================= */

        .admin-sidebar {
          position: fixed;
          top: 0;
          left: 0;
          width: 260px;
          height: 100vh;
          background: #ffffff;
          border-right: 1px solid #e9ecef;
          z-index: 1050;
          transition: transform 0.3s ease;
          overflow-y: auto;
        }

        .sidebar-inner {
          min-height: 100%;
          display: flex;
          flex-direction: column;
          padding: 22px 16px;
        }

        .sidebar-brand {
          display: flex;
          align-items: center;
          gap: 12px;
          padding: 4px 8px 24px;
          border-bottom: 1px solid #eef0f2;
        }

        .brand-icon {
          width: 42px;
          height: 42px;
          border-radius: 12px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #198754;
          color: #ffffff;
          font-size: 19px;
          box-shadow: 0 8px 20px rgba(25, 135, 84, 0.18);
          flex-shrink: 0;
        }

        .brand-text {
          min-width: 0;
          line-height: 1.15;
        }

        .brand-text strong {
          display: block;
          font-size: 15px;
          font-weight: 700;
          color: #17202a;
        }

        .brand-text span {
          display: block;
          margin-top: 4px;
          font-size: 11px;
          color: #8a94a6;
          letter-spacing: 0.4px;
        }

        .sidebar-close {
          margin-left: auto;
          border: 0;
          background: transparent;
          color: #6c757d;
          font-size: 18px;
        }

        .sidebar-section-label {
          padding: 20px 10px 8px;
          font-size: 10px;
          font-weight: 700;
          color: #a0a8b3;
          letter-spacing: 1.1px;
        }

        .sidebar-nav {
          display: flex;
          flex-direction: column;
          gap: 3px;
        }

        .sidebar-link {
          display: flex;
          align-items: center;
          gap: 12px;
          min-height: 44px;
          padding: 9px 12px;
          border-radius: 10px;
          color: #667085;
          text-decoration: none;
          font-size: 13px;
          font-weight: 500;
          transition:
            background 0.2s ease,
            color 0.2s ease,
            transform 0.2s ease;
        }

        .sidebar-link:hover {
          background: #f0f9f4;
          color: #198754;
          transform: translateX(2px);
        }

        .sidebar-link.active {
          background: #e9f7ef;
          color: #198754;
          font-weight: 600;
        }

        .sidebar-link-icon {
          width: 20px;
          display: flex;
          justify-content: center;
          font-size: 16px;
          flex-shrink: 0;
        }

        .sidebar-bottom {
          margin-top: auto;
          padding-top: 20px;
          border-top: 1px solid #eef0f2;
        }

        .sidebar-website {
          display: flex;
          align-items: center;
          gap: 10px;
          padding: 11px 12px;
          border-radius: 10px;
          color: #667085;
          text-decoration: none;
          font-size: 13px;
          transition: all 0.2s ease;
        }

        .sidebar-website:hover {
          background: #f5f7f9;
          color: #198754;
        }

        /* =========================
           MAIN
        ========================= */

        .admin-main {
          margin-left: 260px;
          min-height: 100vh;
          width: calc(100% - 260px);
        }

        /* =========================
           TOPBAR
        ========================= */

        .admin-topbar {
          height: 76px;
          background: rgba(255, 255, 255, 0.96);
          border-bottom: 1px solid #e9ecef;
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 0 32px;
          position: sticky;
          top: 0;
          z-index: 1000;
          backdrop-filter: blur(12px);
        }

        .topbar-left,
        .topbar-right {
          display: flex;
          align-items: center;
        }

        .topbar-left {
          gap: 14px;
        }

        .topbar-right {
          gap: 10px;
        }

        .mobile-menu-button {
          width: 40px;
          height: 40px;
          border: 1px solid #e5e7eb;
          background: #ffffff;
          color: #475467;
          border-radius: 9px;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 20px;
        }

        .topbar-label {
          font-size: 10px;
          font-weight: 700;
          color: #98a2b3;
          letter-spacing: 1px;
          margin-bottom: 2px;
        }

        .topbar-title {
          font-size: 15px;
          font-weight: 700;
          color: #1d2939;
        }

        .topbar-website,
        .topbar-logout {
          min-height: 40px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
          padding: 8px 13px;
          border-radius: 9px;
          text-decoration: none;
          font-size: 13px;
          font-weight: 600;
          transition: all 0.2s ease;
          white-space: nowrap;
        }

        .topbar-website {
          color: #475467;
          border: 1px solid #e4e7ec;
          background: #ffffff;
        }

        .topbar-website:hover {
          color: #198754;
          border-color: #b7dfc9;
          background: #f4fbf7;
        }

        .topbar-logout {
          color: #dc3545;
          background: #fff5f5;
          border: 1px solid #ffd6d9;
        }

        .topbar-logout:hover {
          background: #dc3545;
          border-color: #dc3545;
          color: #ffffff;
        }

        /* =========================
           CONTENT
        ========================= */

        .admin-content {
          padding: 32px;
          max-width: 1600px;
          margin: 0 auto;
        }

        .page-heading {
          display: flex;
          align-items: flex-end;
          justify-content: space-between;
          gap: 25px;
          margin-bottom: 28px;
        }

        .page-heading-left {
          min-width: 0;
        }

        .back-dashboard {
          display: inline-flex;
          align-items: center;
          gap: 7px;
          color: #667085;
          text-decoration: none;
          font-size: 12px;
          font-weight: 600;
          margin-bottom: 17px;
          transition: color 0.2s ease;
        }

        .back-dashboard:hover {
          color: #198754;
        }

        .page-title-row {
          display: flex;
          align-items: center;
          gap: 14px;
        }

        .page-title-icon {
          width: 48px;
          height: 48px;
          border-radius: 13px;
          background: #e9f7ef;
          color: #198754;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 21px;
          flex-shrink: 0;
        }

        .page-eyebrow {
          color: #198754;
          font-size: 10px;
          font-weight: 700;
          letter-spacing: 1.2px;
          margin-bottom: 4px;
        }

        .page-title {
          margin: 0;
          font-size: clamp(24px, 3vw, 32px);
          line-height: 1.15;
          font-weight: 750;
          color: #101828;
        }

        .page-description {
          margin: 7px 0 0;
          color: #667085;
          font-size: 13px;
          line-height: 1.7;
          max-width: 720px;
          text-align: justify;
        }

        /* =========================
           FORM CARD
        ========================= */

        .form-card {
          background: #ffffff;
          border: 1px solid #eaecf0;
          border-radius: 16px;
          overflow: hidden;
          box-shadow: 0 3px 12px rgba(16, 24, 40, 0.035);
        }

        .form-card-header {
          padding: 21px 24px;
          border-bottom: 1px solid #eaecf0;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 20px;
        }

        .form-card-eyebrow {
          font-size: 10px;
          font-weight: 700;
          color: #198754;
          letter-spacing: 1px;
          margin-bottom: 4px;
        }

        .form-card-title {
          margin: 0;
          color: #101828;
          font-size: 17px;
          font-weight: 750;
        }

        .form-card-description {
          margin: 5px 0 0;
          color: #667085;
          font-size: 12px;
          line-height: 1.7;
          text-align: justify;
          max-width: 700px;
        }

        .form-card-icon {
          width: 40px;
          height: 40px;
          border-radius: 10px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #f5f7f9;
          color: #198754;
          font-size: 17px;
          flex-shrink: 0;
        }

        .form-body {
          padding: 24px;
        }

        .form-grid {
          display: grid;
          grid-template-columns: repeat(2, minmax(0, 1fr));
          gap: 20px;
        }

        .form-group {
          min-width: 0;
        }

        .form-group-full {
          grid-column: 1 / -1;
        }

        .form-label-custom {
          display: block;
          margin-bottom: 7px;
          color: #344054;
          font-size: 12px;
          font-weight: 700;
        }

        .required-mark {
          color: #dc3545;
          margin-left: 3px;
        }

        .form-control-custom {
          width: 100%;
          min-height: 43px;
          padding: 10px 12px;
          border: 1px solid #d0d5dd;
          border-radius: 9px;
          background: #ffffff;
          color: #344054;
          font-size: 13px;
          outline: none;
          transition:
            border-color 0.2s ease,
            box-shadow 0.2s ease;
        }

        .form-control-custom::placeholder {
          color: #98a2b3;
        }

        .form-control-custom:focus {
          border-color: #198754;
          box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.1);
        }

        textarea.form-control-custom {
          min-height: 135px;
          resize: vertical;
          line-height: 1.7;
          text-align: justify;
        }

        .form-help {
          margin-top: 6px;
          color: #98a2b3;
          font-size: 10px;
          line-height: 1.6;
        }

        .form-help code {
          color: #198754;
          background: #f0f9f4;
          padding: 2px 5px;
          border-radius: 4px;
          font-size: 10px;
        }

        /* =========================
           URL PREVIEW
        ========================= */

        .image-preview {
          margin-top: 10px;
          border: 1px solid #eaecf0;
          border-radius: 10px;
          overflow: hidden;
          background: #f8faf9;
        }

        .image-preview img {
          width: 100%;
          max-height: 230px;
          display: block;
          object-fit: cover;
        }

        /* =========================
           CHECKBOXES
        ========================= */

        .options-section {
          margin-top: 22px;
          padding: 18px;
          border: 1px solid #eaecf0;
          border-radius: 12px;
          background: #fafbfc;
        }

        .options-title {
          margin: 0 0 12px;
          color: #344054;
          font-size: 12px;
          font-weight: 700;
        }

        .options-grid {
          display: grid;
          grid-template-columns: repeat(2, minmax(0, 1fr));
          gap: 12px;
        }

        .option-card {
          display: flex;
          align-items: flex-start;
          gap: 10px;
          padding: 13px;
          border: 1px solid #e4e7ec;
          border-radius: 10px;
          background: #ffffff;
          cursor: pointer;
          transition: all 0.2s ease;
        }

        .option-card:hover {
          border-color: #b7dfc9;
          background: #fcfffd;
        }

        .option-card input {
          width: 16px;
          height: 16px;
          margin-top: 2px;
          accent-color: #198754;
          flex-shrink: 0;
        }

        .option-content {
          min-width: 0;
        }

        .option-label {
          display: block;
          color: #344054;
          font-size: 12px;
          font-weight: 700;
        }

        .option-description {
          display: block;
          margin-top: 3px;
          color: #98a2b3;
          font-size: 10px;
          line-height: 1.6;
          text-align: justify;
        }

        /* =========================
           FORM ACTIONS
        ========================= */

        .form-actions {
          display: flex;
          align-items: center;
          justify-content: flex-end;
          gap: 9px;
          margin-top: 24px;
          padding-top: 20px;
          border-top: 1px solid #eaecf0;
        }

        .form-button {
          min-height: 42px;
          padding: 9px 15px;
          border-radius: 9px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 7px;
          font-size: 12px;
          font-weight: 600;
          cursor: pointer;
          transition: all 0.2s ease;
        }

        .save-button {
          border: 1px solid #198754;
          background: #198754;
          color: #ffffff;
          box-shadow: 0 6px 15px rgba(25, 135, 84, 0.14);
        }

        .save-button:hover {
          background: #157347;
          border-color: #157347;
          transform: translateY(-1px);
          box-shadow: 0 9px 20px rgba(25, 135, 84, 0.18);
        }

        .save-button:disabled {
          opacity: 0.7;
          cursor: not-allowed;
          transform: none;
        }

        .cancel-button {
          border: 1px solid #d0d5dd;
          background: #ffffff;
          color: #475467;
        }

        .cancel-button:hover {
          background: #f5f7f9;
          border-color: #bfc5ce;
          color: #344054;
        }

        .cancel-button:disabled {
          opacity: 0.6;
          cursor: not-allowed;
        }

        /* =========================
           FOOTER
        ========================= */

        .admin-page-footer {
          padding: 22px 2px 8px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
          color: #98a2b3;
          font-size: 11px;
        }

        .admin-page-footer-left {
          display: flex;
          align-items: center;
          gap: 7px;
        }

        .admin-page-footer a {
          color: #667085;
          text-decoration: none;
          font-weight: 600;
        }

        .admin-page-footer a:hover {
          color: #198754;
        }

        /* =========================
           OVERLAY
        ========================= */

        .sidebar-overlay {
          display: none;
          position: fixed;
          inset: 0;
          background: rgba(15, 23, 42, 0.38);
          z-index: 1040;
          backdrop-filter: blur(2px);
        }

        /* =========================
           RESPONSIVE TABLET
        ========================= */

        @media (max-width: 991.98px) {
          .admin-sidebar {
            transform: translateX(-100%);
            box-shadow: 12px 0 30px rgba(15, 23, 42, 0.1);
          }

          .admin-sidebar.sidebar-open {
            transform: translateX(0);
          }

          .sidebar-overlay.sidebar-overlay-show {
            display: block;
          }

          .admin-main {
            width: 100%;
            margin-left: 0;
          }

          .admin-topbar {
            padding: 0 20px;
          }

          .admin-content {
            padding: 25px 20px;
          }

          .page-heading {
            align-items: flex-start;
            flex-direction: column;
          }

          .form-grid {
            grid-template-columns: 1fr;
          }

          .form-group-full {
            grid-column: auto;
          }

          .page-heading-action {
            width: 100%;
          }
        }

        @media (max-width: 767.98px) {
          .options-grid {
            grid-template-columns: 1fr;
          }

          .form-actions {
            flex-direction: column-reverse;
          }

          .form-button {
            width: 100%;
          }
        }

        /* =========================
           RESPONSIVE MOBILE
        ========================= */

        @media (max-width: 575.98px) {
          .admin-topbar {
            height: 68px;
            padding: 0 14px;
          }

          .topbar-left {
            gap: 9px;
            min-width: 0;
          }

          .topbar-right {
            gap: 6px;
          }

          .topbar-website,
          .topbar-logout {
            width: 38px;
            height: 38px;
            min-height: 38px;
            padding: 0;
          }

          .topbar-website span,
          .topbar-logout span {
            display: none !important;
          }

          .topbar-title {
            font-size: 13px;
          }

          .admin-content {
            padding: 20px 14px;
          }

          .back-dashboard {
            margin-bottom: 14px;
          }

          .page-title-row {
            align-items: flex-start;
            gap: 11px;
          }

          .page-title-icon {
            width: 43px;
            height: 43px;
            border-radius: 11px;
            font-size: 18px;
          }

          .page-title {
            font-size: 25px;
          }

          .page-description {
            font-size: 12px;
            line-height: 1.65;
          }

          .form-card-header {
            padding: 17px;
            gap: 12px;
          }

          .form-card-title {
            font-size: 15px;
          }

          .form-card-description {
            font-size: 11px;
          }

          .form-card-icon {
            width: 36px;
            height: 36px;
            font-size: 15px;
          }

          .form-body {
            padding: 17px;
          }

          .form-grid {
            gap: 17px;
          }

          .form-label-custom {
            font-size: 11px;
          }

          .form-control-custom {
            min-height: 42px;
            font-size: 12px;
          }

          textarea.form-control-custom {
            min-height: 125px;
          }

          .form-help {
            font-size: 9px;
          }

          .options-section {
            padding: 14px;
            margin-top: 18px;
          }

          .option-card {
            padding: 11px;
          }

          .option-label {
            font-size: 11px;
          }

          .option-description {
            font-size: 9px;
          }

          .form-actions {
            margin-top: 20px;
            padding-top: 17px;
          }

          .admin-page-footer {
            flex-direction: column;
            align-items: flex-start;
          }
        }
      `}</style>

      <div className="admin-layout">
        {/* MOBILE OVERLAY */}
        <div
          className={`sidebar-overlay ${
            sidebarOpen ? "sidebar-overlay-show" : ""
          }`}
          onClick={() => setSidebarOpen(false)}
        />

        {/* SIDEBAR */}
        <aside
          className={`admin-sidebar ${
            sidebarOpen ? "sidebar-open" : ""
          }`}
        >
          <div className="sidebar-inner">
            <div className="sidebar-brand">
              <div className="brand-icon">
                <i className="bi bi-grid-1x2-fill"></i>
              </div>

              <div className="brand-text">
                <strong>GloVaTech</strong>
                <span>Admin Panel</span>
              </div>

              <button
                type="button"
                className="sidebar-close d-lg-none"
                onClick={() => setSidebarOpen(false)}
                aria-label="Tutup sidebar"
              >
                <i className="bi bi-x-lg"></i>
              </button>
            </div>

            <div className="sidebar-section-label">
              MAIN MENU
            </div>

            <nav className="sidebar-nav">
              <Link
                href="/secure-panel"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-speedometer2"></i>
                </span>
                <span>Dashboard</span>
              </Link>
            </nav>

            <div className="sidebar-section-label">
              CONTENT
            </div>

            <nav className="sidebar-nav">
              <Link
                href="/secure-panel/hero"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-stars"></i>
                </span>
                <span>Hero</span>
              </Link>

              <Link
                href="/secure-panel/about"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-person-vcard"></i>
                </span>
                <span>About</span>
              </Link>

              <Link
                href="/secure-panel/about/stats"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-bar-chart"></i>
                </span>
                <span>About Stats</span>
              </Link>

              <Link
                href="/secure-panel/education"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-mortarboard"></i>
                </span>
                <span>Education</span>
              </Link>

              <Link
                href="/secure-panel/skills"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-tools"></i>
                </span>
                <span>Skills</span>
              </Link>

              <Link
                href="/secure-panel/experience"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-briefcase"></i>
                </span>
                <span>Experience</span>
              </Link>

              <Link
                href="/secure-panel/projects"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-code-square"></i>
                </span>
                <span>Projects</span>
              </Link>

              <Link
                href="/secure-panel/certifications"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-patch-check"></i>
                </span>
                <span>Certification</span>
              </Link>

              <Link
                href="/secure-panel/achievements"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-trophy"></i>
                </span>
                <span>Achievement</span>
              </Link>

              <Link
                href="/secure-panel/services"
                className="sidebar-link active"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-gear-wide-connected"></i>
                </span>
                <span>Services</span>
              </Link>

              <Link
                href="/secure-panel/gallery"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-images"></i>
                </span>
                <span>Gallery</span>
              </Link>

              <Link
                href="/secure-panel/contact-info"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-person-lines-fill"></i>
                </span>
                <span>Contact</span>
              </Link>

              <Link
                href="/secure-panel/contact-info/list"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-share-fill"></i>
                </span>
                <span>Contact Social Media</span>
              </Link>

              <Link
                href="/secure-panel/articles"
                className="sidebar-link"
                onClick={() => setSidebarOpen(false)}
              >
                <span className="sidebar-link-icon">
                  <i className="bi bi-journal-text"></i>
                </span>
                <span>Articles</span>
              </Link>

              <Link
  href="/secure-panel/contact-messages"
  className="sidebar-link"
  onClick={() => setSidebarOpen(false)}
>
  <span className="sidebar-link-icon">
    <i className="bi bi-chat-left-text"></i>
  </span>
  <span>Contact Messages</span>
</Link>

<Link
  href="/secure-panel/contact-users"
  className="sidebar-link"
  onClick={() => setSidebarOpen(false)}
>
  <span className="sidebar-link-icon">
    <i className="bi bi-people-fill"></i>
  </span>
  <span>Contact User</span>
</Link>
            </nav>

            <div className="sidebar-bottom">
              <Link
                href="/"
                className="sidebar-website"
              >
                <i className="bi bi-globe2"></i>
                <span>View Website</span>
                <i className="bi bi-arrow-up-right ms-auto"></i>
              </Link>
            </div>
          </div>
        </aside>

        {/* MAIN */}
        <div className="admin-main">
          {/* TOPBAR */}
          <header className="admin-topbar">
            <div className="topbar-left">
              <button
                type="button"
                className="mobile-menu-button d-lg-none"
                onClick={() => setSidebarOpen(true)}
                aria-label="Buka menu"
              >
                <i className="bi bi-list"></i>
              </button>

              <div>
                <div className="topbar-label">
                  ADMIN PANEL
                </div>

                <h6 className="topbar-title mb-0">
                  Services Management
                </h6>
              </div>
            </div>

            <div className="topbar-right">
              <Link
                href="/"
                className="topbar-website"
                title="Lihat Website"
              >
                <i className="bi bi-globe2"></i>
                <span>Website</span>
              </Link>

              <Link
                href="/secure-panel/login"
                className="topbar-logout"
                title="Logout"
              >
                <i className="bi bi-box-arrow-right"></i>
                <span>Logout</span>
              </Link>
            </div>
          </header>

          {/* CONTENT */}
          <main className="admin-content">
            {/* PAGE HEADING */}
            <section className="page-heading">
              <div className="page-heading-left">
                <Link
                  href="/secure-panel/services"
                  className="back-dashboard"
                >
                  <i className="bi bi-arrow-left"></i>
                  <span>Kembali ke Services</span>
                </Link>

                <div className="page-title-row">
                  <div className="page-title-icon">
                    <i className="bi bi-gear-wide-connected"></i>
                  </div>

                  <div>
                    <div className="page-eyebrow">
                      WEBSITE CONTENT
                    </div>

                    <h1 className="page-title">
                      Tambah Service
                    </h1>

                    <p className="page-description">
                      Tambahkan layanan baru yang akan ditampilkan
                      pada section Services di website portfolio
                      GloVaTech. Lengkapi informasi layanan, icon,
                      gambar, dan status publikasinya.
                    </p>
                  </div>
                </div>
              </div>
            </section>

            {/* FORM */}
            <section className="form-card">
              <div className="form-card-header">
                <div>
                  <div className="form-card-eyebrow">
                    SERVICE INFORMATION
                  </div>

                  <h2 className="form-card-title">
                    Informasi Service
                  </h2>

                  <p className="form-card-description">
                    Masukkan informasi utama service yang ingin
                    ditampilkan pada website. Field bertanda
                    <strong> *</strong> wajib diisi.
                  </p>
                </div>

                <div className="form-card-icon">
                  <i className="bi bi-file-earmark-plus"></i>
                </div>
              </div>

              <form
                onSubmit={handleSubmit}
                className="form-body"
              >
                <div className="form-grid">
                  {/* TITLE */}
                  <div className="form-group">
                    <label
                      htmlFor="title"
                      className="form-label-custom"
                    >
                      Title
                      <span className="required-mark">*</span>
                    </label>

                    <input
                      id="title"
                      type="text"
                      className="form-control-custom"
                      value={title}
                      onChange={(event) =>
                        handleTitleChange(
                          event.target.value
                        )
                      }
                      placeholder="Contoh: Web Development"
                      autoComplete="off"
                    />
                  </div>

                  {/* SLUG */}
                  <div className="form-group">
                    <label
                      htmlFor="slug"
                      className="form-label-custom"
                    >
                      Slug
                      <span className="required-mark">*</span>
                    </label>

                    <input
                      id="slug"
                      type="text"
                      className="form-control-custom"
                      value={slug}
                      onChange={(event) =>
                        setSlug(
                          generateSlug(
                            event.target.value
                          )
                        )
                      }
                      placeholder="web-development"
                      autoComplete="off"
                    />

                    <div className="form-help">
                      Slug dibuat otomatis dari Title dan
                      digunakan sebagai identitas URL.
                    </div>
                  </div>

                  {/* DESCRIPTION */}
                  <div className="form-group form-group-full">
                    <label
                      htmlFor="description"
                      className="form-label-custom"
                    >
                      Description
                    </label>

                    <textarea
                      id="description"
                      className="form-control-custom"
                      rows={6}
                      value={description}
                      onChange={(event) =>
                        setDescription(
                          event.target.value
                        )
                      }
                      placeholder="Jelaskan layanan yang ditawarkan..."
                    />

                    <div className="form-help">
                      Gunakan deskripsi yang singkat, jelas,
                      informatif, dan mudah dipahami pengunjung.
                    </div>
                  </div>

                  {/* ICON */}
                  <div className="form-group">
                    <label
                      htmlFor="icon"
                      className="form-label-custom"
                    >
                      Icon
                    </label>

                    <input
                      id="icon"
                      type="text"
                      className="form-control-custom"
                      value={icon}
                      onChange={(event) =>
                        setIcon(event.target.value)
                      }
                      placeholder="bi bi-code-slash"
                      autoComplete="off"
                    />

                    <div className="form-help">
                      Gunakan class Bootstrap Icons, contoh{" "}
                      <code>bi bi-code-slash</code>.
                    </div>
                  </div>

                  {/* IMAGE */}
                  <div className="form-group">
                    <label
                      htmlFor="image"
                      className="form-label-custom"
                    >
                      Image URL
                    </label>

                    <input
                      id="image"
                      type="text"
                      className="form-control-custom"
                      value={image}
                      onChange={(event) =>
                        setImage(event.target.value)
                      }
                      placeholder="https://..."
                      autoComplete="off"
                    />

                    <div className="form-help">
                      Masukkan URL gambar jika service memiliki
                      gambar pendukung.
                    </div>

                    {image.trim() && (
                      <div className="image-preview">
                        <img
                          src={image}
                          alt="Preview Service"
                          onError={(event) => {
                            event.currentTarget.style.display =
                              "none";
                          }}
                        />
                      </div>
                    )}
                  </div>
                </div>

                {/* OPTIONS */}
                <div className="options-section">
                  <h3 className="options-title">
                    Publishing Options
                  </h3>

                  <div className="options-grid">
                    {/* FEATURED */}
                    <label
                      htmlFor="featured"
                      className="option-card"
                    >
                      <input
                        id="featured"
                        type="checkbox"
                        checked={featured}
                        onChange={(event) =>
                          setFeatured(
                            event.target.checked
                          )
                        }
                      />

                      <span className="option-content">
                        <span className="option-label">
                          Jadikan Featured
                        </span>

                        <span className="option-description">
                          Tandai service sebagai layanan unggulan
                          yang dapat ditampilkan lebih menonjol
                          pada website.
                        </span>
                      </span>
                    </label>

                    {/* ACTIVE */}
                    <label
                      htmlFor="active"
                      className="option-card"
                    >
                      <input
                        id="active"
                        type="checkbox"
                        checked={active}
                        onChange={(event) =>
                          setActive(
                            event.target.checked
                          )
                        }
                      />

                      <span className="option-content">
                        <span className="option-label">
                          Aktifkan Service
                        </span>

                        <span className="option-description">
                          Service akan berstatus Active dan dapat
                          digunakan pada website.
                        </span>
                      </span>
                    </label>
                  </div>
                </div>

                {/* ACTIONS */}
                <div className="form-actions">
                  <button
                    type="button"
                    className="form-button cancel-button"
                    onClick={() =>
                      router.push(
                        "/secure-panel/services"
                      )
                    }
                    disabled={loading}
                  >
                    <i className="bi bi-x-lg"></i>
                    <span>Batal</span>
                  </button>

                  <button
                    type="submit"
                    className="form-button save-button"
                    disabled={loading}
                  >
                    {loading ? (
                      <>
                        <span
                          className="spinner-border spinner-border-sm"
                          aria-hidden="true"
                        ></span>
                        <span>Menyimpan...</span>
                      </>
                    ) : (
                      <>
                        <i className="bi bi-check-lg"></i>
                        <span>Simpan Service</span>
                      </>
                    )}
                  </button>
                </div>
              </form>
            </section>

            {/* FOOTER */}
            <footer className="admin-page-footer">
              <div className="admin-page-footer-left">
                <i className="bi bi-shield-check"></i>

                <span>
                  Admin Content Management System
                </span>
              </div>

              <Link href="/secure-panel/services">
                <i className="bi bi-arrow-left me-1"></i>
                Services
              </Link>
            </footer>
          </main>
        </div>
      </div>
    </>
  );
}