import { getContext, setContext } from 'svelte';
import { useQuery, useWorld } from '../../ecs';
import * as selectionTraits from './traits';
const key = Symbol('selection-plugin-context');
export const provideSelectionPlugin = () => {
    const world = useWorld();
    const entities = useQuery(selectionTraits.SelectionEnclosedPoints);
    const ctx = setContext(key, {
        get current() {
            return entities.current;
        },
        clearSelections() {
            for (const entity of world.query(selectionTraits.SelectionEnclosedPoints)) {
                if (world.has(entity)) {
                    entity.destroy();
                }
            }
        },
    });
    return ctx;
};
export const useSelectionPlugin = () => {
    return getContext(key);
};
