import { create } from 'zustand'

export type AnalyzeSectionVisibility = Record<string, boolean>

export type DropStatusInfo = {
  status: 'available' | 'dropping_soon' | 'taken' | 'unknown'
  deletion_date?: string | null
  is_drop?: boolean
}

export type AnalyzePanelState = {
  isOpen: boolean
  domain: string | null
  fastMode: boolean
  filterText: string
  sectionVisibility: AnalyzeSectionVisibility
  dropStatus: DropStatusInfo | null
  open: (domain: string, dropStatus?: DropStatusInfo) => void
  close: () => void
  setFastMode: (fast: boolean) => void
  setFilterText: (value: string) => void
  setSectionVisibility: (next: AnalyzeSectionVisibility) => void
  setDropStatus: (status: DropStatusInfo | null) => 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,
  dropStatus: null,
  open: (domain, dropStatus) => set({ isOpen: true, domain, filterText: '', dropStatus: dropStatus || null }),
  close: () => set({ isOpen: false, dropStatus: null }),
  setFastMode: (fastMode) => set({ fastMode }),
  setFilterText: (filterText) => set({ filterText }),
  setSectionVisibility: (sectionVisibility) => set({ sectionVisibility }),
  setDropStatus: (dropStatus) => set({ dropStatus }),
}))

export const ANALYZE_PREFS_KEY = 'pounce_analyze_prefs_v1'

