'use strict';

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

var _defineProperty2 = require('babel-runtime/helpers/defineProperty');

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _dec, _class, _class2, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactImmutableProptypes = require('react-immutable-proptypes');

var _reactImmutableProptypes2 = _interopRequireDefault(_reactImmutableProptypes);

var _immutable = require('immutable');

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _lib = require('@instructure/ui-themeable/lib');

var _lib2 = _interopRequireDefault(_lib);

var _formatMessage = require('../../../../../common/format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

var _makeScrollable = require('../../../../../common/components/shared/functionality/makeScrollable');

var _makeScrollable2 = _interopRequireDefault(_makeScrollable);

var _StimulusItems = require('./StimulusItems');

var _StimulusItems2 = _interopRequireDefault(_StimulusItems);

var _StimulusInfo = require('./StimulusInfo');

var _StimulusInfo2 = _interopRequireDefault(_StimulusInfo);

var _theme = require('./theme');

var _theme2 = _interopRequireDefault(_theme);

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

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.TakeStimulus__styles__root {\n  border-bottom: ' + theme.rootBorderWidth + ' solid ' + theme.rootBorderColor + ';\n}\n\n.TakeStimulus__styles__instructions {\n  padding: ' + theme.instructionsPaddingTopBottom + ' ' + theme.instructionsPaddingLeftRight + ';\n  border: ' + theme.instructionsBorderWidth + ' solid ' + theme.instructionsBorderColor + ';\n}\n\n.TakeStimulus__styles__instructionsHeader {\n  padding-bottom: ' + theme.instructionsHeaderPadding + ';\n  font-weight: ' + theme.instructionsHeaderFontWeight + ';\n}\n\n.TakeStimulus__styles__items {\n  padding: ' + theme.itemsPadding + ';\n  width: 50%;\n}\n\n.TakeStimulus__styles__scroll {\n  max-height: 90vh;\n  overflow: auto;\n}\n\n/* for MS Edge */\n\n@supports (-ms-ime-align: auto) {\n  .TakeStimulus__styles__scroll {\n    overflow-x: inherit;\n  }\n}\n\n.TakeStimulus__styles__stimulusGroup {\n  display: flex;\n  flex-direction: row;\n}\n\n.TakeStimulus__styles__stimulusInfo {\n  width: 50%;\n  max-height: 90vh;\n  overflow: auto;\n  height: 100%; /* this height is to allow the background color full height */\n}\n\n@media screen and (--phoneBreakPoint) {\n  .TakeStimulus__styles__stimulusGroup {\n    flex-direction: column;\n  }\n\n  .TakeStimulus__styles__stimulusInfo {\n    width: 100%;\n    max-height: auto;\n  }\n\n  .TakeStimulus__styles__items {\n    width: 100%;\n  }\n\n  .TakeStimulus__styles__scroll {\n    max-height: auto;\n  }\n\n  .TakeStimulus__styles__instructions {\n    padding: ' + theme.phoneInstructionsPaddingTopBottom + ' ' + theme.phoneInstructionsPaddingLeftRight + ';\n  }\n}\n';
  },
  'root': 'TakeStimulus__styles__root',
  'instructions': 'TakeStimulus__styles__instructions',
  'instructionsHeader': 'TakeStimulus__styles__instructionsHeader',
  'items': 'TakeStimulus__styles__items',
  'scroll': 'TakeStimulus__styles__scroll',
  'stimulusGroup': 'TakeStimulus__styles__stimulusGroup',
  'stimulusInfo': 'TakeStimulus__styles__stimulusInfo'
};
var TakeStimulus = exports.TakeStimulus = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(TakeStimulus, _Component);

  function TakeStimulus() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, TakeStimulus);

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

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = TakeStimulus.__proto__ || Object.getPrototypeOf(TakeStimulus)).call.apply(_ref, [this].concat(args))), _this), _this.scrollToInfo = function () {
      _this.props.scrollToItem('stimulus_info_' + _this.stimulus.id);
      _this.stimulusInfoRef.focus();
    }, _this.scrollToItems = function () {
      _this.props.scrollToItem('stimulus_items_' + _this.stimulus.id);
      _this.stimulusItemsRef.focus();
    }, _this.setInfoRef = function (node) {
      _this.stimulusInfoRef = node;
    }, _this.setItemsRef = function (node) {
      _this.stimulusItemsRef = node;
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(TakeStimulus, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      if (this.props.isOqaat) {
        this.stimulusInfoRef.focus();
      }
    }
  }, {
    key: 'renderStimulusInstructions',
    value: function renderStimulusInstructions() {
      var instructions = this.stimulus.instructions;
      if (instructions) {
        return _react2.default.createElement(
          'div',
          { className: styles.instructions },
          _react2.default.createElement(
            'div',
            { className: styles.instructionsHeader },
            'Instructions'
          ),
          _react2.default.createElement(
            'div',
            null,
            instructions
          )
        );
      }
    }
  }, {
    key: 'render',
    value: function render() {
      var itemsClasses = (0, _classnames2.default)(styles.items, (0, _defineProperty3.default)({}, styles.scroll, this.stimulusItems.size > 1));
      return _react2.default.createElement(
        'div',
        { className: styles.root },
        this.renderStimulusInstructions(),
        _react2.default.createElement(
          'div',
          { className: styles.stimulusGroup },
          _react2.default.createElement(
            'div',
            {
              tabIndex: '-1',
              ref: this.setInfoRef,
              className: styles.stimulusInfo,
              scrollKey: 'stimulus_info_' + this.stimulus.id
            },
            _react2.default.createElement(_StimulusInfo2.default, {
              stimulus: this.stimulus,
              scrollToItems: this.scrollToItems
            })
          ),
          _react2.default.createElement(
            'div',
            {
              tabIndex: '-1',
              className: itemsClasses,
              ref: this.setItemsRef,
              scrollKey: 'stimulus_items_' + this.stimulus.id
            },
            _react2.default.createElement(_StimulusItems2.default, {
              items: this.stimulusItems,
              quizSessionId: this.props.quizSessionId,
              scrollToInfo: this.scrollToInfo
            })
          )
        )
      );
    }
  }, {
    key: 'stimulus',
    get: function get() {
      return this.props.sessionItem.stimulusRecord;
    }
  }, {
    key: 'stimulusItems',
    get: function get() {
      return this.props.isOqaat ? (0, _immutable.List)([this.props.sessionItem]) : this.props.sessionItem.getNestedEntries();
    }
  }]);
  TakeStimulus.displayName = 'TakeStimulus'
  ;
  return TakeStimulus;
}(_react.Component), _class2.propTypes = {
  isOqaat: _propTypes2.default.bool,
  quizSessionId: _propTypes2.default.string.isRequired,
  sessionItem: _reactImmutableProptypes2.default.record.isRequired,
  scrollToItem: _propTypes2.default.func.isRequired
}, _class2.defaultProps = {
  isOqaat: false
}, _temp2)) || _class);
exports.default = (0, _makeScrollable2.default)(TakeStimulus);