"use client";
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
import { GET_ROAD_MISSIONS_VIOLATIONS_LIST } from "@/core/utils/routes";
import { Box } from "@mui/material";
import moment from "jalali-moment";
import { useMemo } from "react";
import RowActions from "./RowActions";

const ViolationsList = () => {
    const columns = useMemo(
        () => [
            {
                accessorKey: "id",
                header: "کد یکتا",
                id: "id",
                enableColumnFilter: true,
                datatype: "text",
                filterMode: "equals",
                columnFilterModeOptions: ["equals", "contains"],
                grow: false,
            },
            {
                accessorKey: "type",
                header: "نوع تخلف",
                id: "type",
                enableColumnFilter: true,
                datatype: "numeric",
                filterMode: "equals",
                sortDescFirst: true,
                grow: false,
                Cell: ({ row }) => (row.original.type === 1 ? "خروج بدون مجوز" : "عدم تحرک"),
            },
            {
                accessorKey: "machine_code",
                header: "خودرو",
                id: "machine_code",
                datatype: "text",
                columnFilterModeOptions: ["equals", "contains"],
                grow: false,
            },
            {
                accessorKey: "mission_id",
                header: "کد ماموریت",
                id: "mission_id",
                enableColumnFilter: false,
                datatype: "numeric",
                filterMode: "equals",
                grow: false,
                Cell: ({ row }) => row.original.mission_id || "-",
            },
            {
                accessorKey: "request_date",
                header: "تاریخ تخلف",
                id: "request_date",
                enableColumnFilter: true,
                datatype: "date",
                filterMode: "between",
                grow: false,
                Cell: ({ row }) => moment(row.original.request_date).locale("fa").format("YYYY/MM/DD"),
            },
        ],
        []
    );

    return (
        <>
            <Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
                <DataTableWithAuth
                    need_filter={true}
                    columns={columns}
                    sorting={[{ id: "id", desc: true }]}
                    table_url={GET_ROAD_MISSIONS_VIOLATIONS_LIST}
                    page_name={"roadMissionsOperator"}
                    table_name={"roadMissionsViolationsList"}
                    enableRowActions
                    positionActionsColumn={"first"}
                    RowActions={RowActions}
                />
            </Box>
        </>
    );
};
export default ViolationsList;
