import { UmbContextBase } from '../../../libs/class-api/index.js';
import { UMB_WORKSPACE_CONTEXT } from '../../core/workspace/index.js';
import { UmbArrayState } from '../../../libs/observable-api/index.js';
import { UMB_MENU_STRUCTURE_WORKSPACE_CONTEXT } from '../../core/menu/index.js';
export class UmbLanguageNavigationStructureWorkspaceContext extends UmbContextBase {
    // TODO: figure out the correct type where we have "data" available
    #workspaceContext;
    #structure;
    constructor(host) {
        super(host, UMB_MENU_STRUCTURE_WORKSPACE_CONTEXT);
        this.#structure = new UmbArrayState([], (x) => x.unique);
        this.structure = this.#structure.asObservable();
        // 'UmbMenuStructureWorkspaceContext' is Obsolete, will be removed in v.18
        this.provideContext('UmbMenuStructureWorkspaceContext', this);
        this.consumeContext(UMB_WORKSPACE_CONTEXT, (instance) => {
            this.#workspaceContext = instance;
            this.#requestStructure();
        });
    }
    async #requestStructure() {
        const data = (await this.observe(this.#workspaceContext?.data, () => { })?.asPromise());
        if (!data)
            throw new Error('Data is not available');
        const items = [
            // TODO: figure out if we can get the root from somewhere
            // so we don't have to hardcode it
            {
                unique: null,
                entityType: 'language-root',
                name: 'Languages',
                isFolder: false,
            },
            {
                unique: data.unique,
                entityType: data.entityType,
                name: data.name,
                isFolder: false,
            },
        ];
        this.#structure.setValue(items);
    }
}
export default UmbLanguageNavigationStructureWorkspaceContext;
