import { clone, mapObject } from '../../utils/utils.js';
function buildControllerFromDefinition({ definition, engine, props, }) {
    return ('build' in definition
        ? definition.build(engine)
        : definition.buildWithProps(engine, props));
}
export function buildControllerDefinitions({ definitionsMap, engine, propsMap, }) {
    return mapObject(definitionsMap, (definition, key) => buildControllerFromDefinition({
        definition,
        engine,
        props: propsMap?.[key],
    }));
}
export function createStaticState({ searchAction, controllers, }) {
    return {
        controllers: mapObject(controllers, (controller) => ({
            state: clone(controller.state),
        })),
        searchAction: clone(searchAction),
    };
}
// TODO: KIT-4610: no longer needed along with build()
export function composeFunction(parentFunction, children) {
    const newFunction = ((...params) => parentFunction(...params));
    for (const [key, value] of Object.entries(children)) {
        newFunction[key] = value;
    }
    return newFunction;
}
