'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, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _Button = require('@instructure/ui-buttons/lib/components/Button');

var _Button2 = _interopRequireDefault(_Button);

var _Menu = require('@instructure/ui-menu/lib/components/Menu');

var _Menu2 = _interopRequireDefault(_Menu);

var _MenuItem = require('@instructure/ui-menu/lib/components/Menu/MenuItem');

var _MenuItem2 = _interopRequireDefault(_MenuItem);

var _ScreenReaderContent = require('@instructure/ui-a11y/lib/components/ScreenReaderContent');

var _ScreenReaderContent2 = _interopRequireDefault(_ScreenReaderContent);

var _IconMoreSolid = require('instructure-icons/lib/Solid/IconMoreSolid');

var _IconMoreSolid2 = _interopRequireDefault(_IconMoreSolid);

var _IconImportContentLine = require('instructure-icons/lib/Line/IconImportContentLine');

var _IconImportContentLine2 = _interopRequireDefault(_IconImportContentLine);

var _IconBankLine = require('instructure-icons/lib/Line/IconBankLine');

var _IconBankLine2 = _interopRequireDefault(_IconBankLine);

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

var _lib2 = _interopRequireDefault(_lib);

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

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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._21MhUMrR-v_VJwn1dooc_S {\n  color: ' + theme.quizSavingColor + ';\n  margin: ' + theme.quizSavingMargin + ';\n}\n\n.Zff-in8HOA5Zb10dq_539 {\n  height: 100%;\n  margin-right: ' + theme.buttonsHolderMargin + ';\n  display: flex;\n  align-items: center;\n}\n\n.kYny2wojY7BYymZpcUr4x {\n  vertical-align: middle;\n  margin-right: ' + theme.menuIconMargin + ';\n  font-size: ' + theme.menuIconFontSize + ';\n}\n';
  },
  'quizSaving': '_21MhUMrR-v_VJwn1dooc_S',
  'buttonsHolder': 'Zff-in8HOA5Zb10dq_539',
  'menuIcon': 'kYny2wojY7BYymZpcUr4x'
};
var BuildingButtons = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(BuildingButtons, _Component);

  function BuildingButtons() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = BuildingButtons.__proto__ || Object.getPrototypeOf(BuildingButtons)).call.apply(_ref, [this].concat(args))), _this), _this.openBanksTray = function () {
      _this.props.setBanksTrayButtonRef(_this.banksTrayButton);
      _this.props.openBanksTray();
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(BuildingButtons, [{
    key: 'renderSavingMessage',
    value: function renderSavingMessage() {
      if (this.props.quizSaving) {
        return _react2.default.createElement(
          'div',
          { className: styles.quizSaving },
          (0, _formatMessage2.default)('Saving...')
        );
      }
    }
  }, {
    key: 'isBuildingPage',
    value: function isBuildingPage() {
      return ['building', 'settings'].includes(this.props.app);
    }
  }, {
    key: 'renderMenu',
    value: function renderMenu() {
      if (!this.isBuildingPage()) return;

      var menuItems = [];
      menuItems.push(_react2.default.createElement(
        _MenuItem2.default,
        {
          key: 'import',
          disabled: !this.props.canImport,
          onSelect: this.props.openModal,
          'data-automation': 'sdk-import-content-menuitem'
        },
        _react2.default.createElement(_IconImportContentLine2.default, { className: styles.menuIcon, 'data-automation': 'sdk-import-content-icon' }),
        (0, _formatMessage2.default)('Import Content')
      ));

      if (this.props.enableItemBanking) {
        menuItems.push(_react2.default.createElement(
          _MenuItem2.default,
          {
            key: 'banks',
            onSelect: this.props.navigateToBanks,
            'data-automation': 'sdk-manage-item-banks-menuitem'
          },
          _react2.default.createElement(_IconBankLine2.default, { className: styles.menuIcon, 'data-automation': 'sdk-manage-item-banks-icon' }),
          (0, _formatMessage2.default)('Manage Item Banks')
        ));
      }
      if (menuItems.length < 1) return;

      return _react2.default.createElement(
        _Menu2.default,
        {
          trigger: _react2.default.createElement(
            _Button2.default,
            {
              variant: 'icon',
              icon: _IconMoreSolid2.default,
              'data-automation': 'sdk-more-quiz-actions-button'
            },
            _react2.default.createElement(
              _ScreenReaderContent2.default,
              null,
              (0, _formatMessage2.default)('More Quiz Actions')
            )
          )
        },
        menuItems
      );
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        { className: styles.buttonsHolder },
        this.renderSavingMessage(),
        this.renderMenu()
      );
    }
  }]);
  BuildingButtons.displayName = 'BuildingButtons'
  ;
  return BuildingButtons;
}(_react.Component), _class2.propTypes = {
  app: _propTypes2.default.string,
  canImport: _propTypes2.default.bool.isRequired,
  enableItemBanking: _propTypes2.default.bool,
  navigateToBanks: _propTypes2.default.func.isRequired,
  openBanksTray: _propTypes2.default.func.isRequired,
  openModal: _propTypes2.default.func.isRequired,
  quizSaving: _propTypes2.default.bool,
  setBanksTrayButtonRef: _propTypes2.default.func.isRequired
}, _class2.defaultProps = {
  quizSaving: false,
  app: null,
  enableItemBanking: true
}, _temp2)) || _class);
exports.default = BuildingButtons;