// material-ui
// import {
//     GridActionsCellItem,
// } from "@mui/x-data-grid";
import {FiDataGrid} from "components/FiDataGrid";
//import EditIcon from '@mui/icons-material/Edit';
import {useState, useEffect} from "react";
import {useNavigate} from "react-router-dom";
import { GET_GROUP_LIST_PATH } from "utils/ApiPathConst";
import { clickableLink} from 'utils/CommonFunction';
import * as React from 'react';
// ==============================|| EVENT TABLE ||============================== //

export default function UserGroupTable({searchCriteria, applyGridOnReady,applySearch}) {
    const [_searchCriteria, set_searchCriteria] = useState(searchCriteria);
    const navigate = useNavigate()

    useEffect(() => {
        set_searchCriteria(searchCriteria);
    }, [searchCriteria]);

    // const handleEditClick = (id) => () => {
    //     navigate('/userGroup/'+ id);
    // };

    const columns = [
        // {
        //     field: 'actions',
        //     type: 'actions',
        //     headerName: 'Actions',
        //     width: 100,
        //     cellClassName: 'actions',
        //     getActions: ({id}) => {
        //         return [
        //             <GridActionsCellItem
        //                 key="OutSave"
        //                 icon={<EditIcon/>}
        //                 label="Edit"
        //                 className="textPrimary"
        //                 onClick={handleEditClick(id)}
        //                 color="primary"
        //             />]
        //     },
        // },
        {
            id: 'groupName',
            field: 'name',
            headerName: 'User Group Name',
            flex: 1,
            renderCell: (params) => {
                return clickableLink('/userGroup/'+ params.row.id, params.row.name);
            },
        },
        {
            id: 'description',
            field: 'description',
            headerName: 'User Group Description',
            flex: 1,
        },
    ];

    function handleRowDoubleClick(params) {
        navigate('/userGroup/'+ params.id);
    }

    return (
        <div style={{height: "fit-content", width: '100%'}}>
            <FiDataGrid
                columns={columns}
                customPageSize={10}
                pageSizeOptions={[10, 15, 20]}
                onRowDoubleClick={handleRowDoubleClick}
                applyGridOnReady={applyGridOnReady}
                applySearch={applySearch}
                // doLoad={{
                //     url: GET_GROUP_LIST_PATH,
                //     params: _searchCriteria,
                // }}
                doLoad={React.useMemo(() => ({
                    url: GET_GROUP_LIST_PATH,
                    params: _searchCriteria,
                }), [_searchCriteria])}
            />
        </div>
    );
}
