/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
'use strict';

var index = require('./index-C_J7n4Dv.js');
var events = require('./events-8W8yXGxn.js');
require('./streamAttributes-ce88H9XR.js');
require('./entities-BhIrCJqA.js');
var utils = require('./utils-qErVs2Vt.js');
require('./bundle-BhTmftd-.js');
require('./bundle-Dsc8KJRQ.js');
require('./_commonjsHelpers-CBbBosIU.js');
require('./bundle-96sYCpzz.js');

const sceneTreeTableCellCss = () => `button{border:none;background:transparent;cursor:pointer;margin:0;padding:0}:host{display:flex;align-items:center;box-sizing:border-box;--scene-tree-cell-background-hover:var(--blue-200);--scene-tree-cell-background-selected:var(--blue-300);--scene-tree-cell-text-positioning:left;--scene-tree-cell-padding:0.25rem 0;font-size:var(--scene-tree-default-font-size, unset);font-family:var(--scene-tree-default-font-family, unset);color:var(--scene-tree-default-font-color, #444444)}:host([is-hovered]){background:var(--scene-tree-cell-background-hover)}:host([is-selected]){background:var(--scene-tree-cell-background-selected)}.wrapper{display:flex;align-items:center;box-sizing:border-box;width:100%;height:100%;padding:var(--scene-tree-cell-padding)}.content{width:100%;text-align:var(--scene-tree-cell-text-positioning);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.column-spacer{width:var(--scene-tree-table-column-gap)}.expand-btn{cursor:pointer;display:flex;align-items:center;justify-content:center;min-width:24px;min-height:24px}:host([is-leaf]) .expand-btn,:host([is-end-item]) .expand-btn{visibility:hidden;cursor:default}.no-shrink{flex-shrink:0}.end-item-btn{cursor:default;display:flex;align-items:center;justify-content:center;min-width:24px;min-height:24px}:host(:not([is-end-item])) .end-item-btn{visibility:hidden;cursor:default}.end-item-icon{width:14px;height:14px;fill:var(--scene-tree-secondary-font-color, var(--neutral-600))}.visibility-btn,.isolate-btn{cursor:pointer;display:flex;align-items:center;justify-content:center;width:20px;height:20px}.icon{width:14px;height:14px;fill:var(--scene-tree-default-font-color, currentColor)}`;

