'use strict';

var parseTransform = require('../../../render/dom/parse-transform.js');
var keysTransform = require('../../../render/utils/keys-transform.js');
var index = require('../../../value/types/numbers/index.js');
var units = require('../../../value/types/numbers/units.js');

const isNumOrPxType = (v) => v === index.number || v === units.px;
const transformKeys = new Set(["x", "y", "z"]);
const nonTranslationalTransformKeys = keysTransform.transformPropOrder.filter((key) => !transformKeys.has(key));
function removeNonTranslationalTransform(visualElement) {
    const removedTransforms = [];
    nonTranslationalTransformKeys.forEach((key) => {
        const value = visualElement.getValue(key);
        if (value !== undefined) {
            removedTransforms.push([key, value.get()]);
            value.set(key.startsWith("scale") ? 1 : 0);
        }
    });
    return removedTransforms;
}
const positionalValues = {
    // Dimensions
    width: ({ x }, { paddingLeft = "0", paddingRight = "0", boxSizing }) => {
        const width = x.max - x.min;
        return boxSizing === "border-box"
            ? width
            : width - parseFloat(paddingLeft) - parseFloat(paddingRight);
    },
    height: ({ y }, { paddingTop = "0", paddingBottom = "0", boxSizing }) => {
        const height = y.max - y.min;
        return boxSizing === "border-box"
            ? height
            : height - parseFloat(paddingTop) - parseFloat(paddingBottom);
    },
    top: (_bbox, { top }) => parseFloat(top),
    left: (_bbox, { left }) => parseFloat(left),
    bottom: ({ y }, { top }) => parseFloat(top) + (y.max - y.min),
    right: ({ x }, { left }) => parseFloat(left) + (x.max - x.min),
    // Transform
    x: (_bbox, { transform }) => parseTransform.parseValueFromTransform(transform, "x"),
    y: (_bbox, { transform }) => parseTransform.parseValueFromTransform(transform, "y"),
};
// Alias translate longform names
positionalValues.translateX = positionalValues.x;
positionalValues.translateY = positionalValues.y;

exports.isNumOrPxType = isNumOrPxType;
exports.positionalValues = positionalValues;
exports.removeNonTranslationalTransform = removeNonTranslationalTransform;
