"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get textFieldSliderConfig () {
        return textFieldSliderConfig;
    },
    get textFieldSliderRoot () {
        return textFieldSliderRoot;
    }
});
var _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
var _NumberFormat = require("../NumberFormat");
var _ui = require("./ui");
var _base = require("./variations/_size/base");
var _base1 = require("./variations/_view/base");
var _base2 = require("./variations/_slider-view/base");
var _base3 = require("./variations/_hint-view/base");
var _base4 = require("./variations/_hint-size/base");
var _base5 = require("./variations/_disabled/base");
var _base6 = require("./variations/_readonly/base");
var _TextFieldSliderstyles = require("./TextFieldSlider.styles");
function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
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 _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 _iterable_to_array(iter) {
    if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_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"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
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 ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(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;
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _to_array(arr) {
    return _array_with_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
var HINT_DEFAULT_OFFSET = [
    0,
    0
];
var textFieldSliderRoot = function textFieldSliderRoot(Root) {
    return /*#__PURE__*/ (0, _react.forwardRef)(function(_0, _1) {
        var _ref = [
            _0,
            _1
        ], _ref1 = _to_array(_ref), _ref2 = _ref1[0], _rest = _ref1.slice(1), id = _ref2.id, className = _ref2.className, style = _ref2.style, _ref_hasPointer = _ref2.// layout
        hasPointer, hasPointer = _ref_hasPointer === void 0 ? true : _ref_hasPointer, hasScale = _ref2.hasScale, titleCaption = _ref2.titleCaption, contentLeft = _ref2.contentLeft, contentRight = _ref2.contentRight, textBefore = _ref2.textBefore, textAfter = _ref2.textAfter, // required
        required = _ref2.required, _ref_requiredPlacement = _ref2.requiredPlacement, requiredPlacement = _ref_requiredPlacement === void 0 ? 'right' : _ref_requiredPlacement, optional = _ref2.optional, optionalText = _ref2.optionalText, _ref_hasRequiredIndicator = _ref2.hasRequiredIndicator, hasRequiredIndicator = _ref_hasRequiredIndicator === void 0 ? false : _ref_hasRequiredIndicator, _ref_hintTrigger = _ref2.// hint
        hintTrigger, hintTrigger = _ref_hintTrigger === void 0 ? 'hover' : _ref_hintTrigger, hintText = _ref2.hintText, _ref_hintView = _ref2.hintView, hintView = _ref_hintView === void 0 ? 'default' : _ref_hintView, _ref_hintSize = _ref2.hintSize, hintSize = _ref_hintSize === void 0 ? 'm' : _ref_hintSize, hintTargetIcon = _ref2.hintTargetIcon, _ref_hintTargetPlacement = _ref2.hintTargetPlacement, hintTargetPlacement = _ref_hintTargetPlacement === void 0 ? 'outer' : _ref_hintTargetPlacement, _ref_hintPlacement = _ref2.hintPlacement, hintPlacement = _ref_hintPlacement === void 0 ? 'auto' : _ref_hintPlacement, hintHasArrow = _ref2.hintHasArrow, _ref_hintOffset = _ref2.hintOffset, hintOffset = _ref_hintOffset === void 0 ? HINT_DEFAULT_OFFSET : _ref_hintOffset, hintWidth = _ref2.hintWidth, hintContentLeft = _ref2.hintContentLeft, // variations
        view = _ref2.view, _ref_sliderView = _ref2.sliderView, sliderView = _ref_sliderView === void 0 ? 'default' : _ref_sliderView, size = _ref2.size, _ref_readOnly = _ref2.readOnly, readOnly = _ref_readOnly === void 0 ? false : _ref_readOnly, _ref_disabled = _ref2.disabled, disabled = _ref_disabled === void 0 ? false : _ref_disabled, // controlled
        outerValue = _ref2.value, defaultValue = _ref2.defaultValue, min = _ref2.min, max = _ref2.max, step = _ref2.step, _ref_decimalScale = _ref2.decimalScale, decimalScale = _ref_decimalScale === void 0 ? 2 : _ref_decimalScale, _ref_thousandsGroupStyle = _ref2.thousandsGroupStyle, thousandsGroupStyle = _ref_thousandsGroupStyle === void 0 ? 'none' : _ref_thousandsGroupStyle, _ref_thousandSeparator = _ref2.thousandSeparator, thousandSeparator = _ref_thousandSeparator === void 0 ? '' : _ref_thousandSeparator, _ref_decimalSeparator = _ref2.decimalSeparator, decimalSeparator = _ref_decimalSeparator === void 0 ? '.' : _ref_decimalSeparator, _ref_fixedDecimalScale = _ref2.fixedDecimalScale, fixedDecimalScale = _ref_fixedDecimalScale === void 0 ? false : _ref_fixedDecimalScale, // events
        onChange = _ref2.onChange, onChangeSlider = _ref2.onChangeSlider, onChangeTextField = _ref2.onChangeTextField, rest = _object_without_properties(_ref2, [
            "id",
            "className",
            "style",
            "hasPointer",
            "hasScale",
            "titleCaption",
            "contentLeft",
            "contentRight",
            "textBefore",
            "textAfter",
            "required",
            "requiredPlacement",
            "optional",
            "optionalText",
            "hasRequiredIndicator",
            "hintTrigger",
            "hintText",
            "hintView",
            "hintSize",
            "hintTargetIcon",
            "hintTargetPlacement",
            "hintPlacement",
            "hintHasArrow",
            "hintOffset",
            "hintWidth",
            "hintContentLeft",
            "view",
            "sliderView",
            "size",
            "readOnly",
            "disabled",
            "value",
            "defaultValue",
            "min",
            "max",
            "step",
            "decimalScale",
            "thousandsGroupStyle",
            "thousandSeparator",
            "decimalSeparator",
            "fixedDecimalScale",
            "onChange",
            "onChangeSlider",
            "onChangeTextField"
        ]), _rest1 = _sliced_to_array(_rest, 1), ref = _rest1[0];
        var _useState = _sliced_to_array((0, _react.useState)(defaultValue !== undefined ? defaultValue : ''), 2), innerValue = _useState[0], setInnerValue = _useState[1];
        var value = outerValue !== undefined ? outerValue : innerValue;
        var formattedMin = (0, _react.useMemo)(function() {
            return (0, _NumberFormat.numberFormatter)(String(min) || '', {
                decimalScale: decimalScale,
                thousandsGroupStyle: thousandsGroupStyle,
                thousandSeparator: thousandSeparator,
                decimalSeparator: decimalSeparator,
                fixedDecimalScale: fixedDecimalScale
            });
        }, [
            min,
            decimalScale,
            thousandsGroupStyle,
            thousandSeparator,
            decimalSeparator,
            fixedDecimalScale
        ]);
        var formattedMax = (0, _react.useMemo)(function() {
            return (0, _NumberFormat.numberFormatter)(String(max) || '', {
                decimalScale: decimalScale,
                thousandsGroupStyle: thousandsGroupStyle,
                thousandSeparator: thousandSeparator,
                decimalSeparator: decimalSeparator,
                fixedDecimalScale: fixedDecimalScale
            });
        }, [
            max,
            decimalScale,
            thousandsGroupStyle,
            thousandSeparator,
            decimalSeparator,
            fixedDecimalScale
        ]);
        return /*#__PURE__*/ _react.default.createElement(Root, _object_spread({
            view: view,
            size: size,
            disabled: disabled,
            readOnly: !disabled && readOnly,
            "data-root": true,
            className: className,
            style: style,
            sliderView: sliderView
        }, hintText && {
            hintView: hintView,
            hintSize: hintSize
        }), /*#__PURE__*/ _react.default.createElement(_TextFieldSliderstyles.SliderWithHelpersWrapper, null, /*#__PURE__*/ _react.default.createElement(_ui.Input, _object_spread(_object_spread_props(_object_spread({
            ref: ref,
            id: id,
            value: value,
            min: min,
            max: max,
            decimalScale: decimalScale,
            thousandsGroupStyle: thousandsGroupStyle,
            thousandSeparator: thousandSeparator,
            decimalSeparator: decimalSeparator,
            fixedDecimalScale: fixedDecimalScale,
            disabled: disabled,
            readOnly: readOnly,
            titleCaption: titleCaption,
            contentLeft: contentLeft,
            contentRight: contentRight,
            textBefore: textBefore,
            textAfter: textAfter,
            required: required,
            requiredPlacement: requiredPlacement,
            optional: optional,
            optionalText: optionalText,
            hasRequiredIndicator: hasRequiredIndicator
        }, hintText ? {
            hintText: hintText,
            hintView: hintView,
            hintSize: hintSize,
            hintTrigger: hintTrigger,
            hintTargetIcon: hintTargetIcon,
            hintPlacement: hintPlacement,
            hintHasArrow: hintHasArrow,
            hintOffset: hintOffset,
            hintWidth: hintWidth,
            hintContentLeft: hintContentLeft,
            hintTargetPlacement: hintTargetPlacement
        } : {
            hintText: undefined
        }), {
            setInnerValue: setInnerValue,
            onChange: onChange,
            onChangeTextField: onChangeTextField
        }), rest)), /*#__PURE__*/ _react.default.createElement(_TextFieldSliderstyles.SliderContainer, null, /*#__PURE__*/ _react.default.createElement(_ui.SliderUI, {
            value: value,
            min: min,
            max: max,
            step: step,
            decimalScale: decimalScale,
            thousandsGroupStyle: thousandsGroupStyle,
            thousandSeparator: thousandSeparator,
            decimalSeparator: decimalSeparator,
            fixedDecimalScale: fixedDecimalScale,
            disabled: disabled,
            readOnly: readOnly,
            hasPointer: hasPointer,
            onChange: onChange,
            onChangeSlider: onChangeSlider,
            setInnerValue: setInnerValue
        }))), hasScale && /*#__PURE__*/ _react.default.createElement(_TextFieldSliderstyles.ScaleWrapper, null, /*#__PURE__*/ _react.default.createElement(_TextFieldSliderstyles.ScaleValue, null, formattedMin), /*#__PURE__*/ _react.default.createElement(_TextFieldSliderstyles.ScaleValue, null, formattedMax)));
    });
};
var textFieldSliderConfig = {
    name: 'TextFieldSlider',
    tag: 'div',
    layout: textFieldSliderRoot,
    base: _TextFieldSliderstyles.base,
    variations: {
        view: {
            css: _base1.base
        },
        size: {
            css: _base.base
        },
        disabled: {
            css: _base5.base,
            attrs: true
        },
        readOnly: {
            css: _base6.base,
            attrs: true
        },
        sliderView: {
            css: _base2.base
        },
        hintView: {
            css: _base3.base
        },
        hintSize: {
            css: _base4.base
        }
    },
    defaults: {
        size: 'm',
        view: 'default',
        sliderView: 'default'
    }
};
