"use strict";
/**
 * Copyright (c) Haiku 2016-2018. All rights reserved.
 */
var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var interactionModes_1 = require("./helpers/interactionModes");
exports.DEFAULTS = {
    seed: null,
    timestamp: null,
    automount: true,
    autoplay: true,
    forceFlush: false,
    freeze: false,
    loop: false,
    frame: null,
    clock: {},
    sizing: null,
    alwaysComputeSizing: false,
    preserve3d: 'auto',
    contextMenu: 'enabled',
    position: 'relative',
    overflowX: null,
    overflowY: null,
    overflow: null,
    mixpanel: '6f31d4f99cf71024ce27c3e404a79a61',
    useWebkitPrefix: void (0),
    interactionMode: interactionModes_1.InteractionMode.LIVE,
    states: null,
    eventHandlers: null,
    timelines: null,
    vanities: null,
    children: null,
    placeholder: null,
};
/**
 * Configuration from HaikuContext is forwarded to all HaikuComponent instances in its tree.
 * For child instances, certain settings (such as `loop`) give unexpected behavior and
 * other settings (such as `states`) don't make much sense to pass down. This specifies the
 * settings that are considered safe to forward from the context to all subcomponents.
 */
var CHILD_SAFE_CONFIG = {
    seed: true,
    timestamp: true,
    freeze: true,
    clock: true,
    sizing: true,
    alwaysComputeSizing: true,
    preserve3d: true,
    contextMenu: true,
    mixpanel: true,
    useWebkitPrefix: true,
    interactionMode: true,
    overflowX: true,
    overflowY: true,
    overflow: true,
};
var buildChildSafeConfig = function (config) {
    var out = {};
    for (var key in config) {
        if (CHILD_SAFE_CONFIG[key]) {
            out[key] = config[key];
        }
    }
    return out;
};
function seed() {
    return Math.random().toString(36).slice(2);
}
var CONFIG_KEYS_TO_MERGE = {
    states: true,
    eventHandlers: true,
    timelines: true,
    vanities: true,
    initialStates: true,
};
function build() {
    var argums = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        argums[_i] = arguments[_i];
    }
    var config = {};
    var args = argums.slice();
    args.unshift(exports.DEFAULTS);
    args.forEach(function (incoming) {
        if (!incoming || typeof incoming !== 'object') {
            return;
        }
        for (var key in incoming) {
            if (incoming[key] === undefined) {
                continue;
            }
            if (CONFIG_KEYS_TO_MERGE[key]) {
                if (!config[key]) {
                    config[key] = {};
                }
                config[key] = __assign({}, config[key], incoming[key]);
            }
            else {
                config[key] = incoming[key];
            }
        }
    });
    // Validations
    if (config.overflow && (config.overflowX || config.overflowY)) {
        console.warn('[haiku core] `overflow` overrides `overflowY`/`overflowX`');
        config.overflowX = null;
        config.overflowY = null;
    }
    return config;
}
exports.default = {
    build: build,
    seed: seed,
    DEFAULTS: exports.DEFAULTS,
    buildChildSafeConfig: buildChildSafeConfig,
};
//# sourceMappingURL=Config.js.map