'use client';

import React, { createContext, useContext } from 'react';
import type { FormDefinition } from '../../types/api/form';

export type FormDefinitionsContextValue = {
  leadFormDefinition: FormDefinition | null;
  jobApplicationFormDefinition: FormDefinition | null;
  marketingListSignupFormDefinition: FormDefinition | null;
};

const FormDefinitionsContext = createContext<FormDefinitionsContextValue>({
  leadFormDefinition: null,
  jobApplicationFormDefinition: null,
  marketingListSignupFormDefinition: null,
});

export function FormDefinitionsProvider(props: {
  leadFormDefinition: FormDefinition | null;
  jobApplicationFormDefinition: FormDefinition | null;
  marketingListSignupFormDefinition: FormDefinition | null;
  children: React.ReactNode;
}) {
  const { leadFormDefinition, jobApplicationFormDefinition, marketingListSignupFormDefinition, children } = props;
  return (
    <FormDefinitionsContext.Provider value={{ leadFormDefinition, jobApplicationFormDefinition, marketingListSignupFormDefinition }}>
      {children}
    </FormDefinitionsContext.Provider>
  );
}

export function useFormDefinitions(): FormDefinitionsContextValue {
  return useContext(FormDefinitionsContext);
}

