'use client';

import {useMemo} from 'react';
import {useWorkspace} from '@/shared/providers/WorkspaceProvider';
import type {Scope} from '@/shared/services/httpClient';

/**
 * The {storeId, range} every scoped request is filtered by, in one hook.
 *
 * Feature hooks call this instead of taking scope as an argument, so a page
 * never threads query parameters through its component tree — which is how the
 * dashboard's six panels are guaranteed to agree about what period they are
 * showing.
 *
 * Memoised on its two fields so the object identity only changes when the
 * scope actually does. useResource keys off the serialized URL rather than
 * this reference, but a stable object keeps it out of other dependency arrays.
 */
export function useScope(): Scope {
  const {storeId, range} = useWorkspace();
  return useMemo(() => ({storeId, range}), [storeId, range]);
}
