import { useLocation } from 'react-router-dom';
import { Create, DateInput, SelectInput, SimpleForm, TextInput as RaTextInput } from 'react-admin';
import {
  equipmentLabels,
  equipmentStatusChoices,
  getEquipmentCreateDefaultValues,
  getEquipmentPageContextFromSearch,
} from './shared';

export function EquipmentCreate() {
  const location = useLocation();
  const pageContext = getEquipmentPageContextFromSearch(location.search);

  return (
    <Create>
      <SimpleForm defaultValues={getEquipmentCreateDefaultValues(pageContext)}>
        <RaTextInput source="name" label={equipmentLabels.name} required />
        <RaTextInput source="serialNumber" label={equipmentLabels.serialNumber} required />
        <SelectInput source="status" label={equipmentLabels.status} choices={equipmentStatusChoices} required />
        <DateInput source="dateOfInspection" label={equipmentLabels.dateOfInspection} />
        <DateInput source="installationDate" label={equipmentLabels.installationDate} />
        <DateInput source="writeOffDate" label={equipmentLabels.writeOffDate} />
      </SimpleForm>
    </Create>
  );
}
