import { create } from "zustand";
import { immer } from "zustand/middleware/immer";
import { STATUSES } from "../config";

export const INITIAL = {
  prediction: [0, 0],
  categories: [],
  region: null,
  status: [STATUSES.initial],
  deltaTraffic: [-1000, 1000],
  factTraffic: [0, 0],
  age: [0, 0],
};

const store = (set) => ({
  filters: INITIAL,
  setPrediction: (value) => {
    set((state) => {
      state.filters.prediction = value;
    });
  },

  setDeltaTraffic: (value) => {
    set((state) => {
      state.filters.deltaTraffic = value;
    });
  },

  setFactTraffic: (value) => {
    set((state) => {
      state.filters.factTraffic = value;
    });
  },

  setAge: (value) => {
    set((state) => {
      state.filters.age = value;
    });
  },

  setCategories: (categories) =>
    set((state) => {
      state.filters.categories = categories;
    }),

  setRegion: (value) =>
    set((state) => {
      state.filters.region = value;
    }),

  setStatus: (newStatus) =>
    set((state) => {
      state.filters.status = newStatus;
    }),
});

export const useFilters = create(immer(store));
