import { FieldSchema, StructureSchema } from '@ephox/boulder';
import { Arr, Fun, Obj } from '@ephox/katamari';
import { NoState } from './BehaviourState';
const generateFrom = (spec, all) => {
    /*
     * This takes a basic record of configured behaviours, defaults their state
     * and ensures that all the behaviours were valid. Will need to document
     * this entire process. Let's see where this is used.
     */
    const schema = Arr.map(all, (a) => 
    // Optional here probably just due to ForeignGui listing everything it supports. Can most likely
    // change it to strict once I fix the other errors.
    FieldSchema.optionObjOf(a.name(), [
        FieldSchema.required('config'),
        FieldSchema.defaulted('state', NoState)
    ]));
    const validated = StructureSchema.asRaw('component.behaviours', StructureSchema.objOf(schema), spec.behaviours).fold((errInfo) => {
        throw new Error(StructureSchema.formatError(errInfo) + '\nComplete spec:\n' +
            JSON.stringify(spec, null, 2));
    }, Fun.identity);
    return {
        list: all,
        data: Obj.map(validated, (optBlobThunk) => {
            const output = optBlobThunk.map((blob) => ({
                config: blob.config,
                state: blob.state.init(blob.config)
            }));
            return Fun.constant(output);
        })
    };
};
const getBehaviours = (bData) => bData.list;
const getData = (bData) => bData.data;
export { generateFrom, getBehaviours, getData };
//# sourceMappingURL=BehaviourBlob.js.map