import { create } from 'zustand';
import { TableParams } from '../types';

type ZustandState = {
  params: TableParams;
  updateParams: (newParams: Partial<TableParams>) => void;
  clearParams: (newParams: TableParams) => void;
};

export const useParamsStore = create<ZustandState>((set) => ({
  params: {
    page: 1,
    rows: 10,
    search: "",
  },
  updateParams: (newParams: Partial<TableParams>) =>
    set((state) => ({
      ...state,
      params: {
        ...state.params,
        ...newParams,
      },
    })),
  clearParams: (defaultParams: TableParams) =>
    set((state) => ({
      ...state,
      params: defaultParams,
    })),
}));