"use client";

import { useEffect, useState } from "react";
import ArticleTable from "@/components/table/article-table";
import { Button } from "@/components/ui/button";
import { Plus } from "lucide-react";
import { BannerDialog } from "@/components/form/banner-dialog";
import Link from "next/link";
import ProductTable from "@/components/table/product-table";
import AgentTable from "@/components/table/agent-table";
import withReactContent from "sweetalert2-react-content";
import Swal from "sweetalert2";
import Cookies from "js-cookie";
import { useRouter } from "next/navigation";

export default function AgentPage() {
  const [openDialog, setOpenDialog] = useState(false);

  const [userRoleId, setUserRoleId] = useState<string | null>(null);

  const router = useRouter();
  const MySwal = withReactContent(Swal);

  // 🔹 Ambil userlevelId dari cookies
  useEffect(() => {
    const urie = Cookies.get("urie"); // contoh: "3"
    setUserRoleId(urie ?? null);
  }, []);

  const handleSubmitBanner = (data: any) => {
    console.log("Banner Data:", data);
  };

  return (
    <div>
      <div className="overflow-x-hidden overflow-y-scroll w-full">
        <div className="px-2 md:px-4 md:py-4 w-full">
          <div className="pl-3">
            <h1 className="text-[#1F6779] text-2xl font-semibold">Agent</h1>
            <p>Kelola Agent JAECOO</p>
          </div>

          <div className="dark:bg-[#18181b] rounded-xl p-3">
            {userRoleId !== "1" && (
              <Link href={"/admin/agent/create"}>
                <Button className="bg-[#1F6779] text-white w-full lg:w-fit hover:bg-[#1a9bb5] flex items-center gap-2">
                  <Plus className="h-4 w-4" />
                  Tambah Agent
                </Button>
              </Link>
            )}
            <AgentTable />
          </div>
        </div>
      </div>
    </div>
  );
}
