'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-5aa5c817.js');
const a11y = require('./a11y-802de67a.js');

const SubMenu = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
    }
    get el() { return index.getElement(this); }
    /** 标题 */
    label = '';
    /** 图标 */
    icon;
    /**
     * 是否处于折叠态（由父 hb-menu 在 collapsed=true 时透传）。
     * 折叠态下不再就地展开，而是悬停弹出浮层。
     */
    collapsed = false;
    isOpen = false;
    isHover = false;
    toggle = () => {
        // 折叠态不就地切换展开（改由 hover 浮层承载子菜单）
        if (this.collapsed)
            return;
        this.isOpen = !this.isOpen;
    };
    handleTitleKeydown = (e) => {
        if (a11y.isActivationKey(e.key)) {
            e.preventDefault();
            this.toggle();
        }
    };
    handleMouseEnter = () => {
        if (!this.collapsed)
            return;
        this.isHover = true;
    };
    handleMouseLeave = () => {
        if (!this.collapsed)
            return;
        this.isHover = false;
    };
    /** 折叠态浮层内点击子项后，收起浮层 */
    handleChildrenClick = () => {
        if (!this.collapsed)
            return;
        this.isHover = false;
    };
    render() {
        // 折叠态：浮层是否显示由 hover 决定；非折叠态：就地展开由 isOpen 决定
        const showChildren = this.collapsed ? this.isHover : this.isOpen;
        return (index.h("li", { key: '2158b7ce59919c89c5f86a1218e1f2c16fb7cc11', class: {
                'hb-sub-menu': true,
                'hb-sub-menu--open': this.isOpen,
                'hb-sub-menu--collapsed': this.collapsed,
            }, role: "menuitem", "aria-haspopup": "menu", "aria-expanded": showChildren ? 'true' : 'false', onMouseEnter: this.handleMouseEnter, onMouseLeave: this.handleMouseLeave }, index.h("div", { key: 'ed1b49c0417a21673d8eac14dfb15e31db722917', class: "hb-sub-menu__title", role: "button", tabindex: 0, "aria-expanded": showChildren ? 'true' : 'false',
            // 折叠态用原生 title 提供文字提示（图标条场景）
            title: this.collapsed ? this.label : undefined, onClick: this.toggle, onKeyDown: this.handleTitleKeydown }, this.icon && index.h("span", { key: '488430d18a0a4c2fd81f38d621988b3a06ef874a', class: "hb-sub-menu__icon" }, this.icon), index.h("span", { key: 'ba16d8aaddeba6ec00a9b19ac4069802a1cc503b', class: "hb-sub-menu__label" }, this.label), index.h("span", { key: 'cf3b32672f9f36d4ffbe570f7dbad1e2755afe3c', class: { 'hb-sub-menu__arrow': true, 'hb-sub-menu__arrow--open': showChildren } }, "\u25B6")), showChildren && (index.h("ul", { key: '6f0404f6e5b89ae0c59b47630f8d17620800b46f', class: {
                'hb-sub-menu__children': true,
                'hb-sub-menu__children--popover': this.collapsed,
            }, role: "menu", onClick: this.handleChildrenClick }, index.h("slot", { key: '795f95cc807e590339faff8745eb6c36c326f9f2' })))));
    }
};

exports.hb_sub_menu = SubMenu;

//# sourceMappingURL=hb-sub-menu.cjs.entry.js.map