/**
 * DevExtreme (renovation/number-box.p.js)
 * Version: 20.2.0 (build 20182-0310)
 * Build date: Tue Jun 30 2020
 *
 * Copyright (c) 2012 - 2020 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";

function _typeof(obj) {
    "@babel/helpers - typeof";
    if ("function" === typeof Symbol && "symbol" === typeof Symbol.iterator) {
        _typeof = function(obj) {
            return typeof obj
        }
    } else {
        _typeof = function(obj) {
            return obj && "function" === typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
        }
    }
    return _typeof(obj)
}
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.NumberBoxProps = exports.viewFunction = void 0;
var _number_box = require("../ui/number_box");
var _number_box2 = _interopRequireDefault(_number_box);
var _widget = require("./widget.p");
var _preact = require("preact");
var Preact = _interopRequireWildcard(_preact);
var _hooks = require("preact/hooks");
var _compat = require("preact/compat");

function _getRequireWildcardCache() {
    if ("function" !== typeof WeakMap) {
        return null
    }
    var cache = new WeakMap;
    _getRequireWildcardCache = function() {
        return cache
    };
    return cache
}

function _interopRequireWildcard(obj) {
    if (obj && obj.__esModule) {
        return obj
    }
    if (null === obj || "object" !== _typeof(obj) && "function" !== typeof obj) {
        return {
            "default": obj
        }
    }
    var cache = _getRequireWildcardCache();
    if (cache && cache.has(obj)) {
        return cache.get(obj)
    }
    var newObj = {};
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for (var key in obj) {
        if (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 _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        "default": obj
    }
}

function _objectWithoutProperties(source, excluded) {
    if (null == source) {
        return {}
    }
    var target = _objectWithoutPropertiesLoose(source, excluded);
    var key, i;
    if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
        for (i = 0; i < sourceSymbolKeys.length; i++) {
            key = sourceSymbolKeys[i];
            if (excluded.indexOf(key) >= 0) {
                continue
            }
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) {
                continue
            }
            target[key] = source[key]
        }
    }
    return target
}

function _objectWithoutPropertiesLoose(source, excluded) {
    if (null == source) {
        return {}
    }
    var target = {};
    var sourceKeys = Object.keys(source);
    var key, i;
    for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) {
            continue
        }
        target[key] = source[key]
    }
    return target
}

function _slicedToArray(arr, i) {
    return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest()
}

function _nonIterableRest() {
    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 _unsupportedIterableToArray(o, minLen) {
    if (!o) {
        return
    }
    if ("string" === typeof o) {
        return _arrayLikeToArray(o, minLen)
    }
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if ("Object" === n && o.constructor) {
        n = o.constructor.name
    }
    if ("Map" === n || "Set" === n) {
        return Array.from(o)
    }
    if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) {
        return _arrayLikeToArray(o, minLen)
    }
}

function _arrayLikeToArray(arr, len) {
    if (null == len || len > arr.length) {
        len = arr.length
    }
    for (var i = 0, arr2 = new Array(len); i < len; i++) {
        arr2[i] = arr[i]
    }
    return arr2
}

function _iterableToArrayLimit(arr, i) {
    if ("undefined" === typeof Symbol || !(Symbol.iterator in Object(arr))) {
        return
    }
    var _arr = [];
    var _n = true;
    var _d = false;
    var _e = void 0;
    try {
        for (var _s, _i = arr[Symbol.iterator](); !(_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 && null != _i.return) {
                _i.return()
            }
        } finally {
            if (_d) {
                throw _e
            }
        }
    }
    return _arr
}

function _arrayWithHoles(arr) {
    if (Array.isArray(arr)) {
        return arr
    }
}

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 _objectSpread(target) {
    for (var i = 1; i < arguments.length; i++) {
        var source = null != arguments[i] ? arguments[i] : {};
        if (i % 2) {
            ownKeys(Object(source), true).forEach(function(key) {
                _defineProperty(target, key, source[key])
            })
        } else {
            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 _defineProperty(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 _extends() {
    _extends = Object.assign || function(target) {
        for (var i = 1; i < arguments.length; i++) {
            var source = arguments[i];
            for (var key in source) {
                if (Object.prototype.hasOwnProperty.call(source, key)) {
                    target[key] = source[key]
                }
            }
        }
        return target
    };
    return _extends.apply(this, arguments)
}
var viewFunction = exports.viewFunction = function(_ref) {
    var restAttributes = _ref.restAttributes,
        widgetRef = _ref.widgetRef;
    return Preact.h("div", _extends({
        ref: widgetRef
    }, restAttributes))
};
var NumberBoxProps = exports.NumberBoxProps = _objectSpread(_objectSpread({}, _widget.WidgetProps), {}, {
    valueChange: function() {}
});
var NumberBox = (0, _compat.forwardRef)(function(props, ref) {
    var widgetRef = (0, _hooks.useRef)();
    var _useState = (0, _hooks.useState)(function() {
            return void 0 !== props.value ? props.value : props.defaultValue
        }),
        _useState2 = _slicedToArray(_useState, 2),
        __state_value = _useState2[0];
    _useState2[1];
    (0, _hooks.useImperativeHandle)(ref, function() {
        return {
            getHtmlElement: function() {
                return widgetRef.current
            }
        }
    }, []);
    var __restAttributes = (0, _hooks.useCallback)(function() {
        var _props$value = _objectSpread(_objectSpread({}, props), {}, {
                value: void 0 !== props.value ? props.value : __state_value
            }),
            restProps = (_props$value._feedbackHideTimeout, _props$value._feedbackShowTimeout, _props$value.accessKey, _props$value.activeStateEnabled, _props$value.activeStateUnit, _props$value.aria, _props$value.children, _props$value.className, _props$value.classes, _props$value.defaultValue, _props$value.disabled, _props$value.focusStateEnabled, _props$value.height, _props$value.hint, _props$value.hoverStateEnabled, _props$value.invalidValueMessage, _props$value.max, _props$value.min, _props$value.mode, _props$value.name, _props$value.onActive, _props$value.onClick, _props$value.onContentReady, _props$value.onDimensionChanged, _props$value.onInactive, _props$value.onKeyDown, _props$value.onKeyboardHandled, _props$value.onVisibilityChange, _props$value.rtlEnabled, _props$value.showSpinButtons, _props$value.step, _props$value.tabIndex, _props$value.useLargeSpinButtons, _props$value.value, _props$value.valueChange, _props$value.visible, _props$value.width, _objectWithoutProperties(_props$value, ["_feedbackHideTimeout", "_feedbackShowTimeout", "accessKey", "activeStateEnabled", "activeStateUnit", "aria", "children", "className", "classes", "defaultValue", "disabled", "focusStateEnabled", "height", "hint", "hoverStateEnabled", "invalidValueMessage", "max", "min", "mode", "name", "onActive", "onClick", "onContentReady", "onDimensionChanged", "onInactive", "onKeyDown", "onKeyboardHandled", "onVisibilityChange", "rtlEnabled", "showSpinButtons", "step", "tabIndex", "useLargeSpinButtons", "value", "valueChange", "visible", "width"]));
        return restProps
    }, [props]);
    (0, _hooks.useEffect)(function() {
        var valueChange = props.valueChange;
        var instance = _number_box2.default.getInstance(widgetRef.current);
        if (instance) {
            instance.option(_objectSpread({}, _objectSpread(_objectSpread({}, props), {}, {
                value: void 0 !== props.value ? props.value : __state_value
            })))
        } else {
            new _number_box2.default(widgetRef.current, _objectSpread(_objectSpread({}, _objectSpread(_objectSpread({}, props), {}, {
                value: void 0 !== props.value ? props.value : __state_value
            })), {}, {
                onValueChanged: function(e) {
                    valueChange(e.value)
                }
            }))
        }
    }, [props]);
    return viewFunction({
        props: _objectSpread(_objectSpread({}, props), {}, {
            value: void 0 !== props.value ? props.value : __state_value
        }),
        widgetRef: widgetRef,
        restAttributes: __restAttributes()
    })
});
exports.default = NumberBox;
NumberBox.defaultProps = _objectSpread({}, NumberBoxProps);
