"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateFromTo = exports.getPosition = void 0;
const defaults_1 = require("../../../defaults");
function getPosition(val, scale, width, height) {
    if (val > 0 && scale === defaults_1.DEFAULT_X_SCALE) {
        return width;
    }
    if (val > 0 && scale !== defaults_1.DEFAULT_X_SCALE) {
        return 0;
    }
    if (val <= 0 && scale === defaults_1.DEFAULT_X_SCALE) {
        return 0;
    }
    return height;
}
exports.getPosition = getPosition;
function calculateFromTo(value, scale, timeline, u) {
    return value
        .map((val) => {
        var _a, _b;
        if (Math.abs(val) !== Infinity) {
            if (scale === defaults_1.DEFAULT_X_SCALE) {
                return Math.min(Math.max(val, timeline[0]), timeline[timeline.length - 1]);
            }
            else {
                const scaleCfg = u.scales[scale];
                return Math.min(Math.max(val, (_a = scaleCfg.min) !== null && _a !== void 0 ? _a : val), (_b = scaleCfg.max) !== null && _b !== void 0 ? _b : val);
            }
        }
        const pos = getPosition(val, scale, u.width, u.height);
        return u.posToVal(pos, scale);
    })
        .map((val) => u.valToPos(val, scale, true));
}
exports.calculateFromTo = calculateFromTo;
