import { List, DataTable, TextField, DateField, NumberField, EditButton } from 'react-admin';
import { EquipmentType, EnumPeriodicityTO, EquipmentStatus } from '@prisma/client';

const equipmentTypeChoices = Object.values(EquipmentType).map(value => ({
  id: value,
  name: value,
}));

const periodicityTOChoices = Object.values(EnumPeriodicityTO).map(value => ({
  id: value,
  name: value,
}));

const statusChoices = Object.values(EquipmentStatus).map(value => ({
  id: value,
  name: value,
}));

export const EquipmentList = () => (
  <List>
    <DataTable rowClick="edit">
      <DataTable.Col source="id" />
      <DataTable.Col source="name" />
      <DataTable.Col source="serialNumber" />
      <DataTable.Col source="inventoryNumber" />
      <DataTable.Col 
        source="equipmentType" 
        choices={equipmentTypeChoices}
      />
      <DataTable.Col source="dateOfInspection" field={DateField} />
      <DataTable.Col 
        source="periodicityTO" 
        choices={periodicityTOChoices}
      />
      <DataTable.Col source="location" />
      <DataTable.Col 
        source="status" 
        choices={statusChoices}
      />
      <DataTable.Col source="commissionedAt" field={DateField} />
      <DataTable.Col source="totalEngineHours" field={NumberField} />
      <DataTable.Col source="engineHoursSinceLastRepair" field={NumberField} />
      <DataTable.Col source="lastRepairAt" field={DateField} />
      <DataTable.Col><EditButton /></DataTable.Col>
    </DataTable>
  </List>
);