import { useResourceNames } from '@viamrobotics/svelte-sdk';
import { getContext, setContext } from 'svelte';
const RESOURCE_BY_NAME_CONTEXT_KEY = Symbol('resource-by-name-context');
const createResourceByName = (partID) => {
    const resourceNames = useResourceNames(partID);
    const resourceByName = $derived.by(() => {
        const results = {};
        for (const resourceName of resourceNames.current) {
            results[resourceName.name] = resourceName;
        }
        return results;
    });
    return {
        get current() {
            return resourceByName;
        },
    };
};
export const provideResourceByName = (partID) => {
    setContext(RESOURCE_BY_NAME_CONTEXT_KEY, createResourceByName(partID));
};
export const useResourceByName = () => {
    return getContext(RESOURCE_BY_NAME_CONTEXT_KEY);
};
