import { auth } from "../auth";
import { ThemeService } from "../services/theme.service";
import { headers } from "next/headers";
async function getDefaultThemeMode() {
  var _a, _b, _c;
  try {
    const session = await auth.api.getSession({
      headers: await headers()
    });
    if ((_a = session == null ? void 0 : session.user) == null ? void 0 : _a.id) {
      try {
        const baseUrl = process.env.NEXT_PUBLIC_APP_URL || "http://localhost:5173";
        const response = await fetch(`${baseUrl}/api/user/profile?includeMeta=true`, {
          headers: {
            cookie: (await headers()).get("cookie") || ""
          },
          cache: "no-store"
        });
        if (response.ok) {
          const data = await response.json();
          if ((_c = (_b = data.meta) == null ? void 0 : _b.uiPreferences) == null ? void 0 : _c.theme) {
            const userTheme = data.meta.uiPreferences.theme;
            return userTheme;
          }
        }
      } catch (error) {
      }
    }
  } catch (error) {
  }
  try {
    const activeThemeName = process.env.NEXT_PUBLIC_ACTIVE_THEME || "default";
    const themeConfig = ThemeService.getByName(activeThemeName);
    const defaultMode = (themeConfig == null ? void 0 : themeConfig.defaultMode) || "system";
    return defaultMode;
  } catch (error) {
    return "system";
  }
}
export {
  getDefaultThemeMode
};
