import { FC } from 'react';
import { Control } from 'react-hook-form';

import { IdeaObject } from 'src/types/recognitions';

import CapexForm from './CapexForm';
import CarbonForm from './CarbonForm';
import CostReductionForm from './CostReductionForm';
import EnergySaveForm from './EnergySaveForm';
import MoralForm from './MoralForm';
import OptimizationForm from './OptimizationForm';
import ProductivityForm from './ProductivityForm';
import QualityForm from './QualityForm';
import RawMaterialForm from './RawMaterialForm';
import SecurityForm from './SecurityForm';

export type CategoryFormProps = {
  currentCategory: number;
  control?: Control;
  defaultValues?: IdeaObject;
  isReadOnly?: boolean;
};

export const CategoryForm: FC<CategoryFormProps> = props => {
  const {
    currentCategory,
    control = null,
    defaultValues = null,
    isReadOnly = false,
  } = props;

  const componentByCategory = {
    1: SecurityForm,
    2: QualityForm,
    3: ProductivityForm,
    4: CostReductionForm,
    5: CapexForm,
    6: RawMaterialForm,
    7: OptimizationForm,
    8: MoralForm,
    9: EnergySaveForm,
    10: CarbonForm,
  };

  const FormToShow = componentByCategory[currentCategory];

  return FormToShow ? (
    <FormToShow
      control={control}
      defaultValues={defaultValues}
      isReadOnly={isReadOnly}
    />
  ) : null;
};

export default CategoryForm;
