'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

function addPXSuffix(value, isNegative) {
    return +value ? '' + (isNegative ? '-' : '') + value + 'px' : 0;
}

var buildShadowBorder = exports.buildShadowBorder = function buildShadowBorder(borderWidth, borderColor, out) {
    var inset = out ? '' : 'inset ';
    var split = String(borderWidth).replace(/px/g, '').split(' ').map(function (item) {
        return +item;
    });
    var length = split.length;

    var _split = _slicedToArray(split, 4),
        topWidth = _split[0],
        rightWidth = _split[1],
        bottomWidth = _split[2],
        leftWidth = _split[3];

    if (length === 1) {
        rightWidth = topWidth;
        bottomWidth = topWidth;
        leftWidth = topWidth;
    } else if (length === 2) {
        bottomWidth = topWidth;
        leftWidth = rightWidth;
    } else if (length === 3) {
        leftWidth = rightWidth;
    }

    if (topWidth === rightWidth && topWidth === bottomWidth && topWidth === leftWidth) {
        return topWidth ? inset + '0 0 0 ' + addPXSuffix(topWidth) + ' ' + borderColor : 'none';
    }

    var topAndLeft = '';
    var bottomAndRight = '';

    if (topWidth && leftWidth) {
        topAndLeft = '' + inset + addPXSuffix(leftWidth) + ' ' + addPXSuffix(topWidth) + ' 0 0 ' + borderColor;
    } else if (topWidth) {
        topAndLeft = inset + '0 ' + addPXSuffix(topWidth) + ' 0 0 ' + borderColor;
    } else if (leftWidth) {
        topAndLeft = '' + inset + addPXSuffix(leftWidth) + ' 0 0 0 ' + borderColor;
    }

    if (bottomWidth && rightWidth) {
        bottomAndRight = '' + inset + addPXSuffix(rightWidth, true) + ' ' + addPXSuffix(bottomWidth, true) + ' 0 0 ' + borderColor;
    } else if (bottomWidth) {
        bottomAndRight = inset + '0 ' + addPXSuffix(bottomWidth, true) + ' 0 0 ' + borderColor;
    } else if (rightWidth) {
        bottomAndRight = '' + inset + addPXSuffix(rightWidth, true) + ' 0 0 0 ' + borderColor;
    }

    var result = [];

    topAndLeft && result.push(topAndLeft);
    bottomAndRight && result.push(bottomAndRight);

    return result.join(',');
};