import type { EnsureFunction } from '@videojs/utils/types';
import type { AnyStore, InferStoreRequests } from '../../core/store';
import type { Task } from '../../core/task';
import type { MutationResult } from '../../shared/types';
import { useCallback, useRef, useSyncExternalStore } from 'react';
/**
* Track a store request as a mutation with status, data, and error.
*
* Subscribes to the task queue and re-renders when the mutation's status changes.
*
* Returns a discriminated union — use `status` to narrow the type and access
* `data` (on success) or `error` (on failure).
*
* @param store - The store instance containing the request
* @param name - The request name to track (type-safe with autocomplete)
* @returns A discriminated union with the mutation's current state
*
* @example
* ```tsx
* function SourceSelector() {
* const source = useMutation(store, 'setSource');
*
* return (
* <>
*
* {source.status === 'error' && (
*