import DashboardLayouts from "@/layouts/dashboardLayouts";
import {Box, Typography} from "@mui/material";
import {useMemo} from "react";
import {GET_EXPERT_MANAGEMENT} from "@/core/data/apiRoutes";
import {useTranslations} from "next-intl";
import TableRowActions from "./TableRowActions";
import DataTable from "@/core/components/DataTable";
import TableToolbar from "@/components/dashboard/expert-management/TableToolbar";
import moment from "jalali-moment";
import MuiDatePicker from "@/core/components/MuiDatePicker";

function DashboardExpertManagementComponent() {
    const t = useTranslations();
    const columns = useMemo(
        () => [
            {
                accessorFn: (row) => row.id,
                id: "id",
                header: t("ExpertMangement.id"),
                enableColumnFilter: true,
                datatype: "numeric",
                filterFn: "equals",
                columnFilterModeOptions: [
                    "equals",
                    "notEquals",
                    "contains",
                    "lessThan",
                    "greaterThan",
                    "between",
                ],
                Cell: ({renderedCellValue}) => (
                    <Typography variant="body2">{renderedCellValue}</Typography>
                ),
            },
            {
                accessorFn: (row) => row.name,
                id: "name",
                header: t("ExpertMangement.name"),
                enableColumnFilter: true,
                datatype: "text",
                filterFn: "contains",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({renderedCellValue}) => (
                    <Typography variant="body2">{renderedCellValue}</Typography>
                ),
            },
            {
                accessorFn: (row) => row.username,
                id: "username",
                header: t("ExpertMangement.username"),
                enableColumnFilter: true,
                datatype: "text",
                filterFn: "contains",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({renderedCellValue}) => (
                    <Typography variant="body2">{renderedCellValue}</Typography>
                ),
            },
            {
                accessorFn: (row) => row.email,
                id: "email",
                header: t("ExpertMangement.email"),
                enableColumnFilter: true,
                datatype: "text",
                filterFn: "contains",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({renderedCellValue}) => (
                    <Typography variant="body2">{renderedCellValue}</Typography>
                ),
            },
            {
                accessorFn: (row) => row.phone_number,
                id: "phone_number",
                header: t("ExpertMangement.phone_number"),
                enableColumnFilter: true,
                datatype: "numeric",
                filterFn: "equals",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({renderedCellValue}) => (
                    <Typography variant="body2">{renderedCellValue}</Typography>
                ),
            },
            {
                accessorFn: (row) => row.national_id,
                id: "national_id",
                header: t("ExpertMangement.national_id"),
                enableColumnFilter: true,
                datatype: "numeric",
                filterFn: "equals",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({renderedCellValue}) => (
                    <Typography variant="body2">{renderedCellValue}</Typography>
                ),
            },
            {
                accessorFn: (row) => row.position,
                id: "position",
                header: t("ExpertMangement.position"),
                enableColumnFilter: true,
                datatype: "text",
                filterFn: "contains",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({renderedCellValue}) => (
                    <Typography variant="body2">{renderedCellValue}</Typography>
                ),
            },
            {
                accessorFn: (row) => row.province_name,
                id: "province_name",
                header: t("ExpertMangement.province_name"),
                enableColumnFilter: false,
                datatype: "text",
                filterFn: "contains",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({renderedCellValue}) => (
                    <Typography variant="body2">{renderedCellValue}</Typography>
                ),
            },
            {
                accessorFn: (row) => row.city_name,
                id: "city_name",
                header: t("ExpertMangement.city_name"),
                enableColumnFilter: false,
                datatype: "text",
                filterFn: "contains",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({renderedCellValue}) => (
                    <Typography variant="body2">{renderedCellValue}</Typography>
                ),
            },
            {
                accessorFn: (row) => row.roles[0].name_fa,
                id: "roles[0].name_fa",
                header: t("ExpertMangement.role_name"),
                enableColumnFilter: false,
                datatype: "text",
                filterFn: "contains",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({renderedCellValue}) => (
                    <Typography variant="body2">{renderedCellValue}</Typography>
                ),
            },
            {
                accessorFn: (row) =>
                    moment(row.updated_at).locale("fa").format("HH:mm | yyyy/MM/DD"),
                id: "updated_at",
                header: t("ExpertMangement.updated_at"),
                enableColumnFilter: true,
                datatype: "date",
                filterFn: "lessThan",
                columnFilterModeOptions: ["lessThan", "greaterThan"],
                Cell: ({renderedCellValue}) => {
                    return <Typography variant="body2">{renderedCellValue}</Typography>;
                },
                Header: ({column}) => <>{column.columnDef.header}</>,
                Filter: ({column}) => {
                    return (
                        <MuiDatePicker column={column}/>
                    );
                },
            },
        ],
        []
    );
    return (
        <DashboardLayouts>
            <Box sx={{px: 3}}>
                <DataTable
                    tableUrl={GET_EXPERT_MANAGEMENT}
                    columns={columns}
                    selectableRow={false}
                    CustomToolbar={TableToolbar}
                    enableCustomToolbar={true}
                    enableLastUpdate={true}
                    enablePinning={true}
                    enableDensityToggle={false}
                    initialState={{density: 'compact'}} //compact (small) //comfortable (medium) //spacious (large)
                    enableColumnFilters={true}
                    enableHiding={true}
                    enableFullScreenToggle={false}
                    enableGlobalFilter={false}
                    enableColumnResizing={false} // if you want true this you should change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions
                    enableRowActions={true}
                    TableRowAction={TableRowActions}
                />
            </Box>
        </DashboardLayouts>
    );
}

export default DashboardExpertManagementComponent;
