"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.itemRenderer = void 0;
const vue_1 = require("vue");
const _utils_1 = require("../../_utils");
const MenuOptionGroup_1 = __importStar(require("./MenuOptionGroup"));
const Submenu_1 = __importStar(require("./Submenu"));
const MenuOption_1 = __importStar(require("./MenuOption"));
const groupPropKeys = (0, _utils_1.keysOf)(MenuOptionGroup_1.menuItemGroupProps);
const itemPropKeys = (0, _utils_1.keysOf)(MenuOption_1.menuItemProps);
const submenuPropKeys = (0, _utils_1.keysOf)(Submenu_1.submenuProps);
function itemRenderer(tmNode, menuProps) {
    const { labelField } = menuProps;
    const { rawNode, key, level, isGroup } = tmNode;
    const props = Object.assign(Object.assign({}, rawNode), { title: (rawNode.title || rawNode[labelField]), extra: rawNode.titleExtra || rawNode.extra, key, internalKey: key, // since key can't be used as a prop
        level, root: level === 0, isGroup });
    if (tmNode.children) {
        if (tmNode.isGroup) {
            return (0, vue_1.h)(MenuOptionGroup_1.default, (0, _utils_1.keep)(props, groupPropKeys, { tmNodes: tmNode.children, key }));
        }
        return (0, vue_1.h)(Submenu_1.default, (0, _utils_1.keep)(props, submenuPropKeys, {
            key,
            rawNodes: tmNode.rawNode[menuProps.childrenField],
            tmNodes: tmNode.children,
            tmNode
        }));
    }
    else {
        return (0, vue_1.h)(MenuOption_1.default, (0, _utils_1.keep)(props, itemPropKeys, {
            key,
            tmNode
        }));
    }
}
exports.itemRenderer = itemRenderer;
