"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BackgroundPositionParser = void 0;
const dimension_style_parser_1 = require("../dimension-style.parser");
class BackgroundPositionParser extends dimension_style_parser_1.DimensionStyleParser {
    constructor() {
        super('position');
    }
    parse(value) {
        return this.parseWithDimensions(value);
    }
    parseWithDimensions(value, width = 0, height = 0) {
        let [left, top] = value.split(' ');
        const result = {
            imageStyle: {}
        };
        if (left !== undefined) {
            if (left === 'right') {
                result.imageStyle.left = '100%';
                result.imageStyle.marginLeft = -1 * width;
            }
            else if (left === 'left') {
                result.imageStyle.left = 0;
            }
            else if (left === 'center') {
                result.imageStyle.left = '50%';
                result.imageStyle.marginLeft = -1 * width / 2;
            }
            else {
                result.imageStyle.left = super.parse(left).position;
            }
        }
        if (top !== undefined) {
            if (top === 'bottom') {
                result.imageStyle.top = '100%';
                result.imageStyle.marginTop = -1 * height;
            }
            else if (top === 'top') {
                result.imageStyle.top = 0;
            }
            else if (top === 'center') {
                result.imageStyle.top = '50%';
                result.imageStyle.marginTop = -1 * height / 2;
            }
            else {
                result.imageStyle.top = super.parse(top).position;
            }
        }
        if (left || top) {
            result.imageStyle['position'] = 'absolute';
        }
        result.resizeMode = 'stretch';
        return result;
    }
}
exports.BackgroundPositionParser = BackgroundPositionParser;
//# sourceMappingURL=background-position.parser.js.map