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, { useCallback } from 'react';
import styled from 'styled-components';
import { getSliderThumbValue } from './utils';
var KeyboardSupport = {
    PageUp: 33,
    PageDown: 34,
    End: 35,
    Home: 36,
    ArrowLeft: 37,
    ArrowUp: 38,
    ArrowRight: 39,
    ArrowDown: 40
};
export var ThumbBase = styled.div.withConfig({
    displayName: "ThumbBase",
    componentId: "sc-df386cdf-0"
})([
    "border-radius:50%;background-clip:content-box;box-sizing:content-box;transition:transform 0.1s ease-in-out;&:focus{outline:none;}&:not([disabled]){&.focus-visible,&[data-focus-visible-added]{border-color:currentColor;}}"
]);
export var Thumb = function Thumb(_0) {
    var onChangeCommitted = _0.onChangeCommitted, stepSize = _0.stepSize, _0_xPosition = _0.xPosition, xPosition = _0_xPosition === void 0 ? 0 : _0_xPosition, min = _0.min, max = _0.max, value = _0.value, bounds = _0.bounds, _0_ariaValueMin = _0.ariaValueMin, ariaValueMin = _0_ariaValueMin === void 0 ? min : _0_ariaValueMin, ariaLabel = _0.ariaLabel, multipleStepSize = _0.multipleStepSize, ThumbAbstract = _0.thumb, rest = _object_without_properties(_0, [
        "onChangeCommitted",
        "stepSize",
        "xPosition",
        "min",
        "max",
        "value",
        "bounds",
        "ariaValueMin",
        "ariaLabel",
        "multipleStepSize",
        "thumb"
    ]);
    var onKeyPress = useCallback(function(event) {
        event.persist();
        var keyCode = event.keyCode, target = event.target;
        if (!Object.values(KeyboardSupport).includes(keyCode)) {
            return;
        }
        var ArrowUp = KeyboardSupport.ArrowUp, ArrowRight = KeyboardSupport.ArrowRight, ArrowDown = KeyboardSupport.ArrowDown, ArrowLeft = KeyboardSupport.ArrowLeft, Home = KeyboardSupport.Home, End = KeyboardSupport.End, PageDown = KeyboardSupport.PageDown, PageUp = KeyboardSupport.PageUp;
        var computedMultipleSteps = stepSize * (multipleStepSize / 100 * max);
        var data = {
            x: 0,
            deltaX: stepSize,
            lastX: xPosition,
            y: 0,
            deltaY: 0,
            lastY: 0,
            node: target
        };
        switch(keyCode){
            case ArrowUp:
            case ArrowRight:
                data.x = xPosition + stepSize;
                break;
            case ArrowDown:
            case ArrowLeft:
                data.x = xPosition - stepSize;
                data.deltaX = -stepSize;
                break;
            case PageUp:
                data.x = xPosition + computedMultipleSteps;
                data.deltaX = computedMultipleSteps;
                break;
            case PageDown:
                data.x = xPosition - computedMultipleSteps;
                data.deltaX = -computedMultipleSteps;
                break;
            case End:
                data.x = max * stepSize;
                break;
            case Home:
                data.x = 0;
                break;
            default:
                data.x = 0;
        }
        var left = bounds.left, right = bounds.right;
        /*
             * INFO:Находим значение в диапазоне между указанными левой и правой границами.
             * Необходимо для правильного расчета положения SliderThumb.
             * см. функция clamp
             */ var boundedValue = Math.max(Math.min(right, data.x), left);
        var computedValue = getSliderThumbValue(boundedValue, stepSize, min, max);
        onChangeCommitted(computedValue, data);
    }, [
        onChangeCommitted,
        bounds,
        stepSize,
        multipleStepSize,
        min,
        max,
        xPosition
    ]);
    return /*#__PURE__*/ React.createElement(ThumbAbstract, _object_spread({
        role: "slider",
        "aria-label": ariaLabel,
        "aria-valuemin": ariaValueMin,
        "aria-valuemax": max,
        "aria-valuenow": value,
        "aria-orientation": "horizontal",
        onKeyDown: onKeyPress
    }, rest));
};
