import { create } from "zustand";
import { persist } from "zustand/middleware";
import { trackEvent, AnalyticsEvents } from "@/lib/analytics";

export type ColorMode = "light" | "dark" | "system";

interface ThemeState {
  mode: ColorMode;
  setMode: (mode: ColorMode) => void;
}

export const useThemeStore = create<ThemeState>()(
  persist(
    (set) => ({
      mode: "light",
      setMode: (mode: ColorMode) => {
        trackEvent(AnalyticsEvents.THEME_CHANGED, { theme: mode, platform: 'web' });
        set({ mode });
      },
    }),
    {
      name: "honeydue-theme",
    }
  )
);
