import { FieldPresence, FieldSchema, StructureSchema, ValueType } from '@ephox/boulder';
import { Arr } from '@ephox/katamari';
import * as NativeEvents from '../api/events/NativeEvents';
import * as SystemEvents from '../api/events/SystemEvents';
import { nu as NuModification } from '../dom/DomModification';
const baseBehaviour = 'alloy.base.behaviour';
const schema = StructureSchema.objOf([
    FieldSchema.field('dom', 'dom', FieldPresence.required(), StructureSchema.objOf([
        // Note, no children.
        FieldSchema.required('tag'),
        FieldSchema.defaulted('styles', {}),
        FieldSchema.defaulted('classes', []),
        FieldSchema.defaulted('attributes', {}),
        FieldSchema.option('value'),
        FieldSchema.option('innerHtml')
    ])),
    FieldSchema.required('components'),
    FieldSchema.required('uid'),
    FieldSchema.defaulted('events', {}),
    FieldSchema.defaulted('apis', {}),
    // Use mergeWith in the future when pre-built behaviours conflict
    FieldSchema.field('eventOrder', 'eventOrder', FieldPresence.mergeWith({
        // Note, not using constant behaviour names to avoid code size of unused behaviours
        [SystemEvents.execute()]: ['disabling', baseBehaviour, 'toggling', 'typeaheadevents'],
        [SystemEvents.focus()]: [baseBehaviour, 'focusing', 'keying'],
        [SystemEvents.systemInit()]: [baseBehaviour, 'disabling', 'toggling', 'representing'],
        [NativeEvents.input()]: [baseBehaviour, 'representing', 'streaming', 'invalidating'],
        [SystemEvents.detachedFromDom()]: [baseBehaviour, 'representing', 'item-events', 'tooltipping'],
        [NativeEvents.mousedown()]: ['focusing', baseBehaviour, 'item-type-events'],
        [NativeEvents.touchstart()]: ['focusing', baseBehaviour, 'item-type-events'],
        [NativeEvents.mouseover()]: ['item-type-events', 'tooltipping'],
        [SystemEvents.receive()]: ['receiving', 'reflecting', 'tooltipping']
    }), ValueType.anyValue()),
    FieldSchema.option('domModification')
]);
const toInfo = (spec) => StructureSchema.asRaw('custom.definition', schema, spec);
const toDefinition = (detail) => 
// EFFICIENCY: Consider not merging here.
({
    ...detail.dom,
    uid: detail.uid,
    domChildren: Arr.map(detail.components, (comp) => comp.element)
});
const toModification = (detail) => detail.domModification.fold(() => NuModification({}), NuModification);
const toApis = (info) => info.apis;
const toEvents = (info) => info.events;
export { toInfo, toDefinition, toModification, toApis, toEvents };
//# sourceMappingURL=CustomDefinition.js.map