import { GridColDef, GridRenderCellParams } from '@mui/x-data-grid-premium';
import Typography from '@mui/material/Typography';
import { formatCurrency, formatNumber } from '../utils/orderFormatters';

export const createOrderItemsColumns = (): GridColDef[] => [
  {
    field: 'productId',
    headerName: 'Cód. Produto',
    width: 110,
    minWidth: 100,
    headerAlign: 'right',
    align: 'right',
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography
        variant="body2"
        color="text.primary"
        sx={{ fontSize: '0.75rem', fontWeight: 500, textAlign: 'right' }}
      >
        {params.value}
      </Typography>
    ),
  },
  {
    field: 'description',
    headerName: 'Descrição',
    width: 300,
    minWidth: 250,
    flex: 1,
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography
        variant="body2"
        color="text.primary"
        sx={{ fontSize: '0.75rem' }}
        noWrap
      >
        {params.value}
      </Typography>
    ),
  },
  {
    field: 'pacth',
    headerName: 'Unidade',
    width: 100,
    minWidth: 80,
    headerAlign: 'center',
    align: 'center',
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography
        variant="body2"
        color="text.primary"
        sx={{ fontSize: '0.75rem', textAlign: 'center' }}
      >
        {params.value || '-'}
      </Typography>
    ),
  },
  {
    field: 'color',
    headerName: 'Cor',
    width: 80,
    minWidth: 70,
    headerAlign: 'center',
    align: 'center',
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography
        variant="body2"
        color="text.primary"
        sx={{ fontSize: '0.75rem', textAlign: 'center' }}
      >
        {params.value || '-'}
      </Typography>
    ),
  },
  {
    field: 'stockId',
    headerName: 'Cód. Estoque',
    width: 110,
    minWidth: 100,
    headerAlign: 'right',
    align: 'right',
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography
        variant="body2"
        color="text.primary"
        sx={{ fontSize: '0.75rem', textAlign: 'right' }}
      >
        {params.value}
      </Typography>
    ),
  },
  {
    field: 'quantity',
    headerName: 'Qtd.',
    width: 90,
    minWidth: 80,
    type: 'number',
    aggregable: true,
    headerAlign: 'right',
    align: 'right',
    valueFormatter: (value) => formatNumber(value as number),
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography
        variant="body2"
        color="text.primary"
        sx={{ fontSize: '0.75rem', fontWeight: 500, textAlign: 'right' }}
      >
        {formatNumber(params.value)}
      </Typography>
    ),
  },
  {
    field: 'salePrice',
    headerName: 'Preço Unitário',
    width: 130,
    minWidth: 120,
    type: 'number',
    headerAlign: 'right',
    align: 'right',
    valueFormatter: (value) => formatCurrency(value as number),
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography
        variant="body2"
        color="text.primary"
        sx={{ fontSize: '0.75rem', textAlign: 'right' }}
      >
        {formatCurrency(params.value)}
      </Typography>
    ),
  },
  {
    field: 'total',
    headerName: 'Valor Total',
    width: 130,
    minWidth: 120,
    type: 'number',
    aggregable: true,
    headerAlign: 'right',
    align: 'right',
    valueFormatter: (value) => formatCurrency(value as number),
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography
        variant="body2"
        color="text.primary"
        sx={{ fontSize: '0.75rem', fontWeight: 600, textAlign: 'right' }}
      >
        {formatCurrency(params.value)}
      </Typography>
    ),
  },
  {
    field: 'deliveryType',
    headerName: 'Tipo Entrega',
    width: 140,
    minWidth: 130,
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography
        variant="body2"
        color="text.primary"
        sx={{ fontSize: '0.75rem' }}
        noWrap
      >
        {params.value}
      </Typography>
    ),
  },
  {
    field: 'weight',
    headerName: 'Peso (kg)',
    width: 100,
    minWidth: 90,
    type: 'number',
    aggregable: true,
    headerAlign: 'right',
    align: 'right',
    valueFormatter: (value) => formatNumber(value as number),
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography
        variant="body2"
        color="text.primary"
        sx={{ fontSize: '0.75rem', textAlign: 'right' }}
      >
        {formatNumber(params.value)}
      </Typography>
    ),
  },
  {
    field: 'department',
    headerName: 'Departamento',
    width: 150,
    minWidth: 140,
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography variant="body2" sx={{ fontSize: '0.75rem' }} noWrap>
        {params.value}
      </Typography>
    ),
  },
  {
    field: 'brand',
    headerName: 'Marca',
    width: 150,
    minWidth: 140,
    renderCell: (params: Readonly<GridRenderCellParams>) => (
      <Typography variant="body2" sx={{ fontSize: '0.75rem' }} noWrap>
        {params.value}
      </Typography>
    ),
  },
];
