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

interface PipelineStore {
  viewMode: 'board' | 'table';
  boardFilters: {
    leadCategory?: string;
    search?: string;
  };
  setViewMode: (mode: 'board' | 'table') => void;
  setBoardFilter: (key: keyof PipelineStore['boardFilters'], value: string | undefined) => void;
  clearBoardFilters: () => void;
}

export const usePipelineStore = create<PipelineStore>()(
  persist(
    (set) => ({
      viewMode: 'table',
      boardFilters: {},
      setViewMode: (mode) => set({ viewMode: mode }),
      setBoardFilter: (key, value) =>
        set((s) => ({ boardFilters: { ...s.boardFilters, [key]: value } })),
      clearBoardFilters: () => set({ boardFilters: {} }),
    }),
    {
      name: 'pn-crm-pipeline',
      partialize: (state) => ({
        viewMode: state.viewMode,
        boardFilters: state.boardFilters,
      }),
    },
  ),
);
