'use strict';

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

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 _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _Leading = require('../Leading');

var _Leading2 = _interopRequireDefault(_Leading);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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; }

var Result = function (_Component) {
  _inherits(Result, _Component);

  function Result(props, context) {
    _classCallCheck(this, Result);

    return _possibleConstructorReturn(this, (Result.__proto__ || Object.getPrototypeOf(Result)).call(this, props, context));
  }

  _createClass(Result, [{
    key: 'render',
    value: function render() {
      var _props = this.props;
      var results = _props.results;
      var questions = _props.questions;
      var answers = _props.answers;

      var score = _lodash2.default.chain(questions).map(function (itm, idx) {
        var options = itm.options;

        var s = _lodash2.default.find(options, { id: answers[idx] })['score'];
        return s;
      }).reduce(function (t, n) {
        return t + n;
      }).value();
      var rs = _lodash2.default.chain(results).filter(function (itm) {
        return score >= itm.range.from && score < itm.range.to;
      }).first().value();
      var mediaSource = {
        heroImage: { image: _lodash2.default.get(rs, ['image'], null) },
        heroVideo: { video: _lodash2.default.get(rs, ['video'], null) },
        audio: { audio: _lodash2.default.get(rs, ['audio'], null) }
      };
      return _react2.default.createElement(
        'div',
        { className: 'result-container' },
        _react2.default.createElement(_Leading2.default, { leading: 'image', mediaSource: mediaSource }),
        _react2.default.createElement(
          'h3',
          null,
          rs.title
        )
      );
    }
  }]);

  return Result;
}(_react.Component);

exports.default = Result;