"use client";

import { useEffect, useState } from "react";
import Link from "next/link";

import Navbar from "@/components/Navbar";
import Footer from "@/components/Footer";

type Article = {
  id: number;
  title: string;
  slug: string;
  category: string | null;
  published: boolean;
  publishedAt: string | null;
  createdAt: string;
};

export default function EditArticlesPage() {
  const [articles, setArticles] = useState<Article[]>([]);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState("");

  useEffect(() => {
    const loadArticles = async () => {
      try {
        const response = await fetch(
          "/api/user/articles"
        );

        const result = await response.json();

        if (!response.ok || !result.success) {
          throw new Error(
            result.message ||
              "Gagal mengambil Article"
          );
        }

        setArticles(result.articles || []);
      } catch (error) {
        console.error(
          "LOAD USER ARTICLES ERROR:",
          error
        );

        setError(
          error instanceof Error
            ? error.message
            : "Gagal mengambil Article"
        );
      } finally {
        setLoading(false);
      }
    };

    loadArticles();
  }, []);

  const publishedCount = articles.filter(
    (article) => article.published
  ).length;

  const draftCount = articles.filter(
    (article) => !article.published
  ).length;

  return (
    <>
      <Navbar />

      <style>{`
        /* =====================================================
           PAGE
        ===================================================== */

        .edit-articles-page {
          position: relative;

          min-height: 100vh;

          padding: 120px 0 90px;

          overflow: hidden;

          background:
            radial-gradient(
              circle at 8% 0%,
              rgba(25, 135, 84, 0.09),
              transparent 27%
            ),
            radial-gradient(
              circle at 95% 35%,
              rgba(25, 135, 84, 0.055),
              transparent 25%
            ),
            #f4f7f5;
        }

        /*
          Ambient background animation
        */

        .edit-articles-page::before {
          content: "";

          position: absolute;

          width: 500px;
          height: 500px;

          top: -280px;
          right: -180px;

          border-radius: 50%;

          background:
            radial-gradient(
              circle,
              rgba(25, 135, 84, 0.10),
              rgba(25, 135, 84, 0.02),
              transparent 70%
            );

          filter: blur(8px);

          pointer-events: none;

          animation:
            ambientMove 12s ease-in-out infinite;
        }

        .edit-articles-page::after {
          content: "";

          position: absolute;

          width: 420px;
          height: 420px;

          bottom: -260px;
          left: -180px;

          border-radius: 50%;

          background:
            radial-gradient(
              circle,
              rgba(25, 135, 84, 0.075),
              transparent 70%
            );

          pointer-events: none;

          animation:
            ambientMoveReverse 15s ease-in-out infinite;
        }

        .edit-articles-wrapper {
          position: relative;

          z-index: 2;

          max-width: 1180px;

          margin: 0 auto;
        }

        /* =====================================================
           HEADER
        ===================================================== */

        .edit-articles-header {
          text-align: center;

          margin-bottom: 34px;

          animation:
            headerReveal 0.8s ease both;
        }

        .header-badge {
          position: relative;

          display: inline-flex;

          align-items: center;

          gap: 8px;

          padding: 7px 14px;

          margin-bottom: 14px;

          overflow: hidden;

          border: 1px solid #cfe5d8;

          border-radius: 999px;

          background: #e9f6ee;

          color: #198754;

          font-size: 11px;

          font-weight: 700;

          letter-spacing: 0.7px;

          text-transform: uppercase;

          box-shadow:
            0 5px 15px
            rgba(25, 135, 84, 0.06);

          animation:
            badgeFloat 4s ease-in-out infinite;
        }

        /*
          Shine bergerak di badge
        */

        .header-badge::after {
          content: "";

          position: absolute;

          top: 0;
          left: -80%;

          width: 45%;
          height: 100%;

          background:
            linear-gradient(
              90deg,
              transparent,
              rgba(255, 255, 255, 0.8),
              transparent
            );

          transform: skewX(-20deg);

          animation:
            badgeShine 4.5s ease-in-out infinite;
        }

        .header-badge-dot {
          position: relative;

          z-index: 2;

          width: 7px;
          height: 7px;

          border-radius: 50%;

          background: #198754;

          box-shadow:
            0 0 0 5px
            rgba(25, 135, 84, 0.08);

          animation:
            badgePulse 2s ease-in-out infinite;
        }

        .edit-articles-header h1 {
          margin: 0 0 10px;

          color: #17231d;

          font-size: clamp(30px, 4vw, 43px);

          font-weight: 750;

          letter-spacing: -1px;

          line-height: 1.15;
        }

        .edit-articles-header p {
          max-width: 620px;

          margin: 0 auto;

          color: #728078;

          font-size: 14px;

          line-height: 1.7;
        }

        /* =====================================================
           MAIN CARD
        ===================================================== */

        .articles-card {
          position: relative;

          overflow: hidden;

          background: #ffffff;

          border: 1px solid #d8e2dc;

          border-radius: 22px;

          box-shadow:
            0 2px 4px
            rgba(22, 55, 38, 0.03),

            0 12px 28px
            rgba(22, 55, 38, 0.06),

            0 28px 65px
            rgba(22, 55, 38, 0.07);

          animation:
            cardReveal 0.8s ease both,
            cardBreathing 7s ease-in-out infinite;
        }

        /*
          Animated green accent
        */

        .articles-card::before {
  content: "";

  position: absolute;

  top: 0;
  left: -100%;

  width: 100%;
  height: 4px;

  background:
    linear-gradient(
      90deg,
      #198754,
      #73c69a,
      #198754,
      #4aa977,
      #198754
    );

  animation: greenLineLoop 4s linear infinite;

  z-index: 10;
}

@keyframes greenLineLoop {
  0% {
    left: -100%;
  }

  100% {
    left: 100%;
  }
}

          background-size: 300% 100%;

          animation:
            greenFlow 5s linear infinite;

          z-index: 5;
        }

        /*
          Subtle moving glow inside card
        */

        .articles-card::after {
          content: "";

          position: absolute;

          top: -100px;
          left: -180px;

          width: 180px;
          height: 180px;

          border-radius: 50%;

          background:
            radial-gradient(
              circle,
              rgba(25, 135, 84, 0.045),
              transparent 70%
            );

          pointer-events: none;

          animation:
            cardGlowMove 10s ease-in-out infinite;
        }

        /* =====================================================
           CARD HEADER
        ===================================================== */

        .articles-card-header {
          position: relative;

          z-index: 2;

          display: flex;

          align-items: center;

          justify-content: space-between;

          gap: 20px;

          padding: 25px 28px;

          border-bottom: 1px solid #e5ebe7;

          background:
            linear-gradient(
              180deg,
              #ffffff,
              #fbfdfc
            );
        }

        .card-header-left {
          display: flex;

          align-items: center;

          gap: 14px;
        }

        .card-header-icon {
          position: relative;

          width: 45px;
          height: 45px;

          display: flex;

          align-items: center;

          justify-content: center;

          flex: 0 0 45px;

          border-radius: 13px;

          background: #e7f5ed;

          color: #198754;

          font-size: 19px;

          box-shadow:
            inset 0 0 0 1px
            rgba(25, 135, 84, 0.07),

            0 6px 18px
            rgba(25, 135, 84, 0.07);

          animation:
            iconFloat 3.8s ease-in-out infinite;
        }

        /*
          Icon ring
        */

        .card-header-icon::before {
          content: "";

          position: absolute;

          inset: -4px;

          border: 1px solid
            rgba(25, 135, 84, 0.12);

          border-radius: 16px;

          animation:
            iconRing 3s ease-in-out infinite;
        }

        .card-header-left h2 {
          margin: 0 0 3px;

          color: #26332c;

          font-size: 16px;

          font-weight: 750;
        }

        .card-header-left p {
          margin: 0;

          color: #8a958f;

          font-size: 11px;
        }

        /* =====================================================
           SUMMARY
        ===================================================== */

        .article-summary {
          display: flex;

          align-items: center;

          gap: 9px;
        }

        .summary-item {
          position: relative;

          min-width: 74px;

          padding: 8px 11px;

          overflow: hidden;

          text-align: center;

          border: 1px solid #e2e9e4;

          border-radius: 10px;

          background: #fafcfb;

          animation:
            summaryFloat 5s ease-in-out infinite;
        }

        .summary-item:nth-child(2) {
          animation-delay: 0.5s;
        }

        .summary-item:nth-child(3) {
          animation-delay: 1s;
        }

        /*
          Summary shine
        */

        .summary-item::after {
          content: "";

          position: absolute;

          top: 0;
          left: -100%;

          width: 55%;
          height: 100%;

          background:
            linear-gradient(
              90deg,
              transparent,
              rgba(255, 255, 255, 0.8),
              transparent
            );

          animation:
            summaryShine 5s ease-in-out infinite;
        }

        .summary-number {
          display: block;

          color: #26332c;

          font-size: 15px;

          font-weight: 750;

          line-height: 1.2;

          animation:
            numberBreathing 3s ease-in-out infinite;
        }

        .summary-label {
          display: block;

          margin-top: 3px;

          color: #929c96;

          font-size: 9px;

          text-transform: uppercase;

          letter-spacing: 0.4px;
        }

        .summary-published
          .summary-number {
          color: #198754;
        }

        /* =====================================================
           TABLE
        ===================================================== */

        .table-container {
          position: relative;

          z-index: 2;

          width: 100%;

          overflow-x: auto;
        }

        .articles-table {
          width: 100%;

          margin: 0;

          border-collapse: separate;

          border-spacing: 0;
        }

        .articles-table thead th {
          padding: 14px 18px;

          background: #f7faf8;

          border-bottom: 1px solid #dfe8e2;

          color: #68766e;

          font-size: 10px;

          font-weight: 750;

          letter-spacing: 0.7px;

          text-transform: uppercase;

          white-space: nowrap;
        }

        .articles-table thead th:first-child {
          padding-left: 28px;
        }

        .articles-table thead th:last-child {
          padding-right: 28px;
        }

        .articles-table tbody td {
          padding: 17px 18px;

          border-bottom: 1px solid #edf1ee;

          vertical-align: middle;

          color: #4d5a53;

          font-size: 12px;

          background: #ffffff;

          transition:
            background 0.3s ease,
            padding 0.3s ease;
        }

        .articles-table tbody tr {
          position: relative;

          transition:
            transform 0.35s ease;
        }

        .articles-table tbody tr:hover {
          transform: translateX(3px);
        }

        .articles-table tbody tr:hover td {
          background: #fbfdfc;
        }

        .articles-table tbody tr:last-child td {
          border-bottom: none;
        }

        .articles-table tbody td:first-child {
          padding-left: 28px;
        }

        .articles-table tbody td:last-child {
          padding-right: 28px;
        }

        /* =====================================================
           NUMBER
        ===================================================== */

        .article-number {
          width: 31px;
          height: 31px;

          display: flex;

          align-items: center;

          justify-content: center;

          border-radius: 9px;

          background: #f0f5f2;

          border: 1px solid #e0e8e3;

          color: #6e7c74;

          font-size: 10px;

          font-weight: 750;

          transition:
            all 0.3s ease;

          animation:
            numberFloat 5s ease-in-out infinite;
        }

        .articles-table tbody tr:hover
          .article-number {
          background: #e5f3eb;

          border-color: #cce4d5;

          color: #198754;

          transform:
            translateY(-2px)
            rotate(-2deg);
        }

        /* =====================================================
           ARTICLE INFO
        ===================================================== */

        .article-info {
          min-width: 260px;

          max-width: 430px;
        }

        .article-title {
          margin-bottom: 5px;

          color: #25322b;

          font-size: 13px;

          font-weight: 700;

          line-height: 1.45;

          transition:
            color 0.25s ease;
        }

        .articles-table tbody tr:hover
          .article-title {
          color: #198754;
        }

        .article-slug {
          color: #929c96;

          font-size: 10px;

          line-height: 1.4;

          word-break: break-word;
        }

        /* =====================================================
           CATEGORY
        ===================================================== */

        .category-badge {
          display: inline-flex;

          align-items: center;

          max-width: 170px;

          padding: 6px 9px;

          border: 1px solid #e1e9e4;

          border-radius: 7px;

          background: #f8faf9;

          color: #617068;

          font-size: 10px;

          font-weight: 600;

          white-space: nowrap;

          overflow: hidden;

          text-overflow: ellipsis;

          transition:
            all 0.3s ease;
        }

        .articles-table tbody tr:hover
          .category-badge {
          border-color: #cfe3d7;

          background: #edf8f2;

          color: #198754;

          transform: translateY(-1px);
        }

        .category-empty {
          color: #a2aaa5;

          font-size: 11px;
        }

        /* =====================================================
           STATUS
        ===================================================== */

        .status-badge {
          display: inline-flex;

          align-items: center;

          gap: 6px;

          padding: 6px 10px;

          border-radius: 999px;

          font-size: 10px;

          font-weight: 700;

          white-space: nowrap;

          transition:
            transform 0.25s ease;
        }

        .articles-table tbody tr:hover
          .status-badge {
          transform: translateY(-1px);
        }

        .status-dot {
          width: 6px;
          height: 6px;

          border-radius: 50%;
        }

        .status-published {
          color: #147548;

          background: #e8f6ee;

          border: 1px solid #d0eadb;
        }

        .status-published
          .status-dot {
          background: #198754;

          box-shadow:
            0 0 0 3px
            rgba(25, 135, 84, 0.08);

          animation:
            statusPulse 2s ease-in-out infinite;
        }

        .status-draft {
          color: #6d7771;

          background: #f1f3f4;

          border: 1px solid #e1e4e5;
        }

        .status-draft
          .status-dot {
          background: #9ca5a0;

          animation:
            draftPulse 3s ease-in-out infinite;
        }

        /* =====================================================
           DATE
        ===================================================== */

        .published-date {
          display: inline-flex;

          align-items: center;

          gap: 7px;

          color: #66736b;

          font-size: 11px;

          white-space: nowrap;
        }

        .date-icon {
          color: #198754;

          font-size: 8px;

          animation:
            datePulse 2.5s ease-in-out infinite;
        }

        .no-date {
          color: #a0a8a4;

          font-size: 11px;
        }

        /* =====================================================
           EDIT BUTTON
        ===================================================== */

        .edit-button {
          position: relative;

          display: inline-flex;

          align-items: center;

          justify-content: center;

          gap: 7px;

          min-width: 75px;

          padding: 8px 13px;

          overflow: hidden;

          border: 1px solid #198754;

          border-radius: 8px;

          background: #198754;

          color: #ffffff;

          text-decoration: none;

          font-size: 10px;

          font-weight: 700;

          transition:
            background 0.25s ease,
            transform 0.25s ease,
            box-shadow 0.25s ease;
        }

        /*
          Idle shine
        */

        .edit-button::before {
          content: "";

          position: absolute;

          top: 0;
          left: -90%;

          width: 45%;
          height: 100%;

          background:
            linear-gradient(
              90deg,
              transparent,
              rgba(255, 255, 255, 0.28),
              transparent
            );

          transform: skewX(-20deg);

          animation:
            buttonShine 4s ease-in-out infinite;
        }

        .edit-button:hover {
          background: #157347;

          color: #ffffff;

          transform: translateY(-2px);

          box-shadow:
            0 7px 15px
            rgba(25, 135, 84, 0.20);
        }

        .edit-button:active {
          transform: translateY(0);
        }

        .edit-arrow {
          font-size: 12px;

          transition:
            transform 0.25s ease;
        }

        .edit-button:hover
          .edit-arrow {
          transform: translateX(3px);
        }

        /* =====================================================
           MOBILE ARTICLE CARD
        ===================================================== */

        .mobile-articles {
          display: none;

          position: relative;

          z-index: 2;

          padding: 17px;
        }

        .mobile-article-item {
          position: relative;

          padding: 17px;

          margin-bottom: 12px;

          border: 1px solid #dfe8e3;

          border-radius: 14px;

          background: #ffffff;

          box-shadow:
            0 5px 16px
            rgba(25, 60, 42, 0.04);

          animation:
            mobileCardReveal
            0.5s ease both,
            mobileCardFloat 6s ease-in-out infinite;

          transition:
            transform 0.25s ease,
            box-shadow 0.25s ease,
            border-color 0.25s ease;
        }

        .mobile-article-item:nth-child(even) {
          animation-delay: 0.25s, 1s;
        }

        .mobile-article-item:last-child {
          margin-bottom: 0;
        }

        .mobile-article-item:hover {
          transform: translateY(-3px);

          border-color: #cbded2;

          box-shadow:
            0 10px 24px
            rgba(25, 135, 84, 0.08);
        }

        .mobile-top {
          display: flex;

          align-items: flex-start;

          justify-content: space-between;

          gap: 12px;

          margin-bottom: 13px;
        }

        .mobile-number {
          display: inline-flex;

          align-items: center;

          justify-content: center;

          width: 29px;
          height: 29px;

          flex: 0 0 29px;

          border-radius: 8px;

          background: #e8f5ed;

          color: #198754;

          font-size: 10px;

          font-weight: 750;

          animation:
            mobileNumberFloat 4s ease-in-out infinite;
        }

        .mobile-title-wrapper {
          flex: 1;
        }

        .mobile-title {
          margin: 0 0 4px;

          color: #26332c;

          font-size: 13px;

          font-weight: 700;

          line-height: 1.45;
        }

        .mobile-slug {
          color: #929c96;

          font-size: 9px;

          word-break: break-word;
        }

        .mobile-meta {
          display: grid;

          grid-template-columns:
            repeat(2, minmax(0, 1fr));

          gap: 9px;

          margin-bottom: 13px;
        }

        .mobile-meta-item {
          padding: 10px;

          border: 1px solid #e8edea;

          border-radius: 9px;

          background: #fafcfb;

          transition:
            border-color 0.25s ease,
            background 0.25s ease;
        }

        .mobile-article-item:hover
          .mobile-meta-item {
          border-color: #d9e7de;

          background: #fcfefd;
        }

        .mobile-meta-label {
          display: block;

          margin-bottom: 5px;

          color: #9aa39e;

          font-size: 8px;

          font-weight: 700;

          letter-spacing: 0.5px;

          text-transform: uppercase;
        }

        .mobile-meta-value {
          color: #536159;

          font-size: 10px;

          font-weight: 600;
        }

        .mobile-action {
          display: flex;

          width: 100%;

          text-align: center;
        }

        /* =====================================================
           EMPTY STATE
        ===================================================== */

        .empty-state {
          position: relative;

          z-index: 2;

          padding: 75px 25px;

          text-align: center;
        }

        .empty-icon {
          width: 66px;
          height: 66px;

          display: flex;

          align-items: center;

          justify-content: center;

          margin: 0 auto 20px;

          border-radius: 19px;

          background: #e8f5ed;

          color: #198754;

          font-size: 27px;

          box-shadow:
            0 8px 25px
            rgba(25, 135, 84, 0.10);

          animation:
            emptyFloat 4s ease-in-out infinite;
        }

        .empty-state h5 {
          margin: 0 0 8px;

          color: #26332c;

          font-size: 18px;

          font-weight: 750;
        }

        .empty-state p {
          max-width: 430px;

          margin: 0 auto 22px;

          color: #89948e;

          font-size: 12px;

          line-height: 1.7;
        }

        .empty-button {
          position: relative;

          display: inline-flex;

          align-items: center;

          justify-content: center;

          gap: 7px;

          padding: 10px 17px;

          overflow: hidden;

          border-radius: 9px;

          background: #198754;

          color: #ffffff;

          text-decoration: none;

          font-size: 11px;

          font-weight: 700;

          transition:
            all 0.25s ease;
        }

        .empty-button:hover {
          background: #157347;

          color: #ffffff;

          transform: translateY(-2px);

          box-shadow:
            0 8px 18px
            rgba(25, 135, 84, 0.20);
        }

        /* =====================================================
           ERROR
        ===================================================== */

        .error-state {
          position: relative;

          z-index: 2;

          padding: 65px 25px;

          text-align: center;
        }

        .error-icon {
          width: 60px;
          height: 60px;

          display: flex;

          align-items: center;

          justify-content: center;

          margin: 0 auto 18px;

          border-radius: 18px;

          background: #fff0f1;

          border: 1px solid #f5d5d8;

          color: #dc3545;

          font-size: 24px;

          animation:
            errorPulse 3s ease-in-out infinite;
        }

        .error-state h5 {
          margin: 0 0 7px;

          color: #343a40;

          font-size: 16px;

          font-weight: 700;
        }

        .error-message {
          margin: 0;

          color: #dc3545;

          font-size: 12px;
        }

        /* =====================================================
           LOADING
        ===================================================== */

        .loading-state {
          position: relative;

          z-index: 2;

          padding: 28px;
        }

        .loading-row {
          display: grid;

          grid-template-columns:
            45px
            minmax(250px, 2fr)
            minmax(100px, 1fr)
            minmax(100px, 1fr)
            minmax(120px, 1fr)
            90px;

          align-items: center;

          gap: 18px;

          padding: 17px 0;

          border-bottom: 1px solid #edf1ee;
        }

        .loading-row:last-child {
          border-bottom: none;
        }

        .skeleton {
          height: 13px;

          border-radius: 7px;

          background:
            linear-gradient(
              90deg,
              #edf2ef 25%,
              #f7f9f8 50%,
              #edf2ef 75%
            );

          background-size: 200% 100%;

          animation:
            skeletonFlow 1.6s linear infinite;
        }

        .skeleton-small {
          width: 31px;
          height: 31px;

          border-radius: 9px;
        }

        .skeleton-short {
          width: 65%;
        }

        .skeleton-button {
          height: 31px;

          border-radius: 8px;
        }

        /* =====================================================
           ANIMATIONS
        ===================================================== */

        @keyframes headerReveal {
          from {
            opacity: 0;
            transform: translateY(-18px);
          }

          to {
            opacity: 1;
            transform: translateY(0);
          }
        }

        @keyframes cardReveal {
          from {
            opacity: 0;
            transform: translateY(22px);
          }

          to {
            opacity: 1;
            transform: translateY(0);
          }
        }

        @keyframes cardBreathing {
          0%,
          100% {
            box-shadow:
              0 2px 4px
              rgba(22, 55, 38, 0.03),

              0 12px 28px
              rgba(22, 55, 38, 0.06),

              0 28px 65px
              rgba(22, 55, 38, 0.07);
          }

          50% {
            box-shadow:
              0 3px 5px
              rgba(22, 55, 38, 0.03),

              0 16px 32px
              rgba(22, 55, 38, 0.07),

              0 34px 72px
              rgba(22, 55, 38, 0.085);
          }
        }

        @keyframes greenFlow {
          from {
            background-position: 0% 50%;
          }

          to {
            background-position: 300% 50%;
          }
        }

        @keyframes ambientMove {
          0%,
          100% {
            transform:
              translate3d(0, 0, 0)
              scale(1);
          }

          50% {
            transform:
              translate3d(-70px, 80px, 0)
              scale(1.18);
          }
        }

        @keyframes ambientMoveReverse {
          0%,
          100% {
            transform:
              translate3d(0, 0, 0)
              scale(1);
          }

          50% {
            transform:
              translate3d(80px, -50px, 0)
              scale(1.15);
          }
        }

        @keyframes cardGlowMove {
          0% {
            transform:
              translate(0, 0)
              scale(1);
          }

          50% {
            transform:
              translate(700px, 260px)
              scale(1.6);
          }

          100% {
            transform:
              translate(0, 0)
              scale(1);
          }
        }

        @keyframes badgeFloat {
          0%,
          100% {
            transform: translateY(0);
          }

          50% {
            transform: translateY(-3px);
          }
        }

        @keyframes badgePulse {
          0%,
          100% {
            transform: scale(1);
            box-shadow:
              0 0 0 5px
              rgba(25, 135, 84, 0.08);
          }

          50% {
            transform: scale(1.18);
            box-shadow:
              0 0 0 8px
              rgba(25, 135, 84, 0.035);
          }
        }

        @keyframes badgeShine {
          0%,
          55% {
            left: -80%;
          }

          75%,
          100% {
            left: 130%;
          }
        }

        @keyframes iconFloat {
          0%,
          100% {
            transform:
              translateY(0)
              rotate(0deg);
          }

          50% {
            transform:
              translateY(-4px)
              rotate(-1deg);
          }
        }

        @keyframes iconRing {
          0%,
          100% {
            opacity: 0.35;
            transform: scale(1);
          }

          50% {
            opacity: 0;
            transform: scale(1.12);
          }
        }

        @keyframes summaryFloat {
          0%,
          100% {
            transform: translateY(0);
          }

          50% {
            transform: translateY(-2px);
          }
        }

        @keyframes summaryShine {
          0%,
          60% {
            left: -100%;
          }

          80%,
          100% {
            left: 140%;
          }
        }

        @keyframes numberBreathing {
          0%,
          100% {
            opacity: 1;
          }

          50% {
            opacity: 0.78;
          }
        }

        @keyframes numberFloat {
          0%,
          100% {
            transform: translateY(0);
          }

          50% {
            transform: translateY(-2px);
          }
        }

        @keyframes statusPulse {
          0%,
          100% {
            opacity: 1;
            transform: scale(1);
          }

          50% {
            opacity: 0.45;
            transform: scale(0.82);
          }
        }

        @keyframes draftPulse {
          0%,
          100% {
            opacity: 0.55;
          }

          50% {
            opacity: 1;
          }
        }

        @keyframes datePulse {
          0%,
          100% {
            opacity: 0.55;
          }

          50% {
            opacity: 1;
          }
        }

        @keyframes buttonShine {
          0%,
          55% {
            left: -90%;
          }

          78%,
          100% {
            left: 140%;
          }
        }

        @keyframes mobileCardReveal {
          from {
            opacity: 0;
            transform: translateY(10px);
          }

          to {
            opacity: 1;
            transform: translateY(0);
          }
        }

        @keyframes mobileCardFloat {
          0%,
          100% {
            box-shadow:
              0 5px 16px
              rgba(25, 60, 42, 0.04);
          }

          50% {
            box-shadow:
              0 9px 22px
              rgba(25, 135, 84, 0.065);
          }
        }

        @keyframes mobileNumberFloat {
          0%,
          100% {
            transform: translateY(0);
          }

          50% {
            transform: translateY(-2px);
          }
        }

        @keyframes emptyFloat {
          0%,
          100% {
            transform:
              translateY(0)
              rotate(0deg);
          }

          50% {
            transform:
              translateY(-6px)
              rotate(-2deg);
          }
        }

        @keyframes errorPulse {
          0%,
          100% {
            transform: scale(1);
          }

          50% {
            transform: scale(1.035);
          }
        }

        @keyframes skeletonFlow {
          from {
            background-position: 200% 0;
          }

          to {
            background-position: -200% 0;
          }
        }

        /* =====================================================
           RESPONSIVE
        ===================================================== */

        @media (max-width: 992px) {
          .edit-articles-page {
            padding-top: 105px;
          }

          .articles-card-header {
            padding: 22px;
          }

          .articles-table thead th:first-child,
          .articles-table tbody td:first-child {
            padding-left: 22px;
          }

          .articles-table thead th:last-child,
          .articles-table tbody td:last-child {
            padding-right: 22px;
          }

          .articles-table thead th,
          .articles-table tbody td {
            padding-left: 13px;
            padding-right: 13px;
          }
        }

        @media (max-width: 768px) {
          .edit-articles-page {
            padding:
              95px
              0
              65px;
          }

          .edit-articles-header {
            margin-bottom: 25px;
          }

          .edit-articles-header h1 {
            font-size: 30px;
          }

          .edit-articles-header p {
            padding: 0 15px;

            font-size: 12px;
          }

          .articles-card {
            border-radius: 18px;
          }

          .articles-card-header {
            display: block;

            padding: 19px;
          }

          .card-header-left {
            margin-bottom: 17px;
          }

          .article-summary {
            width: 100%;
          }

          .summary-item {
            flex: 1;
          }

          /*
            Desktop table disembunyikan
            di mobile.
          */

          .table-container {
            display: none;
          }

          .mobile-articles {
            display: block;
          }
        }

        @media (max-width: 480px) {
          .edit-articles-header h1 {
            font-size: 27px;
          }

          .header-badge {
            font-size: 9px;
          }

          .card-header-left h2 {
            font-size: 14px;
          }

          .card-header-left p {
            font-size: 10px;
          }

          .card-header-icon {
            width: 40px;
            height: 40px;

            flex-basis: 40px;
          }

          .summary-item {
            min-width: 0;

            padding:
              8px
              7px;
          }

          .summary-number {
            font-size: 13px;
          }

          .summary-label {
            font-size: 8px;
          }

          .mobile-articles {
            padding: 13px;
          }

          .mobile-article-item {
            padding: 14px;
          }

          .mobile-meta {
            grid-template-columns: 1fr;
          }
        }

        @media (prefers-reduced-motion: reduce) {
          *,
          *::before,
          *::after {
            animation-duration: 0.01ms !important;

            animation-iteration-count:
              1 !important;

            transition-duration:
              0.01ms !important;
          }
        }
      `}</style>

      <main className="edit-articles-page">
        <div className="container">
          <div className="edit-articles-wrapper">

            {/* =================================================
                HEADER
            ================================================= */}

            <div className="edit-articles-header">

              <div className="header-badge">
                <span className="header-badge-dot" />

                Article Management
              </div>

              <h1>
                Edit My Articles
              </h1>

              <p>
                Manage and update the articles you have
                created. Only your own articles are displayed
                on this page.
              </p>

            </div>

            {/* =================================================
                MAIN CARD
            ================================================= */}

            <div className="articles-card">

              {/* =================================================
                  CARD HEADER
              ================================================= */}

              <div className="articles-card-header">

                <div className="card-header-left">

                  <div className="card-header-icon">
                    ✎
                  </div>

                  <div>
                    <h2>
                      My Articles
                    </h2>

                    <p>
                      Articles created by your account
                    </p>
                  </div>

                </div>

                {!loading &&
                  !error &&
                  articles.length > 0 && (

                    <div className="article-summary">

                      <div className="summary-item">

                        <span className="summary-number">
                          {articles.length}
                        </span>

                        <span className="summary-label">
                          Total
                        </span>

                      </div>

                      <div className="summary-item summary-published">

                        <span className="summary-number">
                          {publishedCount}
                        </span>

                        <span className="summary-label">
                          Published
                        </span>

                      </div>

                      <div className="summary-item">

                        <span className="summary-number">
                          {draftCount}
                        </span>

                        <span className="summary-label">
                          Draft
                        </span>

                      </div>

                    </div>

                  )}

              </div>

              {/* =================================================
                  LOADING
              ================================================= */}

              {loading ? (

                <div className="loading-state">

                  {[1, 2, 3, 4].map(
                    (item) => (

                      <div
                        className="loading-row"
                        key={item}
                      >

                        <div className="skeleton skeleton-small" />

                        <div>

                          <div className="skeleton mb-2" />

                          <div className="skeleton skeleton-short" />

                        </div>

                        <div className="skeleton" />

                        <div className="skeleton" />

                        <div className="skeleton" />

                        <div className="skeleton skeleton-button" />

                      </div>

                    )
                  )}

                </div>

              ) : error ? (

                /* =================================================
                   ERROR
                ================================================= */

                <div className="error-state">

                  <div className="error-icon">
                    !
                  </div>

                  <h5>
                    Unable to Load Articles
                  </h5>

                  <p className="error-message">
                    {error}
                  </p>

                </div>

              ) : articles.length === 0 ? (

                /* =================================================
                   EMPTY
                ================================================= */

                <div className="empty-state">

                  <div className="empty-icon">
                    ✎
                  </div>

                  <h5>
                    No Articles Yet
                  </h5>

                  <p>
                    You have not created any articles yet.
                    Create your first article to start
                    sharing your content.
                  </p>

                  <Link
                    href="/articles/create"
                    className="empty-button"
                  >
                    <span>
                      +
                    </span>

                    Add Article
                  </Link>

                </div>

              ) : (

                <>
                  {/* =================================================
                      DESKTOP TABLE
                  ================================================= */}

                  <div className="table-container">

                    <table className="table articles-table">

                      <thead>

                        <tr>

                          <th>
                            No
                          </th>

                          <th>
                            Article
                          </th>

                          <th>
                            Category
                          </th>

                          <th>
                            Status
                          </th>

                          <th>
                            Published
                          </th>

                          <th>
                            Action
                          </th>

                        </tr>

                      </thead>

                      <tbody>

                        {articles.map(
                          (
                            article,
                            index
                          ) => (

                            <tr
                              key={article.id}
                            >

                              {/* NUMBER */}

                              <td>

                                <div className="article-number">

                                  {String(
                                    index + 1
                                  ).padStart(
                                    2,
                                    "0"
                                  )}

                                </div>

                              </td>

                              {/* ARTICLE */}

                              <td>

                                <div className="article-info">

                                  <div className="article-title">
                                    {article.title}
                                  </div>

                                  <div className="article-slug">
                                    /{article.slug}
                                  </div>

                                </div>

                              </td>

                              {/* CATEGORY */}

                              <td>

                                {article.category ? (

                                  <span className="category-badge">
                                    {article.category}
                                  </span>

                                ) : (

                                  <span className="category-empty">
                                    No category
                                  </span>

                                )}

                              </td>

                              {/* STATUS */}

                              <td>

                                {article.published ? (

                                  <span className="status-badge status-published">

                                    <span className="status-dot" />

                                    Published

                                  </span>

                                ) : (

                                  <span className="status-badge status-draft">

                                    <span className="status-dot" />

                                    Draft

                                  </span>

                                )}

                              </td>

                              {/* DATE */}

                              <td>

                                {article.publishedAt ? (

                                  <span className="published-date">

                                    <span className="date-icon">
                                      ●
                                    </span>

                                    {new Date(
                                      article.publishedAt
                                    ).toLocaleDateString(
                                      "id-ID",
                                      {
                                        day: "2-digit",
                                        month: "short",
                                        year: "numeric",
                                      }
                                    )}

                                  </span>

                                ) : (

                                  <span className="no-date">
                                    Not published
                                  </span>

                                )}

                              </td>

                              {/* ACTION */}

                              <td>

                                <Link
                                  href={`/articles/edit/${article.id}`}
                                  className="edit-button"
                                >

                                  Edit

                                  <span className="edit-arrow">
                                    →
                                  </span>

                                </Link>

                              </td>

                            </tr>

                          )
                        )}

                      </tbody>

                    </table>

                  </div>

                  {/* =================================================
                      MOBILE
                  ================================================= */}

                  <div className="mobile-articles">

                    {articles.map(
                      (
                        article,
                        index
                      ) => (

                        <div
                          className="mobile-article-item"
                          key={article.id}
                          style={{
                            animationDelay: `${
                              index * 70
                            }ms`,
                          }}
                        >

                          <div className="mobile-top">

                            <div className="mobile-number">

                              {String(
                                index + 1
                              ).padStart(
                                2,
                                "0"
                              )}

                            </div>

                            <div className="mobile-title-wrapper">

                              <h3 className="mobile-title">
                                {article.title}
                              </h3>

                              <div className="mobile-slug">
                                /{article.slug}
                              </div>

                            </div>

                            {article.published ? (

                              <span className="status-badge status-published">

                                <span className="status-dot" />

                                Published

                              </span>

                            ) : (

                              <span className="status-badge status-draft">

                                <span className="status-dot" />

                                Draft

                              </span>

                            )}

                          </div>

                          <div className="mobile-meta">

                            <div className="mobile-meta-item">

                              <span className="mobile-meta-label">
                                Category
                              </span>

                              <span className="mobile-meta-value">
                                {article.category ||
                                  "No category"}
                              </span>

                            </div>

                            <div className="mobile-meta-item">

                              <span className="mobile-meta-label">
                                Published
                              </span>

                              <span className="mobile-meta-value">

                                {article.publishedAt
                                  ? new Date(
                                      article.publishedAt
                                    ).toLocaleDateString(
                                      "id-ID",
                                      {
                                        day: "2-digit",
                                        month: "short",
                                        year: "numeric",
                                      }
                                    )
                                  : "Not published"}

                              </span>

                            </div>

                          </div>

                          <Link
                            href={`/articles/edit/${article.id}`}
                            className="edit-button mobile-action"
                          >

                            Edit Article

                            <span className="edit-arrow">
                              →
                            </span>

                          </Link>

                        </div>

                      )
                    )}

                  </div>
                </>

              )}

            </div>

          </div>
        </div>
      </main>

      <Footer />
    </>
  );
}