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

import {localeText} from '../../locales/ru/localeText'

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

  const columns = React.useMemo<GridColDef[]>(
    () => [
      {
        field: 'code',
        headerName: 'Код',
        type: 'string',
        minWidth: 100,
        display: 'flex',
        align: 'left',
        headerAlign: 'left',
      },
      {
        field: 'name',
        headerName: 'Название',
        type: 'string',
        minWidth: 100,
        flex: 1,
      },
      {
        field: 'actions',
        headerName: 'Действия',
        align: 'right',
        headerAlign: 'center',
        minWidth: 120,
        sortable: false,
        display: 'flex',
        renderCell: function render({row}) {
          return (
            <>
              <EditButton hideText recordItemId={row.code} />
              <ShowButton hideText recordItemId={row.code} />
              <DeleteButton hideText recordItemId={row.code} />
            </>
          )
        },
      },
    ],
    [],
  )

  return (
    <List>
      <CustomDataGrid {...dataGridProps} columns={columns} localeText={localeText} getRowId={(row: any) => row.code} />
    </List>
  )
}
