// material-ui
import * as React from 'react';
import {FiDataGrid} from "components/FiDataGrid";
import {
    // Button,
    // Typography, 
    useMediaQuery
} from '@mui/material';
import * as DateUtils from "utils/DateUtils"
import {GET_LOGIN_LOG_LIST } from "utils/ApiPathConst";
import {useTheme} from "@emotion/react";

// ==============================|| EVENT TABLE ||============================== //

export default function LoginGrid({u1}) {
    // const navigate = useNavigate()
    const theme = useTheme();
    const isMdOrLg = useMediaQuery(theme.breakpoints.up('md'));


    const columns = [
        {
            id: 'loginTime',
            field: 'loginTime',
            headerName: "Date Time",
            width: isMdOrLg ? 'auto' : 160,
            flex: isMdOrLg ? 1 : undefined,
            valueGetter:(params)=>{
                return DateUtils.datetimeStr(params?.value);
            }
        },
        {
            id: 'result',
            field: 'result',
            headerName: 'Result',
            width: isMdOrLg ? 'auto' : 300,
            flex: isMdOrLg ? 2 : undefined,
            valueGetter:(params)=>{
                let resultMessage = "";
                if (params.row.success>0){
                    resultMessage="Success"
                }
                if (params.row.success==0){
                    resultMessage="Fail"
                }
                if (params.row.success<0){
                    resultMessage= params.row.actionType + " by " + (params.row.modifiedBy == null?"multiple times failed login attempt.":params.row.modifiedBy) 
                }
                return resultMessage;
            }
        },
    ];
    
    // function handleRowDoubleClick(params) {
    //     navigate('/publicNotice/'+ params.id);
    // }

    return (
        <div style={{minHeight: 200, height:"100%", width: '100%', padding: 4}}>
            <FiDataGrid
                columns={columns}
                customPageSize={10}
                // onRowDoubleClick={handleRowDoubleClick}
                getRowHeight={() => 'auto'}
                doLoad={{
                    url:GET_LOGIN_LOG_LIST,
                    params:{u1:u1}
                }}
            />
        </div>
    );
}
