"use client";

import { create } from "zustand";
import { persist } from "zustand/middleware";
import type { DateRangeKey, UserRole } from "@/lib/types";

type UIStore = {
  role: UserRole;
  dateRange: DateRangeKey;
  locationId: string;
  search: string;
  setRole: (role: UserRole) => void;
  setDateRange: (range: DateRangeKey) => void;
  setLocationId: (locationId: string) => void;
  setSearch: (search: string) => void;
};

export const useUIStore = create<UIStore>()(
  persist(
    (set) => ({
      role: "owner",
      dateRange: "esta-semana",
      locationId: "todas",
      search: "",
      setRole: (role) => set({ role }),
      setDateRange: (dateRange) => set({ dateRange }),
      setLocationId: (locationId) => set({ locationId }),
      setSearch: (search) => set({ search }),
    }),
    {
      name: "casa-benell-ui",
      partialize: (state) => ({
        role: state.role,
        dateRange: state.dateRange,
        locationId: state.locationId,
      }),
    }
  )
);
