import { getContext, setContext } from 'svelte';
import { useFragmentInfo } from './useFragmentInfo.svelte';
import { useFrames } from './useFrames.svelte';
import { usePartConfig } from './usePartConfig.svelte';
const key = Symbol('frameless-components-context');
export const provideFramelessComponents = () => {
    const partConfig = usePartConfig();
    const fragmentInfo = useFragmentInfo();
    const frames = useFrames();
    const current = $derived.by(() => {
        const { components } = partConfig.current;
        const partComponentsWIthNoFrame = components
            ?.filter((component) => component.frame === undefined)
            .map((component) => component.name) ?? [];
        const fragmentComponentsWithNoFrame = new Set(partComponentsWIthNoFrame);
        for (const fragmentComponentName of Object.keys(fragmentInfo.current)) {
            if (frames.current.some((frame) => frame.referenceFrame === fragmentComponentName)) {
                continue;
            }
            fragmentComponentsWithNoFrame.add(fragmentComponentName);
        }
        return [...fragmentComponentsWithNoFrame];
    });
    setContext(key, {
        get current() {
            return current;
        },
    });
};
export const useFramelessComponents = () => {
    return getContext(key);
};
