'use strict';

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

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, _temp;

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 _OutcomeAlignments = require('outcomes-react/lib/containers/OutcomeAlignments');

var _OutcomeAlignments2 = _interopRequireDefault(_OutcomeAlignments);

var _Heading = require('@instructure/ui-elements/lib/components/Heading');

var _Heading2 = _interopRequireDefault(_Heading);

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

var _lib2 = _interopRequireDefault(_lib);

var _CustomPropTypes = require('../../../../../../common/util/CustomPropTypes');

var _CustomPropTypes2 = _interopRequireDefault(_CustomPropTypes);

var _Card = require('../../../../../../common/components/shared/Card');

var _Card2 = _interopRequireDefault(_Card);

var _ElementsForSelectors = require('../../../../../../common/util/ElementsForSelectors');

var _ElementsForSelectors2 = _interopRequireDefault(_ElementsForSelectors);

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

var _theme2 = _interopRequireDefault(_theme);

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

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n._6q5qgcVnYYDCGlzN3PY4a {\n  padding-bottom: 0;\n  margin-bottom: 0;\n  margin-top: 0;\n}\n\n._2xLxiZrKsoq2r_K3d_tkBx {\n  padding: ' + theme.labelPadding + ';\n  padding-left: ' + theme.labelLeftPadding + ';\n  padding-bottom: ' + theme.labelBottomPadding + ';\n\n  font-size: ' + theme.labelFontSize + ';\n  color: ' + theme.labelColor + ';\n}\n\n._3Fhel0Fa3oy2yXfa5p2AJM {\n  padding: ' + theme.contentTopBottomPadding + ' ' + theme.contentLeftRightPadding + ';\n}\n\n._2Um--4pLv_Z3OI6ZknkXfE {\n  padding-bottom: 0;\n  padding-left: 0;\n  padding-right: 0;\n}\n';
  },
  'card': '_6q5qgcVnYYDCGlzN3PY4a',
  'label': '_2xLxiZrKsoq2r_K3d_tkBx',
  'content': '_3Fhel0Fa3oy2yXfa5p2AJM',
  'wrapper': '_2Um--4pLv_Z3OI6ZknkXfE'
};
var OutcomesEditPanel = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp = _class2 = function (_Component) {
  (0, _inherits3.default)(OutcomesEditPanel, _Component);

  function OutcomesEditPanel() {
    (0, _classCallCheck3.default)(this, OutcomesEditPanel);

    var _this = (0, _possibleConstructorReturn3.default)(this, (OutcomesEditPanel.__proto__ || Object.getPrototypeOf(OutcomesEditPanel)).call(this));

    _this.applicationElement = function () {
      return (0, _ElementsForSelectors2.default)(_this.props.appContainer);
    };

    _this.onOutcomeAlignmentSetChange = _this.onOutcomeAlignmentSetChange.bind(_this);
    return _this;
  }

  (0, _createClass3.default)(OutcomesEditPanel, [{
    key: 'quizID',
    value: function quizID() {
      return this.props.quiz.id;
    }
  }, {
    key: 'workingQuiz',
    value: function workingQuiz() {
      return this.props.quiz.getWorkingInstance();
    }
  }, {
    key: 'onOutcomeAlignmentSetChange',
    value: function onOutcomeAlignmentSetChange(outcomeAlignmentSet) {
      this.props.changeQuizOutcomeAlignmentSetGuid(this.quizID(), outcomeAlignmentSet.guid);
      this.props.saveQuizChange(this.workingQuiz(), this.props.quiz);
    }
  }, {
    key: 'render',
    value: function render() {
      if (this.props.isEditing) {
        return _react2.default.createElement(
          _Card2.default,
          { wrapped: true, className: styles.card, wrapperClassName: styles.wrapper },
          _react2.default.createElement(
            'div',
            { className: styles.label },
            _react2.default.createElement(
              _Heading2.default,
              { level: 'h4', as: 'h2' },
              (0, _formatMessage2.default)('Align Outcomes to Quiz')
            )
          ),
          _react2.default.createElement(
            'div',
            { className: styles.content },
            _react2.default.createElement(_OutcomeAlignments2.default, {
              applicationElement: this.applicationElement,
              alignmentSetId: this.workingQuiz().outcomeAlignmentSetGuid,
              artifactId: this.props.quiz.id,
              artifactType: 'quiz',
              artifactTypeName: (0, _formatMessage2.default)('Quiz'),
              contextUuid: this.props.contextUuid,
              displayMasteryDescription: true,
              displayMasteryPercentText: true,
              emptySetHeading: (0, _formatMessage2.default)('Align Institution outcomes to this quiz'),
              host: this.props.outcomesEndpoint,
              jwt: this.props.outcomesToken,
              onUpdate: this.onOutcomeAlignmentSetChange
            })
          )
        );
      } else {
        return null;
      }
    }
  }]);
  OutcomesEditPanel.displayName = 'OutcomesEditPanel'
  ;
  return OutcomesEditPanel;
}(_react.Component), _class2.propTypes = {
  appContainer: _CustomPropTypes2.default.selectors.isRequired,
  quiz: _reactImmutableProptypes2.default.record.isRequired,
  contextUuid: _propTypes2.default.string.isRequired,
  outcomesEndpoint: _propTypes2.default.string.isRequired,
  outcomesToken: _propTypes2.default.string.isRequired,
  isEditing: _propTypes2.default.bool.isRequired,
  changeQuizOutcomeAlignmentSetGuid: _propTypes2.default.func.isRequired,
  saveQuizChange: _propTypes2.default.func.isRequired
}, _temp)) || _class);
exports.default = OutcomesEditPanel;