"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtensionTreeNode = exports.ExtensionCompositeTreeNode = exports.ExtensionTreeRoot = void 0;
const ide_components_1 = require("@opensumi/ide-components");
const ide_core_common_1 = require("@opensumi/ide-core-common");
class ExtensionTreeRoot extends ide_components_1.CompositeTreeNode {
    static is(node) {
        return !!node && 'children' in node && !node.parent;
    }
    constructor(treeViewDataProvider, treeViewId = '') {
        super(treeViewDataProvider, undefined);
        this.treeViewId = treeViewId;
    }
    get treeItemId() {
        return `TreeViewRoot_${this.treeViewId}`;
    }
    get name() {
        return `TreeViewRoot_${this.id}`;
    }
    get expanded() {
        return true;
    }
    get displayName() {
        return this._displayName;
    }
    dispose() {
        super.dispose();
    }
}
exports.ExtensionTreeRoot = ExtensionTreeRoot;
class ExtensionCompositeTreeNode extends ide_components_1.CompositeTreeNode {
    constructor(tree, parent, label, description = '', icon = '', tooltip = '', command, contextValue = '', treeItemId = '', actions, _checkboxInfo, _accessibilityInformation, expanded, sourceUri) {
        super(tree, parent, undefined, { name: encodeURIComponent(treeItemId) });
        this.description = description;
        this.icon = icon;
        this.contextValue = contextValue;
        this.treeItemId = treeItemId;
        this.actions = actions;
        this._checkboxInfo = _checkboxInfo;
        this._accessibilityInformation = _accessibilityInformation;
        this._resolved = false;
        this.isExpanded = expanded || false;
        this.sourceUri = sourceUri;
        this._command = command;
        this._tooltip = tooltip;
        if ((0, ide_core_common_1.isString)(label)) {
            this._displayName = label;
        }
        else if ((0, ide_core_common_1.isObject)(label)) {
            this._displayName = label.label;
            this._hightlights = label.highlights;
            this._strikethrough = label.strikethrough;
        }
    }
    get resolved() {
        return this._resolved;
    }
    get command() {
        return this._command;
    }
    get tooltip() {
        return this._tooltip;
    }
    get displayName() {
        return this._displayName;
    }
    get checkboxInfo() {
        return this._checkboxInfo;
    }
    get accessibilityInformation() {
        var _a, _b;
        return {
            role: ((_a = this._accessibilityInformation) === null || _a === void 0 ? void 0 : _a.role) || 'treeitem',
            label: ((_b = this._accessibilityInformation) === null || _b === void 0 ? void 0 : _b.label) || this.displayName,
        };
    }
    get strikethrough() {
        return this._strikethrough;
    }
    get uri() {
        return this.sourceUri && ide_core_common_1.Uri.from(this.sourceUri);
    }
    get highlights() {
        return this._hightlights;
    }
    async resolveTreeItem() {
        var _a;
        const resolved = await this._tree.resolveTreeItem(this._tree.treeViewId, this.treeItemId);
        if (resolved) {
            // TODO: resolved markdown string tooltip
            this._tooltip = typeof resolved.tooltip === 'string' ? resolved.tooltip : (_a = resolved.tooltip) === null || _a === void 0 ? void 0 : _a.value;
            this._command = resolved.command;
        }
        this._resolved = true;
    }
    dispose() {
        super.dispose();
    }
}
exports.ExtensionCompositeTreeNode = ExtensionCompositeTreeNode;
class ExtensionTreeNode extends ide_components_1.TreeNode {
    constructor(tree, parent, label, description = '', icon = '', _tooltip, _command, contextValue = '', treeItemId = '', actions, _checkboxInfo, _accessibilityInformation, sourceUri) {
        super(tree, parent, undefined, { name: encodeURIComponent(treeItemId) });
        this.description = description;
        this.icon = icon;
        this._tooltip = _tooltip;
        this._command = _command;
        this.contextValue = contextValue;
        this.treeItemId = treeItemId;
        this.actions = actions;
        this._checkboxInfo = _checkboxInfo;
        this._accessibilityInformation = _accessibilityInformation;
        this.sourceUri = sourceUri;
        this._resolved = false;
        if ((0, ide_core_common_1.isString)(label)) {
            this._displayName = label;
        }
        else if ((0, ide_core_common_1.isObject)(label)) {
            this._displayName = label.label;
            this._hightlights = label.highlights;
            this._strikethrough = label.strikethrough;
        }
    }
    get resolved() {
        return this._resolved;
    }
    get command() {
        return this._command;
    }
    get uri() {
        return this.sourceUri && ide_core_common_1.Uri.from(this.sourceUri);
    }
    get tooltip() {
        return this._tooltip;
    }
    get displayName() {
        return this._displayName;
    }
    get checkboxInfo() {
        return this._checkboxInfo;
    }
    get accessibilityInformation() {
        var _a, _b;
        return {
            role: ((_a = this._accessibilityInformation) === null || _a === void 0 ? void 0 : _a.role) || 'treeitem',
            label: ((_b = this._accessibilityInformation) === null || _b === void 0 ? void 0 : _b.label) || this.displayName,
        };
    }
    get strikethrough() {
        return this._strikethrough;
    }
    get highlights() {
        return this._hightlights;
    }
    async resolveTreeItem() {
        var _a;
        const resolved = await this._tree.resolveTreeItem(this._tree.treeViewId, this.treeItemId);
        if (resolved) {
            // TODO: resolved markdown string tooltip
            this._tooltip = typeof resolved.tooltip === 'string' ? resolved.tooltip : (_a = resolved.tooltip) === null || _a === void 0 ? void 0 : _a.value;
            this._command = resolved.command;
        }
        this._resolved = true;
    }
}
exports.ExtensionTreeNode = ExtensionTreeNode;
//# sourceMappingURL=tree-view.node.defined.js.map