var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { UMB_WORKSPACE_CONTEXT } from '../../../workspace.context-token.js';
import { UMB_WORKSPACE_EDIT_PATH_PATTERN } from '../../../paths.js';
import { css, customElement, html, ifDefined, map, state } from '../../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../lit-element/index.js';
import { UmbTextStyles } from '../../../../style/index.js';
import { UMB_MENU_STRUCTURE_WORKSPACE_CONTEXT } from '../../../../menu/index.js';
import { UMB_SECTION_CONTEXT } from '../../../../section/index.js';
let UmbWorkspaceBreadcrumbElement = class UmbWorkspaceBreadcrumbElement extends UmbLitElement {
    // TODO: figure out the correct context type
    #workspaceContext;
    #sectionContext;
    #structureContext;
    constructor() {
        super();
        this._name = '';
        this._structure = [];
        this._isNew = false;
        this.consumeContext(UMB_SECTION_CONTEXT, (instance) => {
            this.#sectionContext = instance;
        });
        this.consumeContext(UMB_WORKSPACE_CONTEXT, (instance) => {
            this.#workspaceContext = instance;
            this.#observeIsNew();
            this.#observeStructure();
            this.#observeName();
        });
        this.consumeContext(UMB_MENU_STRUCTURE_WORKSPACE_CONTEXT, (instance) => {
            this.#structureContext = instance;
            this.#observeStructure();
        });
    }
    #observeIsNew() {
        this.observe(this.#workspaceContext?.isNew, (value) => {
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-ignore
            this._isNew = value || false;
        }, 'breadcrumbWorkspaceIsNewObserver');
    }
    #observeName() {
        this.observe(this.#workspaceContext?.name, 
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        (value) => (this._name = value || ''), 'breadcrumbWorkspaceNameObserver');
    }
    #observeStructure() {
        if (!this.#structureContext || !this.#workspaceContext)
            return;
        this.observe(this.#structureContext.structure, (value) => {
            this._structure = value;
        }, 'menuStructureObserver');
    }
    #getHref(structureItem) {
        if (structureItem.isFolder || !structureItem.unique)
            return undefined;
        const sectionName = this.#sectionContext?.getPathname();
        if (!sectionName)
            return undefined;
        return UMB_WORKSPACE_EDIT_PATH_PATTERN.generateAbsolute({
            sectionName,
            entityType: structureItem.entityType,
            unique: structureItem.unique,
        });
    }
    render() {
        const structure = this._isNew ? this._structure : this._structure.slice(0, -1);
        return html `
			<uui-breadcrumbs>
				${map(structure, (structureItem) => html `<uui-breadcrumb-item href=${ifDefined(this.#getHref(structureItem))}
							>${this.localize.string(structureItem.name)}</uui-breadcrumb-item
						>`)}
				<uui-breadcrumb-item last-item>${this._name}</uui-breadcrumb-item>
			</uui-breadcrumbs>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			:host {
				margin-left: var(--uui-size-layout-1);
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbWorkspaceBreadcrumbElement.prototype, "_name", void 0);
__decorate([
    state()
], UmbWorkspaceBreadcrumbElement.prototype, "_structure", void 0);
__decorate([
    state()
], UmbWorkspaceBreadcrumbElement.prototype, "_isNew", void 0);
UmbWorkspaceBreadcrumbElement = __decorate([
    customElement('umb-workspace-breadcrumb')
], UmbWorkspaceBreadcrumbElement);
export { UmbWorkspaceBreadcrumbElement };
export default UmbWorkspaceBreadcrumbElement;
