import { create } from 'zustand';
import type { CoverageResult, CoverageSettings } from '@/types/index.ts';

interface CoverageState {
  result: CoverageResult | null;
  isCalculating: boolean;
  settings: CoverageSettings;
  heatmapVisible: boolean;

  setResult: (result: CoverageResult | null) => void;
  setIsCalculating: (val: boolean) => void;
  updateSettings: (settings: Partial<CoverageSettings>) => void;
  toggleHeatmap: () => void;
  setHeatmapVisible: (val: boolean) => void;
}

export const useCoverageStore = create<CoverageState>((set) => ({
  result: null,
  isCalculating: false,
  settings: {
    radius: 10,
    resolution: 200,
    rsrpThreshold: -120,
    heatmapOpacity: 0.7,
  },
  heatmapVisible: true,

  setResult: (result) => set({ result }),
  setIsCalculating: (val) => set({ isCalculating: val }),
  updateSettings: (newSettings) =>
    set((state) => ({
      settings: { ...state.settings, ...newSettings },
    })),
  toggleHeatmap: () => set((s) => ({ heatmapVisible: !s.heatmapVisible })),
  setHeatmapVisible: (val) => set({ heatmapVisible: val }),
}));
