import { createContext, useContext } from "react";

export type ConsentChoice = "pending" | "granted" | "denied";

export interface AnalyticsConsentValue {
  choice: ConsentChoice;
  isSettingsOpen: boolean;
  accept: () => void;
  reject: () => void;
  openSettings: () => void;
  closeSettings: () => void;
}

export const AnalyticsConsentContext =
  createContext<AnalyticsConsentValue | null>(null);

export function useAnalyticsConsent(): AnalyticsConsentValue {
  const context = useContext(AnalyticsConsentContext);
  if (!context) {
    throw new Error(
      "useAnalyticsConsent must be used inside AnalyticsConsentProvider."
    );
  }
  return context;
}
