import { create } from "zustand";
import { persist } from "zustand/middleware";
import type { Settings } from "@/lib/types";
import { DEFAULT_SETTINGS } from "@/lib/defaults";

interface SettingsStore {
  settings: Settings;
  setSettings: (settings: Partial<Settings>) => void;
  resetSettings: () => void;
}

export const useSettingsStore = create<SettingsStore>()(
  persist(
    (set) => ({
      settings: DEFAULT_SETTINGS,
      setSettings: (updates) =>
        set((state) => ({
          settings: { ...state.settings, ...updates },
        })),
      resetSettings: () => set({ settings: DEFAULT_SETTINGS }),
    }),
    { name: "disputed-settings" },
  ),
);
