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 _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;
}
import React from 'react';
import styled, { css } from 'styled-components';
import { toCssSize } from '../../utils';
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 = styled.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) && css([
        "height:0;padding-bottom:",
        "%;"
    ], $ratio ? ratios[$ratio] : $customRatio);
}, function(param) {
    var $width = param.$width, $height = param.$height;
    return css([
        "",
        " ",
        ""
    ], $width && "width: ".concat(toCssSize($width), ";"), $height && "height: ".concat(toCssSize($height), ";"));
});
var StyledImg = styled.img.withConfig({
    displayName: "Image__StyledImg",
    componentId: "sc-c0cf331c-1"
})([
    "width:100%;",
    ";"
], function(param) {
    var src = param.src, ratio = param.ratio;
    return src && ratio && css([
        "height:100%;object-fit:cover;position:absolute;"
    ]);
});
var StyledDivImg = styled.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.createElement(StyledRoot, _object_spread({
        $ratio: ratio,
        $customRatio: customRatio,
        $width: width,
        $height: height
    }, props), base === 'img' && /*#__PURE__*/ React.createElement(StyledImg, {
        src: src,
        srcSet: srcSet,
        sizes: sizes,
        alt: alt,
        ratio: ratio
    }), base === 'div' && /*#__PURE__*/ React.createElement(StyledDivImg, {
        style: {
            backgroundImage: "url(".concat(src, ")")
        },
        role: "img",
        "aria-label": alt
    }));
};
/**
 * Компонент для отображения картинок.
 */ export var Image = styled(ImageBase).withConfig({
    displayName: "Image",
    componentId: "sc-c0cf331c-3"
})([
    ""
]);
