import { useMemo } from 'preact/hooks';
import { getI18n } from '../core/i18n';
import { useAsukaStore } from '../store/asukaStore';

/**
 * Hook returning the translation function.
 * Re-renders when locale/translations change (via i18nVersion tick in Zustand).
 */
export const useT = () => {
  // Subscribe to i18nVersion so any locale/translation changes update UI.
  useAsukaStore((s: any) => s.i18nVersion);

  const api = getI18n();
  return useMemo(() => api.t.bind(api), [api]);
};
