import type { Row, Column } from '@tanstack/react-table'

interface DataTableColumnDatetimeProps<TData, TValue>
  extends React.HTMLAttributes<HTMLDivElement> {
  row: Row<TData>
  column: Column<TData, TValue>
}

const formatted = new Intl.NumberFormat('pt-BR', {
  style: 'currency',
  currency: 'BRL'
})

export function DataTableColumnCurrency<TData, TValue>({
  row,
  column
}: DataTableColumnDatetimeProps<TData, TValue>) {
  // @ts-ignore
  const { accessorKey } = column.columnDef
  const value = row.getValue(accessorKey) as number

  if (value) {
    return formatted.format(value)
  }

  return <></>
}
