import { Button, Checkbox } from "@material-ui/core";
import { GridColumns } from "@material-ui/data-grid";
import { TFunction } from "i18next";
import { IAddress } from "../../../../../../Application/DTOs/AddressDto/AddressDto.types";





export const getCommonAddressColumns = (t: TFunction, onUpdateStatusCallback: (addressId: string | number, newStatus: boolean) => void, onDelete: (addressId: string | number) => void): GridColumns => {


    return [
        {
            field: 'country',
            headerName: t('country'),
            width: 200,
            valueGetter: (params) => t((params.row as IAddress).country)
        },
        {
            field: 'company_name',
            headerName: t('company_name'),
            width: 200
        },
        {
            field: 'actions',
            headerName: t('disabled'),
            width: 200,
            sortable: false,
            disableClickEventBubbling: true,
            renderCell: (params) => {
                const address = params.row as IAddress
                return <Checkbox color="primary" checked={address.is_disabled} onChange={(e) => onUpdateStatusCallback(address.id, e.target.checked)} />
            }
        }
        ,
        {
            field: 'delete',
            headerName: t('delete'),
            width: 200,
            sortable: false,
            disableClickEventBubbling: true,
            renderCell: (params) => {
                const address = params.row as IAddress
                return <Button onClick={() => onDelete(address.id)} variant="contained" color="secondary">{t('delete')}</Button>
            }
        }
    ]
}