import { Box, Stack, Typography } from "@mui/material";
import { useMemo } from "react";
import { GET_REFAHI_PASSENGER_BOSS_RESTORE } from "@/core/data/apiRoutes";
import { useTranslations } from "next-intl";
import TableRowActions from "./TableRowActions";
import moment from "jalali-moment";
import DataTable from "@/core/components/DataTable";
import MuiDatePicker from "@/core/components/MuiDatePicker";
import TableToolbar from "./TableToolbar";

function DashboardPassengerOfficeComponent() {
    const t = useTranslations();

    const columns = useMemo(
        () => [
            {
                accessorFn: (row) => row.id,
                id: "id",
                header: t("PassengerBoss.id"),
                enableColumnFilter: true,
                datatype: "numeric",
                filterFn: "equals",
                columnFilterModeOptions: ["equals", "notEquals", "contains", "lessThan", "greaterThan", "between"],
                Cell: ({ renderedCellValue }) => <Typography variant="body2">{renderedCellValue}</Typography>,
            },
            {
                accessorFn: (row) => row.project_title,
                id: "project_title",
                header: t("PassengerBoss.project_title"),
                enableColumnFilter: false,
                datatype: "text",
                filterFn: "equals",
                columnFilterModeOptions: ["equals", "notEquals", "contains", "lessThan", "greaterThan", "between"],
                Cell: ({ renderedCellValue }) => <Typography variant="body2">{renderedCellValue}</Typography>,
            },
            {
                accessorFn: (row) => row.is_legal_person,
                id: "is_legal_person",
                header: t("PassengerBoss.is_legal_person"),
                enableColumnFilter: false,
                datatype: "numeric",
                filterFn: "equals",
                columnFilterModeOptions: ["equals"],
                Cell: ({ renderedCellValue }) => (
                    <Typography variant="body2">
                        {renderedCellValue === 1 ? `${t("PassengerBoss.hoghoghi")}` : `${t("PassengerBoss.haghighi")}`}
                    </Typography>
                ),
            },
            {
                accessorFn: (row) =>
                    row.is_legal_person === 1 ? `${row.company_name}` : `${row.first_name} ${row.last_name}`,
                id: "name",
                header: t("PassengerBoss.first_name"),
                enableColumnFilter: false,
                datatype: "text",
                filterFn: "contains",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({ renderedCellValue }) => <Typography variant="body2">{renderedCellValue}</Typography>,
            },
            {
                accessorFn: (row) => row.national_id,
                id: "national_id",
                header: t("PassengerBoss.national_id"),
                enableColumnFilter: true,
                datatype: "numeric",
                filterFn: "equals",
                columnFilterModeOptions: ["equals", "notEquals", "contains", "lessThan", "greaterThan", "between"],
                Cell: ({ renderedCellValue }) => <Typography variant="body2">{renderedCellValue}</Typography>,
            },
            {
                accessorFn: (row) => row.shenase_meli,
                id: "shenase_meli",
                header: t("PassengerBoss.shenase_meli"),
                enableColumnFilter: true,
                datatype: "numeric",
                filterFn: "equals",
                columnFilterModeOptions: ["equals", "notEquals", "contains", "lessThan", "greaterThan", "between"],
                Cell: ({ renderedCellValue }) => <Typography variant="body2">{renderedCellValue}</Typography>,
            },
            {
                accessorFn: (row) => row.project_province_name,
                id: "project_province_name",
                header: t("PassengerBoss.province_name"),
                enableColumnFilter: true,
                datatype: "text",
                filterFn: "contains",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({ renderedCellValue }) => <Typography variant="body2">{renderedCellValue}</Typography>,
            },
            {
                accessorFn: (row) => row.project_city_name,
                id: "project_city_name",
                header: t("PassengerBoss.city_name"),
                enableColumnFilter: true,
                datatype: "text",
                filterFn: "contains",
                columnFilterModeOptions: ["contains", "equals", "notEquals"],
                Cell: ({ renderedCellValue }) => <Typography variant="body2">{renderedCellValue}</Typography>,
            },
            {
                accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"),
                id: "created_at",
                header: t("PassengerBoss.created_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} />;
                },
            },
            {
                accessorFn: (row) => row.phone_number,
                id: "phone_number",
                header: t("PassengerBoss.phone_number"),
                enableColumnFilter: true,
                datatype: "numeric",
                filterFn: "equals",
                columnFilterModeOptions: ["equals", "notEquals", "contains", "lessThan", "greaterThan", "between"],
                Cell: ({ renderedCellValue }) => <Typography variant="body2">{renderedCellValue}</Typography>,
            },
            {
                accessorFn: (row) => row.state_name,
                id: "state_id",
                header: t("PassengerBoss.state_name"),
                enableColumnFilter: false,
                datatype: "numeric",
                Cell: ({ renderedCellValue }) => <Typography variant="body2">{renderedCellValue}</Typography>,
            },
        ],
        []
    );
    return (
        <Box sx={{ px: 3 }}>
            <DataTable
                tableUrl={GET_REFAHI_PASSENGER_BOSS_RESTORE}
                columns={columns}
                selectableRow={false}
                enableCustomToolbar={true}
                CustomToolbar={TableToolbar}
                enableLastUpdate={true}
                enablePinning={true}
                enableDensityToggle={false}
                initialState={{ density: "compact" }}
                enableColumnFilters={true}
                enableHiding={true}
                enableFullScreenToggle={false}
                enableGlobalFilter={false}
                enableColumnResizing={false}
                enableRowActions={true}
                TableRowAction={TableRowActions}
            />
        </Box>
    );
}

export default DashboardPassengerOfficeComponent;
