import { useApiCollection } from '../hooks/useLiveApi'

/**
 * Drop-in replacement for useState(INITIAL_ROWS) + local add/update/remove.
 * Usage: const { rows, loading, add, update, remove, refresh } = useLiveRows('feeRecords')
 */
export function useLiveRows(collection) {
  const api = useApiCollection(collection)
  return {
    rows: api.rows,
    loading: api.loading,
    error: api.error,
    refresh: api.refresh,
    add: api.add,
    update: api.update,
    remove: api.remove,
    toggleField: api.toggleField,
    setRows: api.setRows,
    total: api.total,
  }
}
