import React, {createContext, useContext} from 'react';

interface PdfFontScaleContextValue {
  fontScale: number;
}

const PdfFontScaleContext = createContext<PdfFontScaleContextValue | undefined>(
  undefined,
);

interface PdfFontScaleProviderProps {
  children: React.ReactNode;
  fontScale: number;
}

export function PdfFontScaleProvider({
  children,
  fontScale,
}: PdfFontScaleProviderProps) {
  const value = {
    fontScale,
  };

  return (
    <PdfFontScaleContext.Provider value={value}>
      {children}
    </PdfFontScaleContext.Provider>
  );
}

export function usePdfFontScale(): PdfFontScaleContextValue {
  const context = useContext(PdfFontScaleContext);
  if (context === undefined) {
    throw new Error(
      'usePdfFontScale must be used within a PdfFontScaleProvider',
    );
  }
  return context;
}
