import { TextField as MuiTextField } from '@mui/material';
import { FieldComponentProps } from '../../types/overrides';

export default function DateField({ field, value, onChange, disabled }: FieldComponentProps) {
  const isDatetime = field.type === 'datetime';
  return (
    <MuiTextField
      fullWidth
      label={field.label}
      type={isDatetime ? "datetime-local" : "date"}
      InputLabelProps={{ shrink: true }}
      value={value ? new Date(value).toISOString().slice(0, isDatetime ? 16 : 10) : ''}
      onChange={(e) => onChange(e.target.value)}
      disabled={disabled}
      required={field.required}
    />
  );
}
