'use client';

import React from 'react';
import type { FormContextValue } from './types';

// ==================== Form Context ====================

const FormContext = React.createContext<FormContextValue<any> | null>(null);

export function useFormContext<TValues extends Record<string, any>>() {
  const context = React.useContext(FormContext);
  if (!context) {
    throw new Error('Form components must be used within Form');
  }
  return context as FormContextValue<TValues>;
}

export { FormContext };
