"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireDefault(require("react"));
var _react2 = require("@storybook/react");
var _index = _interopRequireDefault(require("../index"));
var _Layout = require("../../Layout");
var _FormField = _interopRequireDefault(require("../../FormField"));
var _visual = require("../../utils/test-utils/visual");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/AutoComplete/test/AutoComplete.visual.jsx",
  _this2 = void 0;
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(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; })(); }
var interactiveDataHook = 'interactive-dropdown';
var inputDataHook = 'wsr-input';
var InteractiveEyeTest = /*#__PURE__*/function (_React$Component) {
  function InteractiveEyeTest() {
    var _this;
    (0, _classCallCheck2["default"])(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;
  }
  (0, _inherits2["default"])(InteractiveEyeTest, _React$Component);
  return (0, _createClass2["default"])(InteractiveEyeTest, [{
    key: "componentDidMount",
    value: function () {
      var _componentDidMount = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
        return _regenerator["default"].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["default"].createElement(_Layout.Layout, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 29,
          columnNumber: 7
        }
      }, /*#__PURE__*/_react["default"].createElement(_Layout.Cell, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 30,
          columnNumber: 9
        }
      }, /*#__PURE__*/_react["default"].createElement(_index["default"], (0, _extends2["default"])({
        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["default"].Component);
var AutocompleteWithFormFieldStatus = /*#__PURE__*/function (_React$Component2) {
  function AutocompleteWithFormFieldStatus() {
    (0, _classCallCheck2["default"])(this, AutocompleteWithFormFieldStatus);
    return _callSuper(this, AutocompleteWithFormFieldStatus, arguments);
  }
  (0, _inherits2["default"])(AutocompleteWithFormFieldStatus, _React$Component2);
  return (0, _createClass2["default"])(AutocompleteWithFormFieldStatus, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/_react["default"].createElement(_Layout.Layout, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 51,
          columnNumber: 7
        }
      }, /*#__PURE__*/_react["default"].createElement(_Layout.Cell, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 52,
          columnNumber: 9
        }
      }, /*#__PURE__*/_react["default"].createElement(_FormField["default"], {
        status: this.props.status,
        statusMessage: this.props.statusMessage,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 53,
          columnNumber: 11
        }
      }, /*#__PURE__*/_react["default"].createElement(_index["default"], {
        dataHook: interactiveDataHook,
        placeholder: "Start typing",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 57,
          columnNumber: 13
        }
      })), /*#__PURE__*/_react["default"].createElement(_index["default"], {
        status: this.props.status,
        dataHook: interactiveDataHook,
        placeholder: "Start typing",
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 62,
          columnNumber: 11
        }
      })));
    }
  }]);
}(_react["default"].Component);
var interactiveTests = [{
  describe: 'Usage',
  its: [{
    it: 'simple',
    componentDidMount: function componentDidMount() {
      (0, _visual.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() {
      (0, _visual.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() {
      (0, _visual.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;
    (0, _react2.storiesOf)("AutoComplete".concat(describe ? '/' + describe : ''), module).add(it, function () {
      return /*#__PURE__*/_react["default"].createElement(InteractiveEyeTest, (0, _extends2["default"])({}, 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;
    (0, _react2.storiesOf)("AutoComplete".concat(describe ? '/' + describe : ''), module).add(it, function () {
      return /*#__PURE__*/_react["default"].createElement(AutocompleteWithFormFieldStatus, (0, _extends2["default"])({}, props, {
        __self: _this2,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 167,
          columnNumber: 13
        }
      }));
    });
  });
});