"use client"; import * as React from "react"; import { ColumnDef } from "@tanstack/react-table"; import { Eye, MoreVertical, CheckCircle, Clock } from "lucide-react"; import { cn, getCookiesDecrypt } from "@/lib/utils"; import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, DropdownMenuItem, } from "@/components/ui/dropdown-menu"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { format } from "date-fns"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { PendingApprovalData } from "@/service/content/content"; const usePendingApprovalColumns = () => { const router = useRouter(); const userLevelId = getCookiesDecrypt("ulie"); const columns: ColumnDef[] = [ { accessorKey: "id", header: "No", cell: ({ row, table }) => { const pageIndex = table.getState().pagination.pageIndex; const pageSize = table.getState().pagination.pageSize; const rowIndex = row.index; console.log("pageIndex :", pageIndex); console.log("pageSize :", pageSize); console.log("rowIndex :", rowIndex); console.log("calculated number :", pageIndex * pageSize + rowIndex + 1); return (

{pageIndex * pageSize + rowIndex + 1}

); }, }, { accessorKey: "title", header: "Title", cell: ({ row }: { row: { getValue: (key: string) => string } }) => { const title: string = row.getValue("title"); return ( {title.length > 50 ? `${title.slice(0, 30)}...` : title} ); }, }, { accessorKey: "categoryName", header: "Category", cell: ({ row }) => { const categoryName = row.getValue("categoryName") as string; return ( {categoryName || "-"} ); }, }, { accessorKey: "authorName", header: "Author", cell: ({ row }) => ( {row.getValue("authorName")} ), }, { accessorKey: "submittedAt", header: "Submitted Date", cell: ({ row }) => { const submittedAt = row.getValue("submittedAt") as string; const formattedDate = submittedAt ? format(new Date(submittedAt), "dd-MM-yyyy HH:mm:ss") : "-"; return {formattedDate}; }, }, { accessorKey: "priority", header: "Priority", cell: ({ row }) => { const priority = row.getValue("priority") as string; const colors: Record = { high: "bg-red-100 text-red-600", medium: "bg-yellow-100 text-yellow-600", low: "bg-green-100 text-green-600", }; const priorityStyles = colors[priority] || "bg-gray-100 text-gray-600"; return ( {priority?.toUpperCase() || "N/A"} ); }, }, { accessorKey: "currentStep", header: "Progress", cell: ({ row }) => { const currentStep = row.getValue("currentStep") as number; const totalSteps = row.original.totalSteps; const progress = totalSteps > 0 ? (currentStep / totalSteps) * 100 : 0; return (
{currentStep}/{totalSteps}
); }, }, { accessorKey: "daysInQueue", header: "Days in Queue", cell: ({ row }) => { const days = row.getValue("daysInQueue") as number; const colorClass = days > 7 ? "text-red-600" : days > 3 ? "text-yellow-600" : "text-green-600"; return (
{days} days
); }, }, { accessorKey: "estimatedTime", header: "Est. Time", cell: ({ row }) => ( {row.getValue("estimatedTime") || "-"} ), }, { id: "actions", accessorKey: "action", header: "Action", enableHiding: false, cell: ({ row }) => { const canApprove = row.original.canApprove; return ( View {/* {canApprove && ( { // Handle approval logic here console.log("Approve item:", row.original.id); }} > Approve )} */} ); }, }, ]; return columns; }; export default usePendingApprovalColumns;