"use client"

import type { MailThemeMode } from "@/lib/mail-settings/types"
import { useDemoThemeStore } from "@/lib/demo/demo-theme-store"
import { useIsDemoApp } from "@/lib/demo/use-is-demo-app"
import { useMailSettingsStore } from "@/lib/stores/mail-settings-store"

/** Thème clair/sombre/système : store démo isolé sur /demo/*, sinon réglages mail. */
export function useThemeModeControls(): {
  themeMode: MailThemeMode
  setThemeMode: (mode: MailThemeMode) => void
} {
  const isDemo = useIsDemoApp()
  const mailThemeMode = useMailSettingsStore((s) => s.themeMode)
  const setMailThemeMode = useMailSettingsStore((s) => s.setThemeMode)
  const demoThemeMode = useDemoThemeStore((s) => s.themeMode)
  const setDemoThemeMode = useDemoThemeStore((s) => s.setThemeMode)

  if (isDemo) {
    return { themeMode: demoThemeMode, setThemeMode: setDemoThemeMode }
  }

  return { themeMode: mailThemeMode, setThemeMode: setMailThemeMode }
}
