import { h } from 'vue';
import { keep, keysOf } from '../../_utils';
import NMenuOptionGroup, { menuItemGroupProps } from './MenuOptionGroup';
import NSubmenu, { submenuProps } from './Submenu';
import NMenuOption, { menuItemProps } from './MenuOption';
const groupPropKeys = keysOf(menuItemGroupProps);
const itemPropKeys = keysOf(menuItemProps);
const submenuPropKeys = keysOf(submenuProps);
export 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 h(NMenuOptionGroup, keep(props, groupPropKeys, { tmNodes: tmNode.children, key }));
        }
        return h(NSubmenu, keep(props, submenuPropKeys, {
            key,
            rawNodes: tmNode.rawNode[menuProps.childrenField],
            tmNodes: tmNode.children,
            tmNode
        }));
    }
    else {
        return h(NMenuOption, keep(props, itemPropKeys, {
            key,
            tmNode
        }));
    }
}
