// material-ui
import * as React from 'react';
import * as DateUtils from "utils/DateUtils";
import { useNavigate } from "react-router-dom";
import { FiDataGrid } from "components/FiDataGrid";
import {useIntl} from "react-intl";
import { clickableLink } from 'utils/CommonFunction';
// ==============================|| EVENT TABLE ||============================== //

export default function MsgTable({ recordList }) {
    const [rows, setRows] = React.useState(recordList);
    const navigate = useNavigate()
    const intl = useIntl();

    const _sx = {
        padding: "4 2 4 2",
        boxShadow: 1,
        border: 1,
        borderColor: '#DDD',
        '& .MuiDataGrid-cell': {
            borderTop: 1,
            borderBottom: 1,
            borderColor: "#EEE"
        },
        '& .MuiDataGrid-footerContainer': {
            border: 1,
            borderColor: "#EEE"
        }
    }

    React.useEffect(() => {
        setRows(recordList);
    }, [recordList]);

    const handleEditClick = (params) => () => {
        navigate('/msg/details/' + params.row.id);
    };

    const columns = [
        {
            id: 'sentDate',
            field: 'sentDate',
            headerName: intl.formatMessage({id: 'date'}),
            width: 160,
            renderCell: (params) => {
                return DateUtils.datetimeStr(params.row.sentDate);
            },
        },
        {
            field: 'actions',
            headerName: intl.formatMessage({id: 'payId'}),
            flex: 1 ,
            cellClassName: 'actions',
            renderCell: (params) => {
                return clickableLink('/msg/details/' + params.row.id, params.row.subject);
            },
        },
    ];

    return (
        <div style={{ minHeight: 400, width: '100%' }}>

            <FiDataGrid
                sx={_sx}
                rowHeight={80}
                rows={rows}
                columns={columns}
                customPageSize={20}
                onRowDoubleClick={handleEditClick}
            />
        </div>
    );
}
