import { __assign, __extends } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { Component } from 'react';
import debounce from '../../utils/debounce';
import color from '../helpers/color';
export var ColorWrap = function (Picker) {
    var ColorPicker = (function (_super) {
        __extends(ColorPicker, _super);
        function ColorPicker(props) {
            var _this = _super.call(this, props) || this;
            _this.debounce = debounce(function (fn, data, event) {
                fn(data, event);
            }, 100);
            _this.handleChange = function (data, event) {
                var isValidColor = color.simpleCheckForValidColor(data);
                if (isValidColor) {
                    var colors = color.toState(data, data.h || _this.state.oldHue);
                    _this.setState(colors);
                    _this.props.onChangeComplete &&
                        _this.debounce(_this.props.onChangeComplete, colors, event);
                    _this.props.onChange && _this.props.onChange(colors, event);
                }
            };
            _this.state = __assign(__assign({}, color.toState(props.color, 0)), { visible: props.display });
            return _this;
        }
        ColorPicker.getDerivedStateFromProps = function (props, state) {
            return __assign(__assign({}, color.toState(props.color, state.oldHue)), { visible: props.display });
        };
        ColorPicker.prototype.render = function () {
            return (_jsx(Picker, __assign({}, this.props, this.state, { onChange: this.handleChange }), void 0));
        };
        ColorPicker.defaultProps = {
            color: {
                h: 250,
                s: 0.5,
                l: 0.2,
                a: 1,
            },
        };
        return ColorPicker;
    }(Component));
    return ColorPicker;
};
export default ColorWrap;
