"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@storybook/react");
var _ScrollableContainer = _interopRequireDefault(require("../ScrollableContainer"));
var _ScrollableContainerPrivateUni = require("./ScrollableContainer.private.uni.driver");
var _vanilla = require("@wix/wix-ui-test-utils/vanilla");
var _index = require("../index");
var _excluded = ["expected"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/common/ScrollableContainer/test/ScrollableContainer.visual.jsx",
  _this = void 0;
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var commonProps = {
  style: {
    height: '300px',
    width: '200px',
    border: '1px solid black'
  },
  children: new Array(50).fill('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ').join()
};
var scrollableContainerTestkitFactory = (0, _vanilla.testkitFactoryCreator)(_ScrollableContainerPrivateUni.scrollableContainerPrivateUniDriverFactory);
var dataHook = 'scrollable-container';
var createDriver = function createDriver() {
  return scrollableContainerTestkitFactory({
    wrapper: document.body,
    dataHook: dataHook
  });
};
var tests = [{
  describe: 'scroll-y area',
  its: [],
  skippedIts: [{
    it: 'no scroll',
    props: {
      children: 'short text'
    },
    expected: _index.AreaY.NONE
  }, {
    it: 'scrolled to top',
    props: {},
    expected: _index.AreaY.TOP
  }, {
    it: 'scrolled to middle',
    props: {},
    expected: _index.AreaY.MIDDLE,
    componentDidMount: function componentDidMount() {
      createDriver()._scrollContentTo({
        y: 375
      });
    }
  }, {
    it: 'scrolled to bottom',
    props: {},
    expected: _index.AreaY.BOTTOM,
    componentDidMount: function componentDidMount() {
      createDriver()._scrollContentTo({
        y: 99999
      });
    }
  }]
}, {
  describe: 'scroll-y information',
  its: [{
    it: 'scrolled to 500',
    props: {},
    expected: 500,
    componentDidMount: function componentDidMount() {
      createDriver()._scrollContentTo({
        y: 500
      });
    }
  }]
}];
var ScrollableContainerWrapper = function ScrollableContainerWrapper(_ref) {
  var expected = _ref.expected,
    props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
  var _useState = (0, _react.useState)(''),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    scrollArea = _useState2[0],
    setScrollArea = _useState2[1];
  var _useState3 = (0, _react.useState)(0),
    _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
    scrollTop = _useState4[0],
    setScrollTop = _useState4[1];
  var handleScrollAreaChanged = function handleScrollAreaChanged(_ref2) {
    var area = _ref2.area;
    return setScrollArea(area.y);
  };
  var handleScrollChanged = function handleScrollChanged(_ref3) {
    var target = _ref3.target;
    return setScrollTop(target.scrollTop);
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 86,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react["default"].createElement(_ScrollableContainer["default"], (0, _extends2["default"])({}, props, {
    onScrollAreaChanged: handleScrollAreaChanged,
    onScrollChanged: handleScrollChanged,
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 87,
      columnNumber: 7
    }
  })), /*#__PURE__*/_react["default"].createElement("br", {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 92,
      columnNumber: 7
    }
  }), /*#__PURE__*/_react["default"].createElement("div", {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 93,
      columnNumber: 7
    }
  }, "Scroll-Y:", /*#__PURE__*/_react["default"].createElement("ul", {
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 95,
      columnNumber: 9
    }
  }, /*#__PURE__*/_react["default"].createElement("li", {
    "data-test-ready": scrollArea === expected,
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 96,
      columnNumber: 11
    }
  }, "Area: ".concat(scrollArea)), /*#__PURE__*/_react["default"].createElement("li", {
    "data-test-ready": scrollTop === expected,
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 99,
      columnNumber: 11
    }
  }, "scrollTop: ".concat(scrollTop)))));
};
tests.forEach(function (_ref4) {
  var describe = _ref4.describe,
    its = _ref4.its;
  its.forEach(function (_ref5) {
    var it = _ref5.it,
      props = _ref5.props,
      componentDidMount = _ref5.componentDidMount,
      expected = _ref5.expected;
    (0, _react2.storiesOf)("ScrollableContainer".concat(describe ? '/' + describe : ''), module).add(it, function () {
      (0, _react.useEffect)(function () {
        componentDidMount && componentDidMount();
      }, []);
      return /*#__PURE__*/_react["default"].createElement(ScrollableContainerWrapper, (0, _extends2["default"])({
        componentDidMount: componentDidMount,
        expected: expected,
        dataHook: dataHook
      }, commonProps, props, {
        __self: _this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 120,
          columnNumber: 11
        }
      }));
    }, {
      eyes: {
        waitBeforeScreenshot: "[data-test-ready=\"true\"]"
      }
    });
  });
});