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, { keyframes, css } from 'styled-components';
import { accent } from '../../tokens';
import { useUniqId } from '../../hooks';
import { SpinnerSvg } from './SpinnerSvg';
var rotateAnimation = keyframes([
    "from{transform:rotate(0);}to{transform:rotate(360deg);}"
]);
var StyledRoot = styled.div.withConfig({
    displayName: "Spinner__StyledRoot",
    componentId: "sc-c7478b4f-0"
})([
    "display:flex;box-sizing:border-box;",
    " animation:",
    " 1s linear infinite;"
], function(param) {
    var $size = param.$size;
    return css([
        "width:",
        ";height:",
        ";"
    ], $size, $size);
}, rotateAnimation);
var scalingPixelBasis = 16;
var sizeFormatting = function sizeFormatting(size) {
    var deviceScale = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
    if (typeof size === 'number' || !size.endsWith('rem') && !size.endsWith('px')) {
        return "".concat(Number(size) / (scalingPixelBasis * deviceScale), "rem");
    }
    return size;
};
/**
 * Компонент для отображения индикатора загрузки.
 */ export var Spinner = function Spinner(props) {
    var id = props.id, _props_size = props.size, size = _props_size === void 0 ? 56 : _props_size, _props_color = props.color, color = _props_color === void 0 ? accent : _props_color, deviceScale = props.deviceScale, rest = _object_without_properties(props, [
        "id",
        "size",
        "color",
        "deviceScale"
    ]);
    var uniqId = useUniqId();
    var innerId = id || uniqId;
    var currentSize = sizeFormatting(size, deviceScale);
    return /*#__PURE__*/ React.createElement(StyledRoot, _object_spread({
        id: innerId,
        $size: currentSize
    }, rest), /*#__PURE__*/ React.createElement(SpinnerSvg, {
        id: innerId,
        width: size,
        height: size,
        color: color
    }));
};
