"use client";

import { FormEvent, useEffect, useState } from "react";
import { useParams, useRouter } from "next/navigation";
import Link from "next/link";

type EducationForm = {
  institution: string;
  degree: string;
  field: string;
  startDate: string;
  endDate: string;
  description: string;
};

export default function EditEducationPage() {
  const params = useParams();
  const router = useRouter();

  const id = params.id as string;

  const [loading, setLoading] = useState(true);
  const [saving, setSaving] = useState(false);
  const [sidebarOpen, setSidebarOpen] = useState(false);

  const [form, setForm] = useState<EducationForm>({
    institution: "",
    degree: "S1",
    field: "",
    startDate: "",
    endDate: "",
    description: "",
  });

  // =========================================================
  // GET EDUCATION
  // =========================================================

  useEffect(() => {
    const getEducation = async () => {
      try {
        setLoading(true);

        const response = await fetch(`/api/education?id=${id}`, {
          cache: "no-store",
        });

        const result = await response.json();

        if (!response.ok || !result.success) {
          alert(result.message || "Failed to load education.");
          router.push("/secure-panel/education");
          return;
        }

        const education = result.data;

        setForm({
          institution: education.institution || "",
          degree: education.degree || "S1",
          field: education.field || "",
          startDate: education.startDate
            ? new Date(education.startDate).getFullYear().toString()
            : "",
          endDate: education.endDate
            ? new Date(education.endDate).getFullYear().toString()
            : "",
          description: education.description || "",
        });
      } catch (error) {
        console.error("GET EDUCATION ERROR:", error);

        alert("Failed to load education.");
        router.push("/secure-panel/education");
      } finally {
        setLoading(false);
      }
    };

    if (id) {
      getEducation();
    }
  }, [id, router]);

  // =========================================================
  // HANDLE CHANGE
  // =========================================================

  const handleChange = (
    e: React.ChangeEvent<
      HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement
    >
  ) => {
    const { name, value } = e.target;

    setForm((prev) => ({
      ...prev,
      [name]: value,
    }));
  };

  // =========================================================
  // HANDLE SUBMIT
  // =========================================================

  const handleSubmit = async (e: FormEvent) => {
    e.preventDefault();

    if (!form.institution.trim()) {
      alert("Institution is required.");
      return;
    }

    if (!form.degree) {
      alert("Education level is required.");
      return;
    }

    if (!form.startDate) {
      alert("Start year is required.");
      return;
    }

    setSaving(true);

    try {
      const response = await fetch("/api/education", {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          id: Number(id),
          institution: form.institution.trim(),
          degree: form.degree,
          field: form.field.trim(),
          startDate: form.startDate,
          endDate: form.endDate || null,
          description: form.description.trim(),
        }),
      });

      const result = await response.json();

      if (!response.ok || !result.success) {
        console.error("UPDATE EDUCATION API ERROR:", result);

        alert(result.message || "Failed to update education.");

        return;
      }

      alert("Education successfully updated.");

      router.push("/secure-panel/education");
    } catch (error) {
      console.error("UPDATE EDUCATION ERROR:", error);

      alert("An error occurred while updating education.");
    } finally {
      setSaving(false);
    }
  };

  // =========================================================
  // CLOSE SIDEBAR
  // =========================================================

  const closeSidebar = () => {
    setSidebarOpen(false);
  };

  // =========================================================
  // LOADING
  // =========================================================

  if (loading) {
    return (
      <>
        <style>{`
          * {
            box-sizing: border-box;
          }

          .education-loading-page {
            min-height: 100vh;
            background: #f5f7fb;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 30px 16px;
          }

          .education-loading-card {
            width: 100%;
            max-width: 430px;
            background: #ffffff;
            border: 1px solid #e8edf2;
            border-radius: 18px;
            padding: 45px 25px;
            text-align: center;
            box-shadow: 0 10px 35px rgba(20, 30, 45, 0.05);
          }

          .loading-spinner {
            width: 44px;
            height: 44px;
            border: 3px solid #dcefe5;
            border-top-color: #198754;
            border-radius: 50%;
            animation: editEducationSpin 0.8s linear infinite;
            margin: 0 auto 18px;
          }

          @keyframes editEducationSpin {
            to {
              transform: rotate(360deg);
            }
          }

          .education-loading-card h5 {
            color: #263241;
            font-weight: 800;
            margin-bottom: 6px;
          }

          .education-loading-card p {
            color: #8a93a0;
            font-size: 13px;
            margin: 0;
          }
        `}</style>

        <main className="education-loading-page">
          <div className="education-loading-card">
            <div className="loading-spinner"></div>

            <h5>Loading Education</h5>

            <p>
              Sedang mengambil data pendidikan dari database...
            </p>
          </div>
        </main>
      </>
    );
  }

  return (
    <>
      <style>{`
        * {
          box-sizing: border-box;
        }

        html,
        body {
          margin: 0;
          padding: 0;
        }

        .education-edit-page {
          min-height: 100vh;
          background: #f5f7fb;
          color: #1f2937;
          overflow-x: hidden;
        }

        /* =====================================================
           LAYOUT
        ===================================================== */

        .edit-admin-layout {
          min-height: 100vh;
          display: flex;
          position: relative;
          width: 100%;
        }

        /* =====================================================
           SIDEBAR
        ===================================================== */

        .edit-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;
        }

        .edit-sidebar-inner {
          height: 100%;
          display: flex;
          flex-direction: column;
          padding: 24px 16px;
          overflow-y: auto;
          overflow-x: hidden;
        }

        .edit-sidebar-brand {
          display: flex;
          align-items: center;
          gap: 12px;
          padding: 4px 10px 28px;
          border-bottom: 1px solid #edf0f4;
          margin-bottom: 22px;
        }

        .edit-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;
        }

        .edit-brand-text {
          min-width: 0;
          flex: 1;
        }

        .edit-brand-text strong {
          display: block;
          font-size: 16px;
          line-height: 1.2;
          color: #17202a;
          white-space: nowrap;
        }

        .edit-brand-text span {
          display: block;
          margin-top: 3px;
          font-size: 11px;
          color: #8b95a5;
          font-weight: 600;
          letter-spacing: 0.08em;
          text-transform: uppercase;
        }

        .edit-sidebar-close {
          margin-left: auto;
          border: 0;
          background: transparent;
          color: #7b8492;
          font-size: 17px;
          padding: 5px;
        }

        .edit-sidebar-section-label {
          padding: 0 12px;
          margin-bottom: 8px;
          color: #9aa3af;
          font-size: 10px;
          font-weight: 700;
          letter-spacing: 0.1em;
        }

        .edit-sidebar-nav {
          display: flex;
          flex-direction: column;
          gap: 4px;
        }

        .edit-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;
          min-width: 0;
        }

        .edit-sidebar-link:hover {
          background: #f0f8f4;
          color: #198754;
          transform: translateX(2px);
        }

        .edit-sidebar-link.active {
          background: linear-gradient(
            90deg,
            rgba(25, 135, 84, 0.12),
            rgba(25, 135, 84, 0.06)
          );
          color: #198754;
          font-weight: 700;
        }

        .edit-sidebar-link-icon {
          width: 23px;
          min-width: 23px;
          text-align: center;
          font-size: 16px;
          flex-shrink: 0;
        }

        .edit-sidebar-link span:last-child {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .edit-sidebar-bottom {
          margin-top: auto;
          padding-top: 18px;
          border-top: 1px solid #edf0f4;
        }

        .edit-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;
        }

        .edit-sidebar-bottom a:hover {
          background: #f5f7fa;
          color: #198754;
        }

        /* =====================================================
           MAIN
        ===================================================== */

        .edit-admin-main {
          width: calc(100% - 270px);
          margin-left: 270px;
          min-width: 0;
          max-width: 100%;
        }

        /* =====================================================
           TOPBAR
        ===================================================== */

        .edit-admin-topbar {
          height: 76px;
          width: 100%;
          background: rgba(255, 255, 255, 0.96);
          border-bottom: 1px solid #e9edf2;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
          padding: 0 34px;
          position: sticky;
          top: 0;
          z-index: 900;
          backdrop-filter: blur(12px);
        }

        .edit-topbar-left {
          display: flex;
          align-items: center;
          gap: 14px;
          min-width: 0;
        }

        .edit-mobile-menu-button {
          width: 40px;
          height: 40px;
          border: 1px solid #e2e7ed;
          background: #ffffff;
          border-radius: 10px;
          color: #344054;
          font-size: 18px;
          flex-shrink: 0;
        }

        .edit-topbar-label {
          color: #9aa3af;
          font-size: 10px;
          font-weight: 700;
          letter-spacing: 0.1em;
          margin-bottom: 3px;
        }

        .edit-topbar-title {
          color: #17202a;
          font-size: 15px;
          font-weight: 700;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }

        .edit-topbar-right {
          display: flex;
          align-items: center;
          gap: 10px;
          flex-shrink: 0;
        }

        .edit-topbar-website,
        .edit-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;
        }

        .edit-topbar-website {
          color: #667085;
          border: 1px solid #e4e8ed;
          background: #ffffff;
        }

        .edit-topbar-website:hover {
          color: #198754;
          border-color: #b7ddca;
          background: #f4fbf7;
        }

        .edit-topbar-logout {
          color: #dc3545;
          border: 1px solid #f1c4c9;
          background: #ffffff;
        }

        .edit-topbar-logout:hover {
          background: #fff5f6;
          border-color: #e8aeb5;
        }

        /* =====================================================
           CONTENT
        ===================================================== */

        .edit-admin-content {
          width: 100%;
          max-width: 1180px;
          margin: 0 auto;
          padding: 34px;
          animation: editContentEnter 0.45s ease both;
        }

        @keyframes editContentEnter {
          from {
            opacity: 0;
            transform: translateY(10px);
          }

          to {
            opacity: 1;
            transform: translateY(0);
          }
        }

        /* =====================================================
           PAGE HEADER
        ===================================================== */

        .edit-page-header {
          margin-bottom: 26px;
        }

        .edit-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;
        }

        .edit-back-link:hover {
          color: #198754;
          transform: translateX(-2px);
        }

        .edit-page-title-row {
          display: flex;
          align-items: flex-start;
          gap: 15px;
          min-width: 0;
        }

        .edit-page-title-icon {
          width: 55px;
          height: 55px;
          min-width: 55px;
          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;
        }

        .edit-page-title-content {
          min-width: 0;
        }

        .edit-page-eyebrow {
          color: #198754;
          font-size: 10px;
          font-weight: 800;
          letter-spacing: 0.11em;
          margin-bottom: 4px;
        }

        .edit-page-title {
          margin: 0;
          font-size: clamp(26px, 3vw, 34px);
          font-weight: 800;
          letter-spacing: -0.025em;
          color: #182230;
          line-height: 1.2;
        }

        .edit-page-description {
          margin: 7px 0 0;
          color: #7a8493;
          font-size: 14px;
          line-height: 1.7;
          max-width: 720px;
          text-align: justify;
        }

        /* =====================================================
           FORM CARD
        ===================================================== */

        .edit-form-card {
          background: #ffffff;
          border: 1px solid #e7ebef;
          border-radius: 18px;
          overflow: hidden;
          box-shadow: 0 6px 22px rgba(20, 30, 45, 0.035);
        }

        .edit-form-header {
          padding: 24px 28px;
          border-bottom: 1px solid #edf0f3;
          background: linear-gradient(
            180deg,
            #ffffff,
            #fcfdfd
          );
        }

        .edit-form-header-top {
          display: flex;
          align-items: center;
          gap: 12px;
        }

        .edit-form-header-icon {
          width: 42px;
          height: 42px;
          min-width: 42px;
          border-radius: 11px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #eaf7f0;
          color: #198754;
          font-size: 17px;
        }

        .edit-form-header-text {
          min-width: 0;
        }

        .edit-form-eyebrow {
          color: #198754;
          font-size: 10px;
          font-weight: 800;
          letter-spacing: 0.1em;
          margin-bottom: 3px;
        }

        .edit-form-title {
          margin: 0;
          color: #182230;
          font-size: 18px;
          font-weight: 800;
        }

        .edit-form-subtitle {
          margin: 6px 0 0;
          color: #8a93a0;
          font-size: 12px;
          line-height: 1.6;
          text-align: justify;
        }

        .edit-form-body {
          padding: 28px;
        }

        /* =====================================================
           FORM GROUP
        ===================================================== */

        .edit-form-group {
          margin-bottom: 23px;
        }

        .edit-form-label {
          display: block;
          margin-bottom: 8px;
          color: #344054;
          font-size: 13px;
          font-weight: 700;
        }

        .edit-form-label-required {
          color: #dc3545;
          margin-left: 3px;
        }

        .edit-form-help {
          margin-top: 6px;
          color: #98a2b3;
          font-size: 11px;
          line-height: 1.5;
        }

        .edit-form-control,
        .edit-form-select,
        .edit-form-textarea {
          width: 100%;
          display: block;
          border: 1px solid #dfe4ea;
          background: #ffffff;
          color: #253143;
          border-radius: 10px;
          font-size: 13px;
          outline: none;
          transition:
            border-color 0.2s ease,
            box-shadow 0.2s ease,
            background 0.2s ease;
        }

        .edit-form-control,
        .edit-form-select {
          min-height: 46px;
          padding: 10px 13px;
        }

        .edit-form-textarea {
          min-height: 160px;
          padding: 12px 13px;
          resize: vertical;
          line-height: 1.7;
          text-align: justify;
        }

        .edit-form-control::placeholder,
        .edit-form-textarea::placeholder {
          color: #a5adb8;
        }

        .edit-form-control:focus,
        .edit-form-select:focus,
        .edit-form-textarea:focus {
          border-color: #198754;
          box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.1);
          background: #ffffff;
        }

        .edit-form-select {
          cursor: pointer;
        }

        /* =====================================================
           YEAR INPUT
        ===================================================== */

        .edit-year-wrapper {
          position: relative;
        }

        .edit-year-wrapper .edit-form-control {
          padding-right: 45px;
        }

        .edit-year-icon {
          position: absolute;
          top: 50%;
          right: 14px;
          transform: translateY(-50%);
          color: #198754;
          pointer-events: none;
        }

        /* =====================================================
           SECTION DIVIDER
        ===================================================== */

        .edit-form-section {
          padding-top: 4px;
          margin-bottom: 23px;
        }

        .edit-section-title {
          display: flex;
          align-items: center;
          gap: 8px;
          color: #344054;
          font-size: 13px;
          font-weight: 800;
          margin-bottom: 15px;
        }

        .edit-section-title i {
          color: #198754;
        }

        .edit-section-line {
          flex: 1;
          height: 1px;
          background: #edf0f3;
        }

        /* =====================================================
           ACTIONS
        ===================================================== */

        .edit-form-actions {
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
          padding-top: 22px;
          margin-top: 5px;
          border-top: 1px solid #edf0f3;
        }

        .edit-action-left,
        .edit-action-right {
          display: flex;
          align-items: center;
          gap: 9px;
        }

        .edit-cancel-button,
        .edit-submit-button {
          min-height: 44px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
          border-radius: 10px;
          padding: 9px 17px;
          font-size: 13px;
          font-weight: 700;
          text-decoration: none;
          transition: 0.2s ease;
          cursor: pointer;
        }

        .edit-cancel-button {
          color: #667085;
          background: #ffffff;
          border: 1px solid #dfe4ea;
        }

        .edit-cancel-button:hover {
          color: #344054;
          background: #f8fafb;
          border-color: #cbd2da;
        }

        .edit-submit-button {
          color: #ffffff;
          background: linear-gradient(135deg, #198754, #20a46c);
          border: 1px solid #198754;
          box-shadow: 0 7px 17px rgba(25, 135, 84, 0.16);
        }

        .edit-submit-button:hover:not(:disabled) {
          color: #ffffff;
          transform: translateY(-1px);
          box-shadow: 0 10px 22px rgba(25, 135, 84, 0.23);
        }

        .edit-submit-button:disabled {
          opacity: 0.7;
          cursor: not-allowed;
          box-shadow: none;
        }

        /* =====================================================
           INFO BOX
        ===================================================== */

        .edit-info-box {
          display: flex;
          align-items: flex-start;
          gap: 11px;
          margin-top: 22px;
          padding: 13px 15px;
          border-radius: 10px;
          background: #f5faf7;
          border: 1px solid #dcefe5;
        }

        .edit-info-icon {
          color: #198754;
          font-size: 15px;
          margin-top: 1px;
          flex-shrink: 0;
        }

        .edit-info-text {
          color: #718096;
          font-size: 11px;
          line-height: 1.65;
          text-align: justify;
        }

        /* =====================================================
           FOOTER
        ===================================================== */

        .edit-page-footer {
          padding: 20px 3px 5px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 15px;
          color: #9aa3af;
          font-size: 11px;
        }

        .edit-page-footer-left {
          display: flex;
          align-items: center;
          gap: 7px;
        }

        .edit-page-footer-left i {
          color: #198754;
        }

        .edit-page-footer a {
          color: #7b8492;
          text-decoration: none;
          font-weight: 600;
        }

        .edit-page-footer a:hover {
          color: #198754;
        }

        /* =====================================================
           MOBILE OVERLAY
        ===================================================== */

        .edit-sidebar-overlay {
          display: none;
        }

        /* =====================================================
           TABLET
        ===================================================== */

        @media (max-width: 1199.98px) {
          .edit-admin-content {
            padding: 28px;
          }
        }

        /* =====================================================
           SIDEBAR MOBILE
        ===================================================== */

        @media (max-width: 991.98px) {
          .edit-admin-sidebar {
            transform: translateX(-100%);
            box-shadow: 15px 0 40px rgba(20, 30, 45, 0.1);
          }

          .edit-admin-sidebar.open {
            transform: translateX(0);
          }

          .edit-admin-main {
            width: 100%;
            margin-left: 0;
          }

          .edit-sidebar-overlay {
            position: fixed;
            inset: 0;
            z-index: 1040;
            display: block;
            background: rgba(15, 23, 42, 0.35);
            backdrop-filter: blur(2px);
          }

          .edit-admin-topbar {
            padding: 0 24px;
          }
        }

        /* =====================================================
           MOBILE
        ===================================================== */

        @media (max-width: 767.98px) {
          .edit-admin-topbar {
            height: 68px;
            padding: 0 16px;
          }

          .edit-topbar-title {
            font-size: 13px;
          }

          .edit-admin-content {
            padding: 23px 16px;
          }

          .edit-page-header {
            margin-bottom: 21px;
          }

          .edit-back-link {
            margin-bottom: 15px;
            font-size: 12px;
          }

          .edit-page-title-row {
            gap: 12px;
          }

          .edit-page-title-icon {
            width: 48px;
            height: 48px;
            min-width: 48px;
            border-radius: 13px;
            font-size: 19px;
          }

          .edit-page-title {
            font-size: 27px;
          }

          .edit-page-description {
            font-size: 12px;
            line-height: 1.65;
          }

          .edit-form-card {
            border-radius: 14px;
          }

          .edit-form-header {
            padding: 18px;
          }

          .edit-form-body {
            padding: 18px;
          }

          .edit-form-header-icon {
            width: 38px;
            height: 38px;
            min-width: 38px;
            font-size: 15px;
          }

          .edit-form-title {
            font-size: 16px;
          }

          .edit-form-subtitle {
            font-size: 11px;
          }

          .edit-form-group {
            margin-bottom: 20px;
          }

          .edit-form-label {
            font-size: 12px;
          }

          .edit-form-control,
          .edit-form-select {
            min-height: 44px;
            font-size: 12px;
          }

          .edit-form-textarea {
            min-height: 145px;
            font-size: 12px;
          }

          .edit-form-actions {
            flex-direction: column-reverse;
            align-items: stretch;
            gap: 10px;
          }

          .edit-action-left,
          .edit-action-right {
            width: 100%;
          }

          .edit-cancel-button,
          .edit-submit-button {
            flex: 1;
            width: 100%;
          }

          .edit-info-box {
            padding: 12px;
          }

          .edit-page-footer {
            flex-direction: column;
            align-items: flex-start;
          }
        }

        /* =====================================================
           SMALL MOBILE
        ===================================================== */

        @media (max-width: 479.98px) {
          .edit-topbar-right {
            gap: 6px;
          }

          .edit-topbar-website,
          .edit-topbar-logout {
            width: 38px;
            height: 38px;
            min-height: 38px;
            padding: 0;
            border-radius: 9px;
          }

          .edit-topbar-title {
            max-width: 145px;
          }

          .edit-admin-content {
            padding: 20px 12px;
          }

          .edit-page-title-row {
            gap: 10px;
          }

          .edit-page-title-icon {
            width: 43px;
            height: 43px;
            min-width: 43px;
            border-radius: 12px;
            font-size: 17px;
          }

          .edit-page-title {
            font-size: 23px;
          }

          .edit-page-description {
            font-size: 11px;
          }

          .edit-form-header {
            padding: 16px;
          }

          .edit-form-body {
            padding: 16px;
          }

          .edit-form-header-top {
            gap: 9px;
          }

          .edit-form-header-icon {
            width: 35px;
            height: 35px;
            min-width: 35px;
            border-radius: 9px;
            font-size: 14px;
          }

          .edit-form-title {
            font-size: 15px;
          }

          .edit-form-subtitle {
            font-size: 10px;
          }

          .edit-form-control,
          .edit-form-select {
            min-height: 43px;
            padding: 9px 11px;
          }

          .edit-form-textarea {
            padding: 10px 11px;
          }

          .edit-cancel-button,
          .edit-submit-button {
            min-height: 43px;
            padding: 9px 12px;
            font-size: 12px;
          }

          .edit-info-text {
            font-size: 10px;
          }

          .edit-page-footer {
            font-size: 10px;
          }
        }

        /* =====================================================
           REDUCED MOTION
        ===================================================== */

        @media (prefers-reduced-motion: reduce) {
          .education-edit-page *,
          .education-edit-page *::before,
          .education-edit-page *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
          }
        }
      `}</style>

      <div className="education-edit-page">
        <div className="edit-admin-layout">

          {/* ===================================================
              MOBILE OVERLAY
          =================================================== */}

          {sidebarOpen && (
            <div
              className="edit-sidebar-overlay"
              onClick={closeSidebar}
              aria-hidden="true"
            />
          )}

          {/* ===================================================
              SIDEBAR
          =================================================== */}

          <aside
            className={`edit-admin-sidebar ${
              sidebarOpen ? "open" : ""
            }`}
          >
            <div className="edit-sidebar-inner">

              {/* BRAND */}

              <div className="edit-sidebar-brand">
                <div className="edit-brand-icon">
                  <i className="bi bi-grid-1x2-fill"></i>
                </div>

                <div className="edit-brand-text">
                  <strong>GloVaTech</strong>
                  <span>Admin Panel</span>
                </div>

                <button
                  type="button"
                  className="edit-sidebar-close d-lg-none"
                  onClick={closeSidebar}
                  aria-label="Close sidebar"
                >
                  <i className="bi bi-x-lg"></i>
                </button>
              </div>

              {/* MAIN MENU */}

              <div className="edit-sidebar-section-label">
                MAIN MENU
              </div>

              <nav className="edit-sidebar-nav">

                <Link
                  href="/secure-panel"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-speedometer2"></i>
                  </span>

                  <span>Dashboard</span>
                </Link>

              </nav>

              {/* CONTENT */}

              <div className="edit-sidebar-section-label mt-4">
                CONTENT
              </div>

              <nav className="edit-sidebar-nav">

                <Link
                  href="/secure-panel/hero"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-stars"></i>
                  </span>

                  <span>Hero</span>
                </Link>

                <Link
                  href="/secure-panel/about"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-person-vcard"></i>
                  </span>

                  <span>About</span>
                </Link>

                <Link href="/secure-panel/about/stats" className="edit-sidebar-link" onClick={closeSidebar} > <span className="edit-sidebar-link-icon"> <i className="bi bi-bar-chart"></i> </span> <span>About Stats</span> </Link>

                <Link
                  href="/secure-panel/education"
                  className="edit-sidebar-link active"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-mortarboard"></i>
                  </span>

                  <span>Education</span>
                </Link>

                <Link
                  href="/secure-panel/skills"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-tools"></i>
                  </span>

                  <span>Skills</span>
                </Link>

                <Link
                  href="/secure-panel/experience"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-briefcase"></i>
                  </span>

                  <span>Experience</span>
                </Link>

                <Link
                  href="/secure-panel/projects"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-code-square"></i>
                  </span>

                  <span>Projects</span>
                </Link>

                <Link
                  href="/secure-panel/certifications"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-patch-check"></i>
                  </span>

                  <span>Certification</span>
                </Link>

                <Link
                  href="/secure-panel/achievements"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-trophy"></i>
                  </span>

                  <span>Achievement</span>
                </Link>

                <Link
                  href="/secure-panel/services"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-gear-wide-connected"></i>
                  </span>

                  <span>Services</span>
                </Link>

                <Link
                  href="/secure-panel/gallery"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-images"></i>
                  </span>

                  <span>Gallery</span>
                </Link>

                <Link
                  href="/secure-panel/contact-info"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-person-lines-fill"></i>
                  </span>

                  <span>Contact</span>
                </Link>

                <Link
  href="/secure-panel/contact-info/list"
  className="edit-sidebar-link"
  onClick={closeSidebar}
>
  <span className="edit-sidebar-link-icon">
    <i className="bi bi-share-fill"></i>
  </span>

  <span>Contact Social Media</span>
</Link>

                <Link
                  href="/secure-panel/articles"
                  className="edit-sidebar-link"
                  onClick={closeSidebar}
                >
                  <span className="edit-sidebar-link-icon">
                    <i className="bi bi-journal-text"></i>
                  </span>

                  <span>Articles</span>
                </Link>

                <Link
  href="/secure-panel/contact-messages"
  className="edit-sidebar-link"
  onClick={closeSidebar}
>
  <span className="edit-sidebar-link-icon">
    <i className="bi bi-chat-left-text"></i>
  </span>

  <span>Contact Messages</span>
</Link>

<Link
  href="/secure-panel/contact-users"
  className="edit-sidebar-link"
  onClick={closeSidebar}
>
  <span className="edit-sidebar-link-icon">
    <i className="bi bi-people-fill"></i>
  </span>

  <span>Contact User</span>
</Link>

              </nav>

              {/* SIDEBAR BOTTOM */}

              <div className="edit-sidebar-bottom">

                <Link href="/">
                  <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="edit-admin-main">

            {/* =================================================
                TOPBAR
            ================================================= */}

            <header className="edit-admin-topbar">

              <div className="edit-topbar-left">

                <button
                  type="button"
                  className="edit-mobile-menu-button d-lg-none"
                  onClick={() => setSidebarOpen(true)}
                  aria-label="Open menu"
                >
                  <i className="bi bi-list"></i>
                </button>

                <div>
                  <div className="edit-topbar-label">
                    ADMIN PANEL
                  </div>

                  <div className="edit-topbar-title">
                    Edit Education
                  </div>
                </div>

              </div>

              <div className="edit-topbar-right">

                <Link
                  href="/"
                  className="edit-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="edit-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="edit-admin-content">

              {/* =================================================
                  PAGE HEADER
              ================================================= */}

              <section className="edit-page-header">

                <Link
                  href="/secure-panel/education"
                  className="edit-back-link"
                >
                  <i className="bi bi-arrow-left"></i>

                  Kembali ke Education
                </Link>

                <div className="edit-page-title-row">

                  <div className="edit-page-title-icon">
                    <i className="bi bi-pencil-square"></i>
                  </div>

                  <div className="edit-page-title-content">

                    <div className="edit-page-eyebrow">
                      WEBSITE CONTENT
                    </div>

                    <h1 className="edit-page-title">
                      Edit Education
                    </h1>

                    <p className="edit-page-description">
                      Perbarui informasi riwayat pendidikan
                      dan latar belakang akademik yang
                      ditampilkan pada website portfolio
                      GloVaTech.
                    </p>

                  </div>

                </div>

              </section>

              {/* =================================================
                  FORM CARD
              ================================================= */}

              <section className="edit-form-card">

                {/* FORM HEADER */}

                <div className="edit-form-header">

                  <div className="edit-form-header-top">

                    <div className="edit-form-header-icon">
                      <i className="bi bi-mortarboard-fill"></i>
                    </div>

                    <div className="edit-form-header-text">

                      <div className="edit-form-eyebrow">
                        EDUCATION INFORMATION
                      </div>

                      <h2 className="edit-form-title">
                        Academic Background
                      </h2>

                    </div>

                  </div>

                  <p className="edit-form-subtitle">
                    Pastikan seluruh informasi pendidikan
                    sudah sesuai sebelum menyimpan perubahan.
                  </p>

                </div>

                {/* FORM BODY */}

                <div className="edit-form-body">

                  <form onSubmit={handleSubmit}>

                    {/* =================================================
                        BASIC INFORMATION
                    ================================================= */}

                    <div className="edit-form-section">

                      <div className="edit-section-title">

                        <i className="bi bi-person-vcard"></i>

                        <span>
                          Basic Information
                        </span>

                        <div className="edit-section-line"></div>

                      </div>

                    </div>

                    {/* INSTITUTION */}

                    <div className="edit-form-group">

                      <label
                        htmlFor="institution"
                        className="edit-form-label"
                      >
                        Institution Name

                        <span className="edit-form-label-required">
                          *
                        </span>
                      </label>

                      <input
                        type="text"
                        id="institution"
                        name="institution"
                        className="edit-form-control"
                        placeholder="Example: Universitas Putra Indonesia YPTK Padang"
                        value={form.institution}
                        onChange={handleChange}
                        required
                      />

                      <div className="edit-form-help">
                        Masukkan nama sekolah, universitas,
                        atau institusi pendidikan.
                      </div>

                    </div>

                    {/* DEGREE */}

                    <div className="edit-form-group">

                      <label
                        htmlFor="degree"
                        className="edit-form-label"
                      >
                        Education Level

                        <span className="edit-form-label-required">
                          *
                        </span>
                      </label>

                      <select
                        id="degree"
                        name="degree"
                        className="edit-form-select"
                        value={form.degree}
                        onChange={handleChange}
                        required
                      >
                        <option value="SMA">
                          High School (SMA)
                        </option>

                        <option value="SMK">
                          Vocational High School (SMK)
                        </option>

                        <option value="D3">
                          Diploma (D3)
                        </option>

                        <option value="S1">
                          Bachelor's Degree (S1)
                        </option>

                        <option value="S2">
                          Master's Degree (S2)
                        </option>

                        <option value="S3">
                          Doctoral Degree (S3)
                        </option>
                      </select>

                    </div>

                    {/* FIELD */}

                    <div className="edit-form-group">

                      <label
                        htmlFor="field"
                        className="edit-form-label"
                      >
                        Field of Study / Major
                      </label>

                      <input
                        type="text"
                        id="field"
                        name="field"
                        className="edit-form-control"
                        placeholder="Example: Information Technology"
                        value={form.field}
                        onChange={handleChange}
                      />

                    </div>

                    {/* =================================================
                        EDUCATION PERIOD
                    ================================================= */}

                    <div className="edit-form-section">

                      <div className="edit-section-title">

                        <i className="bi bi-calendar3"></i>

                        <span>
                          Education Period
                        </span>

                        <div className="edit-section-line"></div>

                      </div>

                    </div>

                    <div className="row g-3">

                      {/* START YEAR */}

                      <div className="col-12 col-md-6">

                        <div className="edit-form-group">

                          <label
                            htmlFor="startDate"
                            className="edit-form-label"
                          >
                            Start Year

                            <span className="edit-form-label-required">
                              *
                            </span>
                          </label>

                          <div className="edit-year-wrapper">

                            <input
                              type="number"
                              id="startDate"
                              name="startDate"
                              className="edit-form-control"
                              placeholder="Example: 2022"
                              min="1900"
                              max="2100"
                              value={form.startDate}
                              onChange={handleChange}
                              required
                            />

                            <i className="bi bi-calendar3 edit-year-icon"></i>

                          </div>

                        </div>

                      </div>

                      {/* END YEAR */}

                      <div className="col-12 col-md-6">

                        <div className="edit-form-group">

                          <label
                            htmlFor="endDate"
                            className="edit-form-label"
                          >
                            Graduation Year
                          </label>

                          <div className="edit-year-wrapper">

                            <input
                              type="number"
                              id="endDate"
                              name="endDate"
                              className="edit-form-control"
                              placeholder="Example: 2026"
                              min="1900"
                              max="2100"
                              value={form.endDate}
                              onChange={handleChange}
                            />

                            <i className="bi bi-calendar-check edit-year-icon"></i>

                          </div>

                          <div className="edit-form-help">
                            Kosongkan jika pendidikan masih
                            berlangsung.
                          </div>

                        </div>

                      </div>

                    </div>

                    {/* =================================================
                        DESCRIPTION
                    ================================================= */}

                    <div className="edit-form-section">

                      <div className="edit-section-title">

                        <i className="bi bi-card-text"></i>

                        <span>
                          Additional Information
                        </span>

                        <div className="edit-section-line"></div>

                      </div>

                    </div>

                    <div className="edit-form-group">

                      <label
                        htmlFor="description"
                        className="edit-form-label"
                      >
                        Description
                      </label>

                      <textarea
                        id="description"
                        name="description"
                        className="edit-form-textarea"
                        rows={7}
                        placeholder="Describe your activities, achievements, organizations, research, or other important experiences..."
                        value={form.description}
                        onChange={handleChange}
                      ></textarea>

                      <div className="edit-form-help">
                        Gunakan deskripsi yang singkat, jelas,
                        profesional, dan relevan dengan
                        pendidikan.
                      </div>

                    </div>

                    {/* INFO */}

                    <div className="edit-info-box">

                      <div className="edit-info-icon">
                        <i className="bi bi-info-circle-fill"></i>
                      </div>

                      <div className="edit-info-text">
                        Perubahan yang disimpan akan langsung
                        memperbarui data Education pada
                        website. Pastikan informasi yang
                        dimasukkan sudah benar sebelum
                        menekan tombol Update Education.
                      </div>

                    </div>

                    {/* =================================================
                        ACTIONS
                    ================================================= */}

                    <div className="edit-form-actions">

                      <div className="edit-action-left">

                        <Link
                          href="/secure-panel/education"
                          className="edit-cancel-button"
                        >
                          <i className="bi bi-x-lg"></i>

                          <span>
                            Cancel
                          </span>
                        </Link>

                      </div>

                      <div className="edit-action-right">

                        <button
                          type="submit"
                          className="edit-submit-button"
                          disabled={saving}
                        >

                          {saving ? (
                            <>
                              <span
                                className="spinner-border spinner-border-sm"
                                role="status"
                                aria-hidden="true"
                              ></span>

                              <span>
                                Updating...
                              </span>
                            </>
                          ) : (
                            <>
                              <i className="bi bi-check-lg"></i>

                              <span>
                                Update Education
                              </span>
                            </>
                          )}

                        </button>

                      </div>

                    </div>

                  </form>

                </div>

              </section>

              {/* =================================================
                  FOOTER
              ================================================= */}

              <footer className="edit-page-footer">

                <div className="edit-page-footer-left">

                  <i className="bi bi-shield-check"></i>

                  <span>
                    Admin Content Management System
                  </span>

                </div>

                <Link href="/secure-panel/education">

                  <i className="bi bi-arrow-left me-1"></i>

                  Education Management

                </Link>

              </footer>

            </main>

          </div>

        </div>
      </div>
    </>
  );
}