import { Arr } from '@ephox/katamari';
import * as ObjIndex from '../alien/ObjIndex';
import { nu as NuModification } from '../dom/DomModification';
// Based on all the behaviour exhibits, and the original dom modification, identify
// the overall combined dom modification that needs to occur
const combine = (info, baseMod, behaviours, base) => {
    // Clone the object so we can change it.
    const modsByBehaviour = { ...baseMod };
    Arr.each(behaviours, (behaviour) => {
        modsByBehaviour[behaviour.name()] = behaviour.exhibit(info, base);
    });
    // byAspect format: { classes: [ { name: Toggling, modification: [ 'selected' ] } ] }
    const byAspect = ObjIndex.byInnerKey(modsByBehaviour, (name, modification) => ({ name, modification }));
    const combineObjects = (objects) => Arr.foldr(objects, (b, a) => ({ ...a.modification, ...b }), {});
    const combinedClasses = Arr.foldr(byAspect.classes, (b, a) => a.modification.concat(b), []);
    const combinedAttributes = combineObjects(byAspect.attributes);
    const combinedStyles = combineObjects(byAspect.styles);
    return NuModification({
        classes: combinedClasses,
        attributes: combinedAttributes,
        styles: combinedStyles
    });
};
export { combine };
//# sourceMappingURL=ComponentDom.js.map