import React from "react";
import PropTypes from "prop-types";
import CheckboxInput from "./Inputs/CheckboxInput.js";
import TextAreaInput from "./Inputs/TextAreaInput.js";
import NumberInput from "./Inputs/NumberInput.js";
import SelectInput from "./Inputs/SelectInput.js";
import RadioInput from "./Inputs/RadioInput.js";
import DateInput from "./Inputs/DateInput.js";
import DateRangeInput from "./Inputs/DateRangeInput.js";
import PhoneNumberInput from "./Inputs/PhoneNumberInput.js";
import DynamicListTypeInput from "./Inputs/DynamicListTypeInput.js";

const inputMap = {
  text: TextAreaInput,
  email: TextAreaInput,
  phone: PhoneNumberInput,
  number: NumberInput,
  textarea: TextAreaInput,
  checkbox: CheckboxInput,
  select: SelectInput,
  radio: RadioInput,
  date: DateInput,
  date_range: DateRangeInput,
  list: DynamicListTypeInput
};

function InputFactory({ field, disabled, onChange, error, helperText }) {
  const Component = inputMap[field.Type];
  if (!Component) return null;

  return (
    <Component
      field={field}
      disabled={disabled}
      onChange={onChange}
      error={error}
      helperText={helperText}
    />
  );
}

export default InputFactory;

InputFactory.propTypes = {
  field: PropTypes.object.isRequired,
  disabled: PropTypes.bool,
  onChange: PropTypes.func.isRequired,
  error: PropTypes.bool,
  helperText: PropTypes.string,
};
