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 MediaList = () => {
  const {dataGridProps} = useDataGrid({})

  const columns = React.useMemo<GridColDef[]>(
    () => [
      {
        field: 'filename',
        headerName: 'Название',
        type: 'string',
        minWidth: 250,
        display: 'flex',
        align: 'left',
        headerAlign: 'left',
      },
      {
        field: 'media_type',
        headerName: 'Тип',
        type: 'number',
        minWidth: 150,
        display: 'flex',
        align: 'left',
        headerAlign: 'left',
      },
      {
        field: 'id',
        headerName: 'ID',
        type: 'number',
        display: 'flex',
        align: 'left',
        headerAlign: 'left',
        flex: 1,
      },
      {
        field: 'actions',
        headerName: 'Действия',
        align: 'right',
        headerAlign: 'right',
        display: 'flex',
        flex: 1,
        sortable: false,
        renderCell: function render({row}) {
          return (
            <>
              <EditButton hideText recordItemId={row.id} />
              <ShowButton hideText recordItemId={row.id} />
              <DeleteButton hideText recordItemId={row.id} />
            </>
          )
        },
      },
    ],
    [],
  )

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