import { FieldSchema, Objects } from '@ephox/boulder';
import { Id } from '@ephox/katamari';
import * as Fields from '../../data/Fields';
import * as TieredMenuSpec from '../../ui/single/TieredMenuSpec';
import { Composing } from '../behaviour/Composing';
import { Highlighting } from '../behaviour/Highlighting';
import { Keying } from '../behaviour/Keying';
import { Replacing } from '../behaviour/Replacing';
import * as SketchBehaviours from '../component/SketchBehaviours';
import { single } from './Sketcher';
const tieredData = (primary, menus, expansions) => ({
    primary,
    menus,
    expansions
});
const singleData = (name, menu) => ({
    primary: name,
    menus: Objects.wrap(name, menu),
    expansions: {}
});
const collapseItem = (text) => ({
    value: Id.generate(TieredMenuSpec.collapseItem()),
    meta: {
        text
    }
});
const tieredMenu = single({
    name: 'TieredMenu',
    configFields: [
        Fields.onStrictKeyboardHandler('onExecute'),
        Fields.onStrictKeyboardHandler('onEscape'),
        Fields.onStrictHandler('onOpenMenu'),
        Fields.onStrictHandler('onOpenSubmenu'),
        Fields.onHandler('onRepositionMenu'),
        Fields.onHandler('onCollapseMenu'),
        FieldSchema.defaulted('highlightImmediately', true),
        FieldSchema.requiredObjOf('data', [
            FieldSchema.required('primary'),
            FieldSchema.required('menus'),
            FieldSchema.required('expansions')
        ]),
        FieldSchema.defaulted('fakeFocus', false),
        Fields.onHandler('onHighlight'),
        Fields.onHandler('onHover'),
        Fields.tieredMenuMarkers(),
        FieldSchema.required('dom'),
        FieldSchema.defaulted('navigateOnHover', true),
        FieldSchema.defaulted('stayInDom', false),
        SketchBehaviours.field('tmenuBehaviours', [Keying, Highlighting, Composing, Replacing]),
        FieldSchema.defaulted('eventOrder', {})
    ],
    apis: {
        collapseMenu: (apis, tmenu) => {
            apis.collapseMenu(tmenu);
        },
        highlightPrimary: (apis, tmenu) => {
            apis.highlightPrimary(tmenu);
        },
        repositionMenus: (apis, tmenu) => {
            apis.repositionMenus(tmenu);
        }
    },
    factory: TieredMenuSpec.make,
    extraApis: {
        tieredData,
        singleData,
        collapseItem
    }
});
export { tieredMenu };
//# sourceMappingURL=TieredMenu.js.map