import { create } from 'zustand'

export type AnalyzeSectionVisibility = Record<string, boolean>

export type AnalyzePanelState = {
  isOpen: boolean
  domain: string | null
  fastMode: boolean
  filterText: string
  sectionVisibility: AnalyzeSectionVisibility
  open: (domain: string) => void
  close: () => void
  setFastMode: (fast: boolean) => void
  setFilterText: (value: string) => void
  setSectionVisibility: (next: AnalyzeSectionVisibility) => void
}

const DEFAULT_VISIBILITY: AnalyzeSectionVisibility = {
  authority: true,
  market: true,
  risk: true,
  value: true,
}

export const useAnalyzePanelStore = create<AnalyzePanelState>((set) => ({
  isOpen: false,
  domain: null,
  fastMode: false,
  filterText: '',
  sectionVisibility: DEFAULT_VISIBILITY,
  open: (domain) => set({ isOpen: true, domain, filterText: '' }),
  close: () => set({ isOpen: false }),
  setFastMode: (fastMode) => set({ fastMode }),
  setFilterText: (filterText) => set({ filterText }),
  setSectionVisibility: (sectionVisibility) => set({ sectionVisibility }),
}))

export const ANALYZE_PREFS_KEY = 'pounce_analyze_prefs_v1'

