import { Fun } from '@ephox/katamari';
import * as Callouts from '../view/Callouts';
import * as MaxHeight from './MaxHeight';
import * as Origins from './Origins';
const defaultOr = (options, key, dephault) => options[key] === undefined ? dephault : options[key];
// This takes care of everything when you are positioning UI that can go anywhere on the screen
const simple = (anchor, element, bubble, layouts, lastPlacement, getBounds, overrideOptions, transition) => {
    // the only supported override at the moment. Once relative has been deleted, maybe this can be optional in the bag
    const maxHeightFunction = defaultOr(overrideOptions, 'maxHeightFunction', MaxHeight.anchored());
    const maxWidthFunction = defaultOr(overrideOptions, 'maxWidthFunction', Fun.noop);
    const anchorBox = anchor.anchorBox;
    const origin = anchor.origin;
    const options = {
        bounds: Origins.viewport(origin, getBounds),
        origin,
        preference: layouts,
        maxHeightFunction,
        maxWidthFunction,
        lastPlacement,
        transition
    };
    return go(anchorBox, element, bubble, options);
};
// This is the old public API. If we ever need full customisability again, this is how to expose it
const go = (anchorBox, element, bubble, options) => {
    const decision = Callouts.layout(anchorBox, element, bubble, options);
    Callouts.position(element, decision, options);
    Callouts.setPlacement(element, decision);
    Callouts.setClasses(element, decision);
    Callouts.setHeight(element, decision, options);
    Callouts.setWidth(element, decision, options);
    return {
        layout: decision.layout,
        placement: decision.placement
    };
};
export { simple };
//# sourceMappingURL=SimpleLayout.js.map