import { useDynamicFormContext } from '@composed-components/dynamic-forms/hooks/useDynamicFormContext';

import { type FormInputsCatalogProps, type Section } from './types';
import FormInputsCatalog from '.';

/**
 *
 * This component connects the FormInputsCatalog component to the dynamic form context.
 */
const FormInputsCatalogConnected = (props: FormInputsCatalogProps) => {
  const { formResponse, isFrozen } = useDynamicFormContext();
  const nextSection = formResponse?.nextSection || props?.section;

  if (!nextSection) return null;

  return (
    <FormInputsCatalog
      {...props}
      isFrozen={isFrozen}
      section={nextSection as Section}
    />
  );
};

export default FormInputsCatalogConnected;
