import { FieldPresence, FieldSchema, StructureSchema } from '@ephox/boulder';
import { Arr, Fun, Optional, Result } from '@ephox/katamari';
import * as Debugging from '../debugging/Debugging';
import * as MenuMarkers from '../menu/util/MenuMarkers';
const _initSize = FieldSchema.requiredObjOf('initSize', [
    FieldSchema.required('numColumns'),
    FieldSchema.required('numRows')
]);
const itemMarkers = () => FieldSchema.requiredOf('markers', MenuMarkers.itemSchema());
const menuMarkers = () => FieldSchema.requiredOf('markers', MenuMarkers.schema());
const tieredMenuMarkers = () => FieldSchema.requiredObjOf('markers', [
    FieldSchema.required('backgroundMenu')
].concat(MenuMarkers.menuFields()).concat(MenuMarkers.itemFields()));
const markers = (required) => FieldSchema.requiredObjOf('markers', Arr.map(required, FieldSchema.required));
const onPresenceHandler = (label, fieldName, presence) => {
    // We care about where the handler was declared (in terms of which schema)
    const trace = Debugging.getTrace();
    return FieldSchema.field(fieldName, fieldName, presence, 
    // Apply some wrapping to their supplied function
    StructureSchema.valueOf((f) => Result.value((...args) => {
        /*
           * This line is just for debugging information
           */
        Debugging.logHandler(label, fieldName, trace);
        return f.apply(undefined, args);
    })));
};
const onHandler = (fieldName) => onPresenceHandler('onHandler', fieldName, FieldPresence.defaulted(Fun.noop));
const onKeyboardHandler = (fieldName) => onPresenceHandler('onKeyboardHandler', fieldName, FieldPresence.defaulted(Optional.none));
const onStrictHandler = (fieldName) => onPresenceHandler('onHandler', fieldName, FieldPresence.required());
const onStrictKeyboardHandler = (fieldName) => onPresenceHandler('onKeyboardHandler', fieldName, FieldPresence.required());
const output = (name, value) => FieldSchema.customField(name, Fun.constant(value));
const snapshot = (name) => FieldSchema.customField(name, Fun.identity);
const initSize = Fun.constant(_initSize);
export { initSize, itemMarkers, menuMarkers, tieredMenuMarkers, markers, onHandler, onKeyboardHandler, onStrictHandler, onStrictKeyboardHandler, output, snapshot };
//# sourceMappingURL=Fields.js.map