'use client';

import {storeRepository} from '@/features/stores/repositories/storeRepository';
import {useResource} from '@/shared/hooks/useResource';
import {useScope} from '@/shared/hooks/useScope';

/**
 * Store data access. See features/dashboard/hooks/useDashboard for the pattern.
 */

/**
 * The directory always asks for ALL stores regardless of the workspace filter:
 * a page whose job is to compare locations cannot be filtered down to one, or
 * it has nothing to compare. The period still applies.
 */
export function useStoreList() {
  const {range} = useScope();
  return useResource(storeRepository.list({range, storeId: 'all'}));
}

export function useStore(storeId: string) {
  const {range} = useScope();
  return useResource(storeRepository.byId({range, storeId}, storeId), {
    // A single object is never "empty" — without this, useResource's default
    // array check would call a populated store empty.
    isEmpty: () => false,
  });
}
