import { create } from 'zustand';

interface FilterState {
  categoryId: number | null;
  searchQuery: string;
  currentPage: number;
  setCategoryId: (id: number | null) => void;
  setSearchQuery: (query: string) => void;
  setCurrentPage: (page: number) => void;
  resetFilters: () => void;
}

const useFilterStore = create<FilterState>((set) => ({
  categoryId: null,
  searchQuery: '',
  currentPage: 1,

  setCategoryId: (id) => set({ categoryId: id, currentPage: 1 }),
  setSearchQuery: (query) => set({ searchQuery: query, currentPage: 1 }),
  setCurrentPage: (page) => set({ currentPage: page }),

  resetFilters: () =>
    set({
      categoryId: null,
      searchQuery: '',
      currentPage: 1,
    }),
}));

export default useFilterStore;
