import _extends from "@babel/runtime/helpers/extends";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/esm/AutoComplete/test/AutoComplete.visual.jsx",
  _this2 = this;
import _regeneratorRuntime from "@babel/runtime/regenerator";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import React from 'react';
import { storiesOf } from '@storybook/react';
import AutoComplete from '../index';
import { Layout, Cell } from '../../Layout';
import FormField from '../../FormField';
import { clickElement } from '../../utils/test-utils/visual';
var interactiveDataHook = 'interactive-dropdown';
var inputDataHook = 'wsr-input';
var InteractiveEyeTest = /*#__PURE__*/function (_React$Component) {
  function InteractiveEyeTest() {
    var _this;
    _classCallCheck(this, InteractiveEyeTest);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, InteractiveEyeTest, [].concat(args));
    _this.state = {
      value: ' '
    };
    _this.onSelect = function (option) {
      _this.setState({
        value: option.value
      });
    };
    _this.onChange = function (event) {
      _this.setState({
        value: event.target.value
      });
    };
    return _this;
  }
  _inherits(InteractiveEyeTest, _React$Component);
  return _createClass(InteractiveEyeTest, [{
    key: "componentDidMount",
    value: function () {
      var _componentDidMount = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              this.props.componentDidMount();
            case 1:
            case "end":
              return _context.stop();
          }
        }, _callee, this);
      }));
      function componentDidMount() {
        return _componentDidMount.apply(this, arguments);
      }
      return componentDidMount;
    }()
  }, {
    key: "render",
    value: function render() {
      var value = this.state.value;
      return /*#__PURE__*/React.createElement(Layout, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 29,
          columnNumber: 7
        }
      }, /*#__PURE__*/React.createElement(Cell, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 30,
          columnNumber: 9
        }
      }, /*#__PURE__*/React.createElement(AutoComplete, _extends({
        dataHook: interactiveDataHook,
        value: value,
        onChange: this.onChange,
        onSelect: this.onSelect,
        placeholder: "Start typing",
        predicate: function predicate(option) {
          return option.value.toLowerCase().indexOf(value.toLowerCase()) !== -1;
        }
      }, this.props, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 31,
          columnNumber: 11
        }
      }))));
    }
  }]);
}(React.Component);
var AutocompleteWithFormFieldStatus = /*#__PURE__*/function (_React$Component2) {
  function AutocompleteWithFormFieldStatus() {
    _classCallCheck(this, AutocompleteWithFormFieldStatus);
    return _callSuper(this, AutocompleteWithFormFieldStatus, arguments);
  }
  _inherits(AutocompleteWithFormFieldStatus, _React$Component2);
  return _createClass(AutocompleteWithFormFieldStatus, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/React.createElement(Layout, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 51,
          columnNumber: 7
        }
      }, /*#__PURE__*/React.createElement(Cell, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 52,
          columnNumber: 9
        }
      }, /*#__PURE__*/React.createElement(FormField, {
        status: this.props.status,
        statusMessage: this.props.statusMessage,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 53,
          columnNumber: 11
        }
      }, /*#__PURE__*/React.createElement(AutoComplete, {
        dataHook: interactiveDataHook,
        placeholder: "Start typing",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 57,
          columnNumber: 13
        }
      })), /*#__PURE__*/React.createElement(AutoComplete, {
        status: this.props.status,
        dataHook: interactiveDataHook,
        placeholder: "Start typing",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 62,
          columnNumber: 11
        }
      })));
    }
  }]);
}(React.Component);
var interactiveTests = [{
  describe: 'Usage',
  its: [{
    it: 'simple',
    componentDidMount: function componentDidMount() {
      clickElement(inputDataHook);
    },
    props: {
      options: [{
        id: 0,
        value: 'First option'
      }, {
        id: 1,
        value: 'Second option'
      }, {
        id: 2,
        value: 'Third option'
      }, {
        id: 3,
        value: 'Fifth option'
      }, {
        id: 4,
        value: 'Fourth option'
      }]
    }
  }, {
    it: 'disabled',
    componentDidMount: function componentDidMount() {
      clickElement(inputDataHook);
    },
    props: {
      disabled: true,
      options: [{
        id: 0,
        value: 'First option'
      }, {
        id: 1,
        value: 'Second option'
      }, {
        id: 2,
        value: 'Third option'
      }, {
        id: 3,
        value: 'Fifth option'
      }, {
        id: 4,
        value: 'Fourth option'
      }]
    }
  }, {
    it: 'error',
    componentDidMount: function componentDidMount() {
      clickElement(inputDataHook);
    },
    props: {
      status: 'error',
      options: [{
        id: 0,
        value: 'First option'
      }, {
        id: 1,
        value: 'Second option'
      }, {
        id: 2,
        value: 'Third option'
      }, {
        id: 3,
        value: 'Fifth option'
      }, {
        id: 4,
        value: 'Fourth option'
      }]
    }
  }]
}];
var AutocompleteWithFormFieldStatusTests = [{
  describe: 'AutoCompleteWithFormField',
  its: [{
    it: 'error',
    props: {
      options: [],
      status: 'error',
      statusMessage: 'This is an error'
    }
  }, {
    it: 'warning',
    props: {
      options: [],
      status: 'warning',
      statusMessage: 'This is a warning'
    }
  }]
}];
interactiveTests.forEach(function (_ref) {
  var describe = _ref.describe,
    its = _ref.its;
  its.forEach(function (_ref2) {
    var it = _ref2.it,
      props = _ref2.props,
      componentDidMount = _ref2.componentDidMount;
    storiesOf("AutoComplete".concat(describe ? '/' + describe : ''), module).add(it, function () {
      return /*#__PURE__*/React.createElement(InteractiveEyeTest, _extends({}, props, {
        componentDidMount: componentDidMount,
        __self: _this2,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 157,
          columnNumber: 9
        }
      }));
    });
  });
});
AutocompleteWithFormFieldStatusTests.forEach(function (_ref3) {
  var describe = _ref3.describe,
    its = _ref3.its;
  its.forEach(function (_ref4) {
    var it = _ref4.it,
      props = _ref4.props;
    storiesOf("AutoComplete".concat(describe ? '/' + describe : ''), module).add(it, function () {
      return /*#__PURE__*/React.createElement(AutocompleteWithFormFieldStatus, _extends({}, props, {
        __self: _this2,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 167,
          columnNumber: 13
        }
      }));
    });
  });
});