'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Suite = undefined;

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _class, _desc, _value, _class2, _descriptor;

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _mobx = require('mobx');

var _mobxReact = require('mobx-react');

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _util = require('../lib/util');

var _test = require('../test/test');

var _test2 = _interopRequireDefault(_test);

var _collapsible = require('../collapsible/collapsible');

var _collapsible2 = _interopRequireDefault(_collapsible);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _initDefineProp(target, property, descriptor, context) {
  if (!descriptor) return;
  Object.defineProperty(target, property, {
    enumerable: descriptor.enumerable,
    configurable: descriptor.configurable,
    writable: descriptor.writable,
    value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
  });
}

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
  var desc = {};
  Object['ke' + 'ys'](descriptor).forEach(function (key) {
    desc[key] = descriptor[key];
  });
  desc.enumerable = !!desc.enumerable;
  desc.configurable = !!desc.configurable;

  if ('value' in desc || desc.initializer) {
    desc.writable = true;
  }

  desc = decorators.slice().reverse().reduce(function (desc, decorator) {
    return decorator(target, property, desc) || desc;
  }, desc);

  if (context && desc.initializer !== void 0) {
    desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
    desc.initializer = undefined;
  }

  if (desc.initializer === void 0) {
    Object['define' + 'Property'](target, property, desc);
    desc = null;
  }

  return desc;
}

function _initializerWarningHelper(descriptor, context) {
  throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.');
}

var Suite = (0, _mobxReact.observer)(function (_ref) {
  var model = _ref.model;

  if (!model.shouldRender) return null;

  return _react2.default.createElement(
    _collapsible2.default,
    {
      header: _react2.default.createElement(
        'span',
        { className: 'runnable-title' },
        model.title
      ),
      headerClass: 'runnable-wrapper',
      headerStyle: { paddingLeft: (0, _util.indent)(model.level) },
      contentClass: 'runnables-region',
      isOpen: true
    },
    _react2.default.createElement(
      'ul',
      { className: 'runnables' },
      _lodash2.default.map(model.children, function (runnable) {
        return _react2.default.createElement(Runnable, { key: runnable.id, model: runnable });
      })
    )
  );
});

var Runnable = (0, _mobxReact.observer)(_class = (_class2 = function (_Component) {
  _inherits(Runnable, _Component);

  function Runnable() {
    var _ref2;

    var _temp, _this, _ret;

    _classCallCheck(this, Runnable);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref2 = Runnable.__proto__ || Object.getPrototypeOf(Runnable)).call.apply(_ref2, [this].concat(args))), _this), _initDefineProp(_this, 'isHovering', _descriptor, _this), _this._hover = function (shouldHover) {
      return (0, _mobx.action)('runnable:hover', function (e) {
        e.stopPropagation();
        _this.isHovering = shouldHover;
      });
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(Runnable, [{
    key: 'render',
    value: function render() {
      var model = this.props.model;


      return _react2.default.createElement(
        'li',
        {
          className: (0, _classnames2.default)(model.type + ' runnable runnable-' + model.state, {
            hover: this.isHovering
          }),
          onMouseOver: this._hover(true),
          onMouseOut: this._hover(false)
        },
        model.type === 'test' ? _react2.default.createElement(_test2.default, { model: model }) : _react2.default.createElement(Suite, { model: model })
      );
    }
  }]);

  return Runnable;
}(_react.Component), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'isHovering', [_mobx.observable], {
  enumerable: true,
  initializer: function initializer() {
    return false;
  }
})), _class2)) || _class;

exports.Suite = Suite;
exports.default = Runnable;