import _extends from "@babel/runtime/helpers/esm/extends";
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
import React from 'react';
import { Tooltip } from "../../../components/Tooltip";
import { DatePicker } from "../../../components/DatePicker";
export var DatePickerPlayground = /*#__PURE__*/function (_React$Component) {
  function DatePickerPlayground() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _this.state = {
      value: '17.06.2019',
      error: false,
      tooltip: false
    };
    _this.handleChange = function (value) {
      _this.setState({
        value: value
      });
    };
    _this.invalidate = function () {
      _this.setState({
        error: false,
        tooltip: false
      });
    };
    _this.validate = function () {
      var currentValue = _this.state.value;
      _this.setState(function () {
        var error = !!currentValue && !DatePicker.validate(currentValue);
        return {
          error: error,
          tooltip: error
        };
      });
    };
    _this.removeTooltip = function () {
      _this.setState({
        tooltip: false
      });
    };
    return _this;
  }
  _inheritsLoose(DatePickerPlayground, _React$Component);
  var _proto = DatePickerPlayground.prototype;
  _proto.render = function render() {
    return /*#__PURE__*/React.createElement(Tooltip, {
      trigger: this.state.tooltip ? 'opened' : 'closed',
      render: function render() {
        return 'Такой даты не существует';
      },
      onCloseClick: this.removeTooltip
    }, /*#__PURE__*/React.createElement(DatePicker, _extends({}, this.props, {
      disabled: this.props.disabled,
      size: this.props.size,
      error: this.state.error,
      value: this.state.value,
      onValueChange: this.handleChange,
      onFocus: this.invalidate,
      onBlur: this.validate,
      enableTodayLink: true
    })));
  };
  return DatePickerPlayground;
}(React.Component);