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

const DataTable = () => {
    const columns = useMemo(
        () => [
            {
                accessorKey: "id",
                header: "کد یکتا",
                id: "id",
                enableColumnFilter: true,
                datatype: "text",
                filterMode: "equals",
                sortDescFirst: false,
                columnFilterModeOptions: ["equals", "contains"],
                grow: false,
                size: 100,
            },
            {
                accessorKey: "name_fa",
                header: "نام",
                id: "name_fa",
                enableColumnFilter: true,
                datatype: "text",
                filterMode: "equals",
                sortDescFirst: false,
                columnFilterModeOptions: ["equals", "contains"],
                grow: false,
                size: 100,
            },
            {
                accessorKey: "created_at",
                header: "تاریخ ساخت",
                id: "created_at",
                enableColumnFilter: false,
                datatype: "date",
                filterMode: "equals",
                grow: false,
                size: 100,
                Cell: ({ renderedCellValue }) => (
                    <Typography variant="body2">
                        {renderedCellValue ? moment(renderedCellValue).locale("fa").format("HH:mm | YYYY/MM/DD") : "-"}
                    </Typography>
                ),
            },
            {
                accessorKey: "updated_at",
                header: "تاریخ آخرین بروزرسانی",
                id: "updated_at",
                enableColumnFilter: false,
                datatype: "date",
                filterMode: "equals",
                grow: false,
                size: 100,
                Cell: ({ renderedCellValue }) => (
                    <Typography variant="body2">
                        {renderedCellValue ? moment(renderedCellValue).locale("fa").format("HH:mm | YYYY/MM/DD") : "-"}
                    </Typography>
                ),
            },
        ],
        []
    );

    return (
        <>
            <Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
                <DataTableWithAuth
                    need_filter={true}
                    columns={columns}
                    sorting={[{ id: "id", desc: true }]}
                    table_url={ROLE_SERVICE}
                    page_name={"rolesPage"}
                    table_name={"rolesList"}
                    TableToolbar={Toolbar}
                    enableRowActions
                    positionActionsColumn={"last"}
                    RowActions={RowActions}
                />
            </Box>
        </>
    );
};
export default DataTable;
