import { useContext } from 'react'

import { GDSContext } from '../GDSContext.ts'

/** Throws an error if used outside of a `GDSProvider`. */
export function useGDS() {
  const context = useContext(GDSContext)

  if (context === null) {
    throw new Error('GDS components must be wrapped in a `GDSProvider`')
  }

  return {
    activeTheme: context.activeTheme,
    dirProps: {
      dir: context.direction,
      lang: context.language,
    },
  }
}
