import { Box } from "@mui/material";
import RegisterInsurance from "../Form/RegisterInsurance";
import CreateFactor from "../Form/CreateFactor";
import DeleteDialog from "./DeleteDialog";
import SendToInsurance from "./SendToInsurance";
import PoliceRahLetter from "./PoliceRahLetter";
import EditForm from "../Form/EditForm";
import { usePermissions } from "@/lib/hooks/usePermissions";
import ChangeStatus from "./ChangeStatus";

const RowActions = ({ row, mutate }) => {
    const { data: userPermissions } = usePermissions();
    const hasChangeStatusPermission = userPermissions.some((item) => ["change-accident-status"].includes(item));
    const hasDeletePermission = userPermissions.some((item) => ["delete-receipt"].includes(item));
    const hasDeleteProvincePermission = userPermissions.some((item) => ["delete-receipt-province"].includes(item));
    const hasEditPermission = userPermissions.some((item) => ["edit-receipt", "edit-receipt-province"].includes(item));
    return (
        <Box sx={{ display: "flex", gap: 1 }}>
            {[4, 5].includes(row.original?.status) && <PoliceRahLetter mutate={mutate} rowId={row.getValue("id")} />}
            {[2, 3].includes(row.original?.status) && (
                <CreateFactor row={row} rowId={row.getValue("id")} mutate={mutate} />
            )}
            {[1, 2].includes(row.original?.status) && (
                <RegisterInsurance mutate={mutate} row={row} rowId={row.getValue("id")} />
            )}
            {[0, 1, 2].includes(row.original?.status) && <SendToInsurance mutate={mutate} rowId={row.getValue("id")} />}
            {hasEditPermission && [0].includes(row.original?.status) && (
                <EditForm row={row} mutate={mutate} rowId={row.getValue("id")} />
            )}
            {(hasDeletePermission || (hasDeleteProvincePermission && [0].includes(row.original?.status))) && (
                <DeleteDialog mutate={mutate} rowId={row.getValue("id")} />
            )}
            {hasChangeStatusPermission && <ChangeStatus mutate={mutate} row={row} />}
        </Box>
    );
};
export default RowActions;
