'use client';

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

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

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

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

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

