var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
    function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
    var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
    var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
    var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
    var _, done = false;
    for (var i = decorators.length - 1; i >= 0; i--) {
        var context = {};
        for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
        for (var p in contextIn.access) context.access[p] = contextIn.access[p];
        context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
        var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
        if (kind === "accessor") {
            if (result === void 0) continue;
            if (result === null || typeof result !== "object") throw new TypeError("Object expected");
            if (_ = accept(result.get)) descriptor.get = _;
            if (_ = accept(result.set)) descriptor.set = _;
            if (_ = accept(result.init)) initializers.unshift(_);
        }
        else if (_ = accept(result)) {
            if (kind === "field") initializers.unshift(_);
            else descriptor[key] = _;
        }
    }
    if (target) Object.defineProperty(target, contextIn.name, descriptor);
    done = true;
};
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
    var useValue = arguments.length > 2;
    for (var i = 0; i < initializers.length; i++) {
        value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
    }
    return useValue ? value : void 0;
};
import { DeesElement, property, html, customElement, state, css, cssManager } from '@design.estate/dees-element';
let WccContextmenu = (() => {
    let _classDecorators = [customElement('wcc-contextmenu')];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _classSuper = DeesElement;
    let _menuItems_decorators;
    let _menuItems_initializers = [];
    let _menuItems_extraInitializers = [];
    let _x_decorators;
    let _x_initializers = [];
    let _x_extraInitializers = [];
    let _y_decorators;
    let _y_initializers = [];
    let _y_extraInitializers = [];
    let _visible_decorators;
    let _visible_initializers = [];
    let _visible_extraInitializers = [];
    var WccContextmenu = class extends _classSuper {
        static { _classThis = this; }
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _menuItems_decorators = [property({ type: Array })];
            _x_decorators = [property({ type: Number })];
            _y_decorators = [property({ type: Number })];
            _visible_decorators = [state()];
            __esDecorate(this, null, _menuItems_decorators, { kind: "accessor", name: "menuItems", static: false, private: false, access: { has: obj => "menuItems" in obj, get: obj => obj.menuItems, set: (obj, value) => { obj.menuItems = value; } }, metadata: _metadata }, _menuItems_initializers, _menuItems_extraInitializers);
            __esDecorate(this, null, _x_decorators, { kind: "accessor", name: "x", static: false, private: false, access: { has: obj => "x" in obj, get: obj => obj.x, set: (obj, value) => { obj.x = value; } }, metadata: _metadata }, _x_initializers, _x_extraInitializers);
            __esDecorate(this, null, _y_decorators, { kind: "accessor", name: "y", static: false, private: false, access: { has: obj => "y" in obj, get: obj => obj.y, set: (obj, value) => { obj.y = value; } }, metadata: _metadata }, _y_initializers, _y_extraInitializers);
            __esDecorate(this, null, _visible_decorators, { kind: "accessor", name: "visible", static: false, private: false, access: { has: obj => "visible" in obj, get: obj => obj.visible, set: (obj, value) => { obj.visible = value; } }, metadata: _metadata }, _visible_initializers, _visible_extraInitializers);
            __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
            WccContextmenu = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        // Static method to show context menu at position
        static async show(event, menuItems) {
            event.preventDefault();
            event.stopPropagation();
            // Remove any existing context menu
            const existing = document.querySelector('wcc-contextmenu');
            if (existing) {
                existing.remove();
            }
            const menu = new WccContextmenu();
            menu.menuItems = menuItems;
            menu.x = event.clientX;
            menu.y = event.clientY;
            document.body.appendChild(menu);
            // Wait for render then adjust position if needed
            await menu.updateComplete;
            menu.adjustPosition();
        }
        #menuItems_accessor_storage = __runInitializers(this, _menuItems_initializers, []);
        get menuItems() { return this.#menuItems_accessor_storage; }
        set menuItems(value) { this.#menuItems_accessor_storage = value; }
        #x_accessor_storage = (__runInitializers(this, _menuItems_extraInitializers), __runInitializers(this, _x_initializers, 0));
        get x() { return this.#x_accessor_storage; }
        set x(value) { this.#x_accessor_storage = value; }
        #y_accessor_storage = (__runInitializers(this, _x_extraInitializers), __runInitializers(this, _y_initializers, 0));
        get y() { return this.#y_accessor_storage; }
        set y(value) { this.#y_accessor_storage = value; }
        #visible_accessor_storage = (__runInitializers(this, _y_extraInitializers), __runInitializers(this, _visible_initializers, false));
        get visible() { return this.#visible_accessor_storage; }
        set visible(value) { this.#visible_accessor_storage = value; }
        boundHandleOutsideClick = (__runInitializers(this, _visible_extraInitializers), this.handleOutsideClick.bind(this));
        boundHandleKeydown = this.handleKeydown.bind(this);
        static styles = [
            css `
      :host {
        position: fixed;
        z-index: 10000;
        opacity: 0;
        transform: scale(0.95) translateY(-5px);
        transition: opacity 0.15s ease, transform 0.15s ease;
        pointer-events: none;
      }

      :host(.visible) {
        opacity: 1;
        transform: scale(1) translateY(0);
        pointer-events: auto;
      }

      .menu {
        min-width: 160px;
        background: #0f0f0f;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 6px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
        padding: 4px 0;
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
        font-size: 12px;
      }

      .menu-item {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        color: #ccc;
        cursor: pointer;
        transition: background 0.1s ease;
        user-select: none;
      }

      .menu-item:hover {
        background: rgba(59, 130, 246, 0.15);
        color: #fff;
      }

      .menu-item.disabled {
        opacity: 0.4;
        cursor: not-allowed;
        pointer-events: none;
      }

      .menu-item .icon {
        font-family: 'Material Symbols Outlined';
        font-size: 16px;
        font-weight: normal;
        font-style: normal;
        line-height: 1;
        letter-spacing: normal;
        text-transform: none;
        white-space: nowrap;
        word-wrap: normal;
        direction: ltr;
        font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
        opacity: 0.7;
      }

      .menu-item:hover .icon {
        opacity: 1;
      }

      .menu-item .label {
        flex: 1;
      }
    `
        ];
        render() {
            return html `
      <div class="menu">
        ${this.menuItems.map(item => html `
          <div
            class="menu-item ${item.disabled ? 'disabled' : ''}"
            @click=${() => this.handleItemClick(item)}
          >
            ${item.iconName ? html `<span class="icon">${item.iconName}</span>` : null}
            <span class="label">${item.name}</span>
          </div>
        `)}
      </div>
    `;
        }
        async connectedCallback() {
            await super.connectedCallback();
            // Delay adding listeners to avoid immediate close
            requestAnimationFrame(() => {
                document.addEventListener('click', this.boundHandleOutsideClick);
                document.addEventListener('contextmenu', this.boundHandleOutsideClick);
                document.addEventListener('keydown', this.boundHandleKeydown);
                this.classList.add('visible');
            });
        }
        async disconnectedCallback() {
            await super.disconnectedCallback();
            document.removeEventListener('click', this.boundHandleOutsideClick);
            document.removeEventListener('contextmenu', this.boundHandleOutsideClick);
            document.removeEventListener('keydown', this.boundHandleKeydown);
        }
        adjustPosition() {
            const rect = this.getBoundingClientRect();
            const windowWidth = window.innerWidth;
            const windowHeight = window.innerHeight;
            let x = this.x;
            let y = this.y;
            // Adjust if menu goes off right edge
            if (x + rect.width > windowWidth - 10) {
                x = windowWidth - rect.width - 10;
            }
            // Adjust if menu goes off bottom edge
            if (y + rect.height > windowHeight - 10) {
                y = windowHeight - rect.height - 10;
            }
            // Ensure not off left or top
            if (x < 10)
                x = 10;
            if (y < 10)
                y = 10;
            this.style.left = `${x}px`;
            this.style.top = `${y}px`;
        }
        handleOutsideClick(e) {
            const path = e.composedPath();
            if (!path.includes(this)) {
                this.close();
            }
        }
        handleKeydown(e) {
            if (e.key === 'Escape') {
                this.close();
            }
        }
        async handleItemClick(item) {
            if (item.disabled)
                return;
            await item.action();
            this.close();
        }
        close() {
            this.classList.remove('visible');
            setTimeout(() => this.remove(), 150);
        }
        static {
            __runInitializers(_classThis, _classExtraInitializers);
        }
    };
    return WccContextmenu = _classThis;
})();
export { WccContextmenu };
//# sourceMappingURL=data:application/json;base64, 