import * as React from "react";
import { ColumnDef } from "@tanstack/react-table";

import { Eye, MoreVertical, SquarePen, Trash2 } from "lucide-react";
import { cn } from "@/lib/utils";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuTrigger,
  DropdownMenuItem,
} from "@/components/ui/dropdown-menu";
import { Button } from "@/components/ui/button";
import { Link } from "@/components/navigation";

const columns: ColumnDef<any>[] = [
  {
    accessorKey: "no",
    header: "No",
    cell: ({ row }) => <span>{row.getValue("no")}</span>,
  },

  {
    accessorKey: "fullname",
    header: "Nama",
    cell: ({ row }) => <span>{row.getValue("fullname")}</span>,
  },
  {
    accessorKey: "address",
    header: "Wilayah",
    cell: ({ row }) => <span>{row.getValue("address")}</span>,
  },
  {
    accessorKey: "experience",
    header: "Posisi",
    cell: ({ row }) => <span>{row.getValue("experience")}</span>,
  },
  {
    accessorKey: "role.name",
    header: "Bidang Keahlian",
    cell: ({ row }) => (
      <span>
        {row.original.userProfilesAdditional?.userCompetency?.name ?? "-"}
      </span>
    ),
  },

  {
    accessorKey: "userExperienceId", // gunakan accessorKey berbeda agar tidak duplikat
    header: "Pengalaman",
    cell: ({ row }) => {
      const experienceId =
        row.original.userProfilesAdditional?.userExperienceId;

      const experienceMap: Record<number, string> = {
        1: "Akademisi",
        2: "Praktisi",
        3: "Akademisi + Praktisi",
      };

      return <span>{experienceMap[experienceId] ?? "-"}</span>;
    },
  },

  {
    id: "actions",
    accessorKey: "action",
    header: "Actions",
    enableHiding: false,
    cell: ({ row }) => {
      return (
        <DropdownMenu>
          <DropdownMenuTrigger asChild>
            <Button
              size="icon"
              className="bg-transparent ring-offset-transparent hover:bg-transparent hover:ring-0 hover:ring-transparent"
            >
              <MoreVertical className="h-4 w-4 text-default-800" />
            </Button>
          </DropdownMenuTrigger>
          <DropdownMenuContent className="p-0" align="end">
            <Link href={`/admin/add-experts/detail/${row?.original?.id}`}>
              <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
                <Eye className="w-4 h-4 me-1.5" />
                View
              </DropdownMenuItem>
            </Link>

            <Link href={`/admin/add-experts/update/${row?.original?.id}`}>
              <DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
                <SquarePen className="w-4 h-4 me-1.5" />
                Edit
              </DropdownMenuItem>
            </Link>
            <DropdownMenuItem
              // onClick={() => handleDeleteMedia(row.original.id)}
              className="p-2 border-b text-destructive bg-destructive/30  focus:bg-destructive focus:text-destructive-foreground rounded-none"
            >
              <Trash2 className="w-4 h-4 me-1.5" />
              Delete
            </DropdownMenuItem>
          </DropdownMenuContent>
        </DropdownMenu>
      );
    },
  },
];

export default columns;
