"use strict";
import { createContext, useContext } from 'react';

/* -------------------------------------------------------------------------------------------------
 * YearPickerContext
 *
 * Context provided by Calendar (and RangeCalendar) to control year-picker visibility.
 * Internal child components consume this to toggle the year-picker open/close state,
 * keeping the public API clean and wrapper-free.
 * -----------------------------------------------------------------------------------------------*/

const YearPickerContext = /*#__PURE__*/createContext(null);
const YearPickerStateContext = /*#__PURE__*/createContext(null);

/**
 * Hook to consume YearPickerContext.
 * Must be used inside Calendar or RangeCalendar.
 */
function useYearPicker() {
  const context = useContext(YearPickerContext);
  if (!context) {
    throw new Error("useYearPicker must be used within a <Calendar> or <RangeCalendar> component.");
  }
  return context;
}

/**
 * Hook to consume normalized calendar state used by YearPicker.
 * Must be provided by Calendar or RangeCalendar root via adapter bridge.
 */
function useYearPickerState() {
  const context = useContext(YearPickerStateContext);
  if (!context) {
    throw new Error("useYearPickerState must be used within a <Calendar> or <RangeCalendar> component.");
  }
  return context;
}

export { YearPickerContext, YearPickerStateContext, useYearPicker, useYearPickerState };
