import { useGetAppSettings, getGetAppSettingsQueryKey } from "@workspace/api-client-react";
import { useEffect } from "react";
import { useTranslation } from "react-i18next";

export function useAppSettings() {
  const query = useGetAppSettings({ query: { queryKey: getGetAppSettingsQueryKey() } });
  return query;
}

export function useAppName() {
  const { i18n } = useTranslation();
  const { data } = useAppSettings();
  const isAr = i18n.language === "ar";
  const fallback = isAr ? "نظام Tx" : "Tx OS";
  const name = data ? (isAr ? data.siteNameAr : data.siteNameEn) : fallback;
  useEffect(() => {
    if (typeof document !== "undefined" && data) {
      document.title = name;
    }
  }, [name, data]);
  return name;
}
