import { createContext, useContext, useMemo, useReducer } from 'react'
import { useApiCollection, COLLECTIONS } from '../../../shared/hooks/useLiveApi'

const StoreContext = createContext(null)

export function DataProvider({ children }) {
  return <StoreContext.Provider value={{}}>{children}</StoreContext.Provider>
}

export function useCollection(name) {
  return useApiCollection(name)
}

export function useStore() {
  const ctx = useContext(StoreContext)
  if (!ctx) throw new Error('useStore must be used within DataProvider')
  return ctx
}

export function useStatusToggle(
  collectionName,
  { field = 'status', onValue = 'Active', offValue = 'Suspended' } = {}
) {
  const { toggleField } = useCollection(collectionName)
  return (row) => toggleField(row.id, field, row[field] === onValue ? offValue : onValue)
}

export { COLLECTIONS }