const SceneTreeTableCell = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.expandToggled = index.createEvent(this, "expandToggled");
        this.visibilityToggled = index.createEvent(this, "visibilityToggled");
        this.selectionToggled = index.createEvent(this, "selectionToggled");
        this.isolatePressed = index.createEvent(this, "isolatePressed");
        this.cellLoaded = index.createEvent(this, "cellLoaded");
        /**
         * The value to display in this cell if the `value` specified is
         * undefined. Defaults to "--".
         */
        this.placeholder = '--';
        /**
         * Whether to always show the requested icons in the cell. If false,
         * the icons will only appear when hovering over the cell.
         */
        this.alwaysShowIcons = false;
        /**
         * @internal
         */
        this.hovered = false;
        this.displayValue = () => {
            const resp = this.value == null || this.value.trim() === ''
                ? this.placeholder
                : this.value;
            return resp;
        };
        this.handleCellPointerEnter = () => {
            var _a, _b, _c;
            (_a = this.hoverController) === null || _a === void 0 ? void 0 : _a.setHovered((_c = (_b = this.node) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.hex);
        };
        this.handleCellPointerLeave = () => {
            var _a;
            (_a = this.hoverController) === null || _a === void 0 ? void 0 : _a.setHovered(undefined);
        };
        this.handleCellPointerUp = (event) => {
            if (!this.isScrolling &&
                this.node != null &&
                this.tree != null &&
                this.longPressTimer != null) {
                if (this.selectionHandler != null) {
                    this.selectionHandler(event, this.node, this.tree);
                }
                else {
                    this.performDefaultSelectionOperation(event);
                }
                this.selectionToggled.emit({ node: this.node, originalEvent: event });
            }
            this.clearLongPressTimer();
        };
        this.handleCellPointerDown = (event) => {
            this.restartLongPressTimer();
        };
        this.createActionPointerUpHandler = (action) => {
            return (event) => {
                // Blur the `hostEl` after a `preventDefault` to clear focus that
                // is left on the element after `pointerdown` event.
                event.preventDefault();
                event.stopPropagation();
                utils.blurElement(this.hostEl);
                action(event);
            };
        };
        this.toggleExpansion = async (event) => {
            if (this.tree != null && this.node != null) {
                if (this.expansionHandler != null) {
                    this.expansionHandler(event, this.node, this.tree);
                }
                else {
                    await this.performDefaultExpansionOperation(this.node, this.tree);
                }
                this.expandToggled.emit({ node: this.node, originalEvent: event });
            }
        };
        this.toggleVisibility = async (event) => {
            if (this.tree != null && this.node != null) {
                if (this.visibilityHandler != null) {
                    this.visibilityHandler(event, this.node, this.tree);
                }
                else {
                    await this.performDefaultVisibilityOperation(this.node, this.tree);
                }
                this.visibilityToggled.emit({ node: this.node, originalEvent: event });
            }
        };
        this.isolate = async (event) => {
            if (this.tree != null && this.node != null) {
                if (this.isolateHandler != null) {
                    this.isolateHandler(event, this.node, this.tree);
                }
                else {
                    await this.performDefaultIsolateOperation(this.node, this.tree);
                }
                this.isolatePressed.emit({ node: this.node, originalEvent: event });
            }
        };
        this.performDefaultSelectionOperation = (event) => {
            var _a, _b, _c, _d, _e, _f;
            if (!event.defaultPrevented && event.button === 0) {
                if ((event.ctrlKey || event.metaKey) && ((_a = this.node) === null || _a === void 0 ? void 0 : _a.selected)) {
                    (_b = this.tree) === null || _b === void 0 ? void 0 : _b.deselectItem(this.node);
                }
                else if ((_c = this.node) === null || _c === void 0 ? void 0 : _c.selected) {
                    (_d = this.tree) === null || _d === void 0 ? void 0 : _d.selectItem(this.node, {
                        recurseParent: true,
                    });
                }
                else if (!((_e = this.node) === null || _e === void 0 ? void 0 : _e.selected)) {
                    (_f = this.tree) === null || _f === void 0 ? void 0 : _f.selectItem(this.node, {
                        append: event.ctrlKey || event.metaKey,
                        range: event.shiftKey,
                    });
                }
            }
        };
        this.performDefaultVisibilityOperation = async (node, tree) => {
            await tree.toggleItemVisibility(node);
        };
        this.performDefaultIsolateOperation = async (node, tree) => {
            await tree.isolateItem(node);
        };
        this.performDefaultExpansionOperation = async (node, tree) => {
            await tree.toggleExpandItem(node);
        };
    }
    componentDidLoad() {
        var _a;
        this.hoverListener = (_a = this.hoverController) === null || _a === void 0 ? void 0 : _a.stateChanged((id) => {
            var _a, _b;
            this.hovered = id === ((_b = (_a = this.node) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.hex);
        });
        this.cellLoaded.emit();
        this.clearLongPressTimer();
    }
    disconnectedCallback() {
        var _a;
        (_a = this.hoverListener) === null || _a === void 0 ? void 0 : _a.dispose();
        this.clearLongPressTimer();
    }
    componentWillRender() {
        var _a, _b, _c, _d, _e, _f;
        this.toggleAttribute('is-hovered', this.hovered);
        this.toggleAttribute('is-hidden', !((_a = this.node) === null || _a === void 0 ? void 0 : _a.visible));
        this.toggleAttribute('is-selected', !!((_b = this.node) === null || _b === void 0 ? void 0 : _b.selected));
        this.toggleAttribute('is-partial', !!((_c = this.node) === null || _c === void 0 ? void 0 : _c.partiallyVisible));
        this.toggleAttribute('is-leaf', !!((_d = this.node) === null || _d === void 0 ? void 0 : _d.isLeaf));
        this.toggleAttribute('is-end-item', !!((_e = this.node) === null || _e === void 0 ? void 0 : _e.endItem));
        this.toggleAttribute('is-filter-hit', !!((_f = this.node) === null || _f === void 0 ? void 0 : _f.filterHit));
    }
    render() {
        var _a, _b, _c, _d;
        // Overrides the `.hydrated` visibility when we have nothing to display
        const hiddenStyle = this.node == null ? { visibility: 'hidden' } : undefined;
        const backgroundColorStyle = this.getBackgroundColorStyle();
        const endItemIcon = this.getEndItemIcon();
        const expansionIcon = this.getExpansionIcon();
        const isolateIcon = this.getIsolateIcon();
        const visibilityIcon = this.getVisibilityIcon();
        const showSpaceForExpansionIcon = this.expandToggle && !endItemIcon;
        const showSpaceForEndItemIcon = endItemIcon && !showSpaceForExpansionIcon;
        return (index.h(index.Host, { key: '703090cacf3d026e220ead0a051d70b186fa056e', onPointerEnter: this.handleCellPointerEnter, onPointerLeave: this.handleCellPointerLeave, onPointerUp: this.handleCellPointerUp, onPointerDown: this.handleCellPointerDown, style: {
                ...hiddenStyle,
                'background-color': backgroundColorStyle,
            } }, index.h("div", { key: '25a45f3cebed75a1d0e469cce01e1cabec5450c4', class: "wrapper" }, index.h("div", { key: '7ba2f3c1b9a5551287f6683f87de841f0717e87b', class: "no-shrink" }, index.h("slot", { key: '04bd203d0e034aa4fce3a0b64d24718ab0ba50af', name: "left-gutter" })), showSpaceForExpansionIcon && (index.h("button", { key: '9dfa16123e24eeb90e208aa0d5936b9bacd9d8f4', class: "expand-btn no-shrink", "data-test-id": 'expand-' + ((_a = this.node) === null || _a === void 0 ? void 0 : _a.name), onPointerUp: this.createActionPointerUpHandler(this.toggleExpansion) }, expansionIcon && (index.h("vertex-viewer-icon", { key: 'dd3c2a86b90d627b3234b76075dafef393418945', class: "icon", name: expansionIcon, size: "sm" })))), showSpaceForEndItemIcon && (index.h("button", { key: '4ba96f6f5d8c0ec7559698b11bfa798a695f8504', class: "end-item-btn no-shrink", "data-test-id": 'end-item-' + ((_b = this.node) === null || _b === void 0 ? void 0 : _b.name) }, endItemIcon && (index.h("vertex-viewer-icon", { key: '57f13de85747c6b1534ea0523e48d73b18125524', class: "end-item-icon", name: endItemIcon, size: "sm" })))), index.h("div", { key: '0757b6b02df6b48a90b8eaedf3755756f64e53c3', class: "content" }, this.value != null && this.value.trim() !== '' ? (index.h("slot", null, this.displayValue())) : (index.h("slot", { name: "placeholder" }, this.placeholder))), this.isolateButton && (index.h("button", { key: '780fc0d60ddf630f9f2f60579bb9f9d25decf59c', class: "isolate-btn no-shrink", "data-test-id": 'isolate-btn-' + ((_c = this.node) === null || _c === void 0 ? void 0 : _c.name), onPointerUp: this.createActionPointerUpHandler(this.isolate) }, isolateIcon && (index.h("vertex-viewer-icon", { key: '14c460641f97b7486d5393274a1ac53aad8dc62f', class: "icon", name: "locate", size: "sm" })))), this.visibilityToggle && (index.h("button", { key: 'b2455e14dc5325e713e2eab8730c7f5d9526336f', class: "visibility-btn no-shrink", "data-test-id": 'visibility-btn-' + ((_d = this.node) === null || _d === void 0 ? void 0 : _d.name), onPointerUp: this.createActionPointerUpHandler(this.toggleVisibility) }, visibilityIcon && (index.h("vertex-viewer-icon", { key: '2c761416d88693cea84490468680c1d39ed27d36', class: "icon", name: visibilityIcon, size: "sm" })))), index.h("div", { key: 'a5728a0c22cea6fea12e3a4b54a4f07e5ccbf768', class: "no-shrink" }, index.h("slot", { key: '76cc87ec6b2f154324de09f261d4337d6c81ae0c', name: "right-gutter" })), !this.visibilityToggle && !this.isolateButton && (index.h("div", { key: '477726d5ac236b87eecaa5652f67d65a7c28108f', class: "column-spacer" })))));
    }
    toggleAttribute(attr, value) {
        if (value) {
            this.hostEl.setAttribute(attr, '');
        }
        else {
            this.hostEl.removeAttribute(attr);
        }
    }
    clearLongPressTimer() {
        if (this.longPressTimer != null) {
            window.clearTimeout(this.longPressTimer);
        }
        this.longPressTimer = undefined;
    }
    restartLongPressTimer() {
        this.clearLongPressTimer();
        this.longPressTimer = window.setTimeout(() => {
            this.clearLongPressTimer();
        }, events.defaultEventConfig.longPressThreshold);
    }
    getBackgroundColorStyle() {
        var _a, _b;
        const backgroundColorStyle = this.getCssVariableWithFallbacks(`--scene-tree-row-background-color-depth-${(_a = this.node) === null || _a === void 0 ? void 0 : _a.depth}`, '--scene-tree-row-background-color');
        const selectedBackgroundColorStyle = this.getCssVariableWithFallbacks('--scene-tree-selected-row-background-color', '--scene-tree-cell-background-selected');
        const hoveredBackgroundColorStyle = this.getCssVariableWithFallbacks('--scene-tree-hovered-row-background-color', '--scene-tree-cell-background-hover');
        if (!!((_b = this.node) === null || _b === void 0 ? void 0 : _b.selected)) {
            return selectedBackgroundColorStyle;
        }
        else if (this.hovered) {
            return hoveredBackgroundColorStyle;
        }
        return backgroundColorStyle;
    }
    getCssVariableWithFallbacks(variable, ...fallbacks) {
        const sequencedFallbacks = [...fallbacks].reverse();
        return [...sequencedFallbacks, variable].reduce((res, s) => `var(${s}, ${res})`, 'unset');
    }
    getIsolateIcon() {
        if (this.hovered || this.alwaysShowIcons) {
            return 'locate';
        }
        return undefined;
    }
    getExpansionIcon() {
        var _a, _b, _c;
        if (!((_a = this.node) === null || _a === void 0 ? void 0 : _a.isLeaf) && !((_b = this.node) === null || _b === void 0 ? void 0 : _b.endItem)) {
            return ((_c = this.node) === null || _c === void 0 ? void 0 : _c.expanded) ? 'chevron-down' : 'chevron-right';
        }
        return undefined;
    }
    getEndItemIcon() {
        var _a, _b, _c;
        // Return the end item icon for an item if it is set as an end item and either is not a leaf item
        // or matches the filter. Note that in the filtered view, an end item matching the filter will always be
        // marked as a leaf node because its children will be excluded from the search results and therefore
        // not present in the filtered tree.
        if (this.endItemIndicator &&
            ((_a = this.node) === null || _a === void 0 ? void 0 : _a.endItem) &&
            (!((_b = this.node) === null || _b === void 0 ? void 0 : _b.isLeaf) || ((_c = this.node) === null || _c === void 0 ? void 0 : _c.filterHit))) {
            return 'lock';
        }
        return undefined;
    }
    getVisibilityIcon() {
        var _a, _b, _c, _d, _e;
        if ((this.hovered || this.alwaysShowIcons) &&
            !((_a = this.node) === null || _a === void 0 ? void 0 : _a.partiallyVisible) &&
            ((_b = this.node) === null || _b === void 0 ? void 0 : _b.visible)) {
            return 'eye-open';
        }
        else if (!((_c = this.node) === null || _c === void 0 ? void 0 : _c.partiallyVisible) && !((_d = this.node) === null || _d === void 0 ? void 0 : _d.visible)) {
            return 'eye-half';
        }
        else if ((_e = this.node) === null || _e === void 0 ? void 0 : _e.partiallyVisible) {
            return 'eye-half-dotted';
        }
        return undefined;
    }
    get hostEl() { return index.getElement(this); }
};
SceneTreeTableCell.style = sceneTreeTableCellCss();

exports.vertex_scene_tree_table_cell = SceneTreeTableCell;
//# sourceMappingURL=vertex-scene-tree-table-cell.entry.cjs.js.map

//# sourceMappingURL=vertex-scene-tree-table-cell.cjs.entry.js.map