"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Image", {
    enumerable: true,
    get: function() {
        return Image;
    }
});
var _react = /*#__PURE__*/ _interop_require_default(require("react"));
var _styledcomponents = /*#__PURE__*/ _interop_require_wildcard(require("styled-components"));
var _utils = require("../../utils");
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
var ratios = {
    '1 / 1': '100',
    '1/1': '100',
    '3 / 4': '133.3333',
    '3/4': '133.3333',
    '4 / 3': '75',
    '4/3': '75',
    '9 / 16': '177.7778',
    '9/16': '177.7778',
    '16 / 9': '56.25',
    '16/9': '56.25',
    '1 / 2': '200',
    '1/2': '200',
    '2 / 1': '50',
    '2/1': '50'
};
var StyledRoot = _styledcomponents.default.div.withConfig({
    displayName: "Image__StyledRoot",
    componentId: "sc-c0cf331c-0"
})([
    "position:relative;display:block;box-sizing:border-box;overflow:hidden;width:100%;height:inherit;border-radius:inherit;",
    " ",
    ""
], function(param) {
    var $ratio = param.$ratio, $customRatio = param.$customRatio;
    return ($ratio || $customRatio) && (0, _styledcomponents.css)([
        "height:0;padding-bottom:",
        "%;"
    ], $ratio ? ratios[$ratio] : $customRatio);
}, function(param) {
    var $width = param.$width, $height = param.$height;
    return (0, _styledcomponents.css)([
        "",
        " ",
        ""
    ], $width && "width: ".concat((0, _utils.toCssSize)($width), ";"), $height && "height: ".concat((0, _utils.toCssSize)($height), ";"));
});
var StyledImg = _styledcomponents.default.img.withConfig({
    displayName: "Image__StyledImg",
    componentId: "sc-c0cf331c-1"
})([
    "width:100%;",
    ";"
], function(param) {
    var src = param.src, ratio = param.ratio;
    return src && ratio && (0, _styledcomponents.css)([
        "height:100%;object-fit:cover;position:absolute;"
    ]);
});
var StyledDivImg = _styledcomponents.default.div.withConfig({
    displayName: "Image__StyledDivImg",
    componentId: "sc-c0cf331c-2"
})([
    "width:100%;height:100%;position:absolute;background-position:center;background-size:cover;"
]);
/**
 * Компонент для отображения картинок.
 */ var ImageBase = function ImageBase(_0) {
    var src = _0.src, srcSet = _0.srcSet, sizes = _0.sizes, _0_base = _0.base, base = _0_base === void 0 ? 'img' : _0_base, alt = _0.alt, width = _0.width, height = _0.height, props = _object_without_properties(_0, [
        "src",
        "srcSet",
        "sizes",
        "base",
        "alt",
        "width",
        "height"
    ]);
    var ratio = 'ratio' in props ? props.ratio : undefined;
    var customRatio = 'customRatio' in props ? props.customRatio : undefined;
    return /*#__PURE__*/ _react.default.createElement(StyledRoot, _object_spread({
        $ratio: ratio,
        $customRatio: customRatio,
        $width: width,
        $height: height
    }, props), base === 'img' && /*#__PURE__*/ _react.default.createElement(StyledImg, {
        src: src,
        srcSet: srcSet,
        sizes: sizes,
        alt: alt,
        ratio: ratio
    }), base === 'div' && /*#__PURE__*/ _react.default.createElement(StyledDivImg, {
        style: {
            backgroundImage: "url(".concat(src, ")")
        },
        role: "img",
        "aria-label": alt
    }));
};
var Image = (0, _styledcomponents.default)(ImageBase).withConfig({
    displayName: "Image",
    componentId: "sc-c0cf331c-3"
})([
    ""
]);
