"use client";

import { create } from "zustand";
import { persist } from "zustand/middleware";

type ProjectsDateRange = "7d" | "30d" | "qtd";
type ProjectsLocationFilter = "all" | string;

type ProjectsUIStore = {
  locationId: ProjectsLocationFilter;
  dateRange: ProjectsDateRange;
  setLocationId: (locationId: ProjectsLocationFilter) => void;
  setDateRange: (dateRange: ProjectsDateRange) => void;
};

export const useProjectsUIStore = create<ProjectsUIStore>()(
  persist(
    (set) => ({
      locationId: "all",
      dateRange: "30d",
      setLocationId: (locationId) => set({ locationId }),
      setDateRange: (dateRange) => set({ dateRange }),
    }),
    {
      name: "casa-benell-projects-ui",
      partialize: (state) => ({
        locationId: state.locationId,
        dateRange: state.dateRange,
      }),
    }
  )
);
