import {DataGrid, type GridColDef} from '@mui/x-data-grid'
import {DeleteButton, EditButton, List, ShowButton, useDataGrid} from '@refinedev/mui'
import React from 'react'

export const VehicleList = () => {
  const {dataGridProps} = useDataGrid({})

  const columns = React.useMemo<GridColDef[]>(
    () => [
      {
        field: 'id',
        headerName: 'ID',
        type: 'number',
        minWidth: 70,
        display: 'flex',
        align: 'left',
        headerAlign: 'left',
      },
      {
        field: 'tail_number',
        headerName: 'Номер рейса',
        type: 'number',
        minWidth: 150,
        display: 'flex',
        align: 'left',
        headerAlign: 'left',
      },
      {
        field: 'type',
        headerName: 'Тип',
        type: 'number',
        minWidth: 150,
        display: 'flex',
        align: 'left',
        headerAlign: 'left',
      },
      {
        field: 'city_id',
        headerName: 'ID города',
        type: 'number',
        minWidth: 70,
        display: 'flex',
        align: 'left',
        headerAlign: 'left',
        flex: 1,
      },
      {
        field: 'actions',
        headerName: 'Действия',
        align: 'right',
        headerAlign: 'center',
        minWidth: 120,
        sortable: false,
        display: 'flex',
        renderCell: function render({row}) {
          return (
            <>
              <EditButton hideText recordItemId={row.id} />
              <ShowButton hideText recordItemId={row.id} />
              <DeleteButton hideText recordItemId={row.id} />
            </>
          )
        },
      },
    ],
    [],
  )

  return (
    <List>
      <DataGrid {...dataGridProps} columns={columns} getRowId={(row: any) => row.id} />
    </List>
  )
}
