"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dropdownMenuInjectionKey = void 0;
const vue_1 = require("vue");
const DropdownOption_1 = require("./DropdownOption");
const DropdownDivider_1 = require("./DropdownDivider");
const DropdownGroup_1 = require("./DropdownGroup");
const utils_1 = require("./utils");
const Dropdown_1 = require("./Dropdown");
exports.dropdownMenuInjectionKey = Symbol('dropdownMenu');
exports.default = vue_1.defineComponent({
    name: 'DropdownMenu',
    props: {
        clsPrefix: {
            type: String,
            required: true
        },
        tmNodes: {
            type: Array,
            default: () => []
        },
        parentKey: {
            type: [String, Number],
            default: null
        }
    },
    setup(props) {
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        const { renderIconRef } = vue_1.inject(Dropdown_1.dropdownInjectionKey);
        vue_1.provide(exports.dropdownMenuInjectionKey, {
            showIconRef: vue_1.computed(() => {
                const renderIcon = renderIconRef.value;
                return props.tmNodes.some((tmNode) => {
                    const { rawNode } = tmNode;
                    if (utils_1.isGroupNode(rawNode)) {
                        return rawNode.children.some((rawChild) => renderIcon ? renderIcon(rawChild) : rawChild.icon);
                    }
                    return renderIcon ? renderIcon(rawNode) : rawNode.icon;
                });
            }),
            hasSubmenuRef: vue_1.computed(() => {
                return props.tmNodes.some((tmNode) => {
                    const { rawNode } = tmNode;
                    if (utils_1.isGroupNode(rawNode)) {
                        return rawNode.children.some((rawChild) => utils_1.isSubmenuNode(rawChild));
                    }
                    return utils_1.isSubmenuNode(rawNode);
                });
            })
        });
    },
    render() {
        const { parentKey, clsPrefix } = this;
        return (vue_1.h("div", { class: `${clsPrefix}-dropdown-menu` }, this.tmNodes.map((tmNode) => {
            if (utils_1.isDividerNode(tmNode.rawNode)) {
                return vue_1.h(DropdownDivider_1.default, { clsPrefix: clsPrefix, key: tmNode.key });
            }
            if (utils_1.isGroupNode(tmNode.rawNode)) {
                return (vue_1.h(DropdownGroup_1.default, { clsPrefix: clsPrefix, tmNode: tmNode, parentKey: parentKey, key: tmNode.key }));
            }
            return (vue_1.h(DropdownOption_1.default, { clsPrefix: clsPrefix, tmNode: tmNode, parentKey: parentKey, key: tmNode.key }));
        })));
    }
});
