"use client"; import { create } from "zustand"; import { persist } from "zustand/middleware"; import type { SelectedLocation } from "@/types/location"; import type { Province } from "@/types/province"; type NotificationProvinceMode = "selected" | "manual"; interface WeatherStore { favorites: string[]; selectedStationId: string | null; selectedLocation: SelectedLocation | null; warningNotificationsEnabled: boolean; morningBriefNotificationsEnabled: boolean; warningNotificationProvinceMode: NotificationProvinceMode; warningNotificationProvince: Province | null; toggleFavorite: (id: string) => void; selectStation: (id: string) => void; selectLocation: (location: SelectedLocation) => void; setWarningNotificationsEnabled: (enabled: boolean) => void; setMorningBriefNotificationsEnabled: (enabled: boolean) => void; setWarningNotificationProvinceMode: (mode: NotificationProvinceMode) => void; setWarningNotificationProvince: (province: Province | null) => void; } export const useWeatherStore = create()( persist( (set) => ({ favorites: [], selectedStationId: null, selectedLocation: null, warningNotificationsEnabled: false, morningBriefNotificationsEnabled: false, warningNotificationProvinceMode: "selected", warningNotificationProvince: null, toggleFavorite: (id) => set((state) => ({ favorites: state.favorites.includes(id) ? state.favorites.filter((favoriteId) => favoriteId !== id) : [...state.favorites, id], })), selectStation: (id) => set({ selectedStationId: id, selectedLocation: null }), selectLocation: (location) => set({ selectedStationId: location.stationId, selectedLocation: location }), setWarningNotificationsEnabled: (enabled) => set({ warningNotificationsEnabled: enabled }), setMorningBriefNotificationsEnabled: (enabled) => set({ morningBriefNotificationsEnabled: enabled }), setWarningNotificationProvinceMode: (mode) => set({ warningNotificationProvinceMode: mode }), setWarningNotificationProvince: (province) => set({ warningNotificationProvince: province }), }), { name: "wtr:preferences" }, ), );