import '../chunk-I2KLQ2HA.js';
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';

// src/zustand/slices/sse.ts
function resetSSEState(state) {
  state.sse.notificationCount = null;
  state.sse.notificationConnected = false;
  state.sse.notificationError = null;
  state.sse.commandQueueConnected = false;
  state.sse.commandQueueError = null;
}
function createSSESlice(set) {
  return {
    sse: {
      notificationCount: null,
      notificationConnected: false,
      notificationError: null,
      commandQueueConnected: false,
      commandQueueError: null
    },
    setNotificationCount: (count) => set((state) => {
      state.sse.notificationCount = count;
    }),
    setNotificationConnected: (connected) => set((state) => {
      state.sse.notificationConnected = connected;
    }),
    setNotificationError: (error) => set((state) => {
      state.sse.notificationError = error;
    }),
    setCommandQueueConnected: (connected) => set((state) => {
      state.sse.commandQueueConnected = connected;
    }),
    setCommandQueueError: (error) => set((state) => {
      state.sse.commandQueueError = error;
    })
  };
}

// src/zustand/slices/theme.ts
var THEME_STORAGE_KEY = "elevasis-theme";
var VALID_SCHEMES = ["light", "dark", "auto"];
function loadThemeFromStorage(defaultPreset, defaultColorScheme) {
  try {
    const raw = localStorage.getItem(THEME_STORAGE_KEY);
    if (raw) {
      const parsed = JSON.parse(raw);
      return {
        preset: typeof parsed.preset === "string" ? parsed.preset : defaultPreset,
        colorScheme: VALID_SCHEMES.includes(parsed.colorScheme) ? parsed.colorScheme : defaultColorScheme
      };
    }
  } catch {
  }
  return { preset: defaultPreset, colorScheme: defaultColorScheme };
}
function saveThemeToStorage(theme) {
  try {
    localStorage.setItem(THEME_STORAGE_KEY, JSON.stringify(theme));
  } catch {
  }
}
function resetThemeState(state, options = {}) {
  state.theme.preset = options.defaultPreset ?? "tactical";
  state.theme.colorScheme = options.defaultColorScheme ?? "dark";
}
function createThemeSlice(set, options = {}) {
  const defaultPreset = options.defaultPreset ?? "tactical";
  const defaultColorScheme = options.defaultColorScheme ?? "dark";
  return {
    theme: loadThemeFromStorage(defaultPreset, defaultColorScheme),
    setTheme: (updates) => set((state) => {
      if (updates.preset !== void 0) {
        state.theme.preset = updates.preset;
      }
      if (updates.colorScheme !== void 0) {
        state.theme.colorScheme = VALID_SCHEMES.includes(updates.colorScheme) ? updates.colorScheme : state.theme.colorScheme;
      }
      saveThemeToStorage(state.theme);
    })
  };
}

// src/zustand/slices/timeRange.ts
function resetTimeRangeState(state) {
  state.timeRange.value = "30d";
}
function createTimeRangeSlice(set) {
  return {
    timeRange: {
      value: "30d"
    },
    setTimeRange: (value) => set((state) => {
      state.timeRange.value = value;
    })
  };
}

// src/zustand/appStore.ts
function createElevasisAppStore(options = {}) {
  const defaultPreset = options.defaultPreset ?? "tactical";
  const defaultColorScheme = options.defaultColorScheme ?? "dark";
  return create()(
    devtools(
      immer((set) => ({
        ...createSSESlice(set),
        ...createThemeSlice(set, { defaultPreset, defaultColorScheme }),
        ...createTimeRangeSlice(set),
        resetStore: () => set(
          (state) => {
            resetSSEState(state);
            resetThemeState(state, { defaultPreset, defaultColorScheme });
            resetTimeRangeState(state);
          },
          void 0,
          "app/resetStore"
        )
      })),
      {
        name: options.devtoolsName ?? "ElevasisAppStore",
        enabled: options.devtoolsEnabled ?? import.meta.env?.DEV ?? false
      }
    )
  );
}

export { createElevasisAppStore, createSSESlice, createThemeSlice, createTimeRangeSlice, resetSSEState, resetThemeState, resetTimeRangeState };
