import { create } from 'zustand'
import type { LeaderboardStore } from './types'

const INITIAL_STATE = {
  rows: [],
  loading: false,
  fetchError: null,
  highlight: null,
} satisfies Pick<LeaderboardStore, 'rows' | 'loading' | 'fetchError' | 'highlight'>

export const useLeaderboardStore = create<LeaderboardStore>((set) => ({
  ...INITIAL_STATE,

  setRows: (rows) => {
    set({ rows })
  },

  setLoading: (loading) => {
    set({ loading })
  },

  setFetchError: (fetchError) => {
    set({ fetchError })
  },

  setHighlight: (highlight) => {
    set({ highlight })
  },

  reset: () => {
    set(INITIAL_STATE)
  },
}))
