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

interface PipelineStore {
  viewMode: 'board' | 'table';
  setViewMode: (mode: 'board' | 'table') => void;
}

// Bumped persist key to drop any stale `boardFilters` shape that earlier
// builds wrote into localStorage. The board no longer has a per-stage
// filter UI; reading a leftover `leadCategory: 'old_value'` would silently
// hide every card in the kanban view.
export const usePipelineStore = create<PipelineStore>()(
  persist(
    (set) => ({
      viewMode: 'table',
      setViewMode: (mode) => set({ viewMode: mode }),
    }),
    {
      name: 'pn-crm-pipeline-v2',
      partialize: (state) => ({ viewMode: state.viewMode }),
    },
  ),
);
