"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

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

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

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

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

var _IconMore = _interopRequireDefault(require("@instructure/ui-icons/lib/Solid/IconMore"));

var _IconImportContent = _interopRequireDefault(require("@instructure/ui-icons/lib/Line/IconImportContent"));

var _IconBank = _interopRequireDefault(require("@instructure/ui-icons/lib/Line/IconBank"));

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

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-i18n/lib/format-message"));

var _theme = _interopRequireDefault(require("./theme"));

var _dec, _class, _class2, _temp;

var styles = {
  componentId: 'exAHi',
  template: function template(theme) {
    return "\n\n.exAHi_cKjJ{color:".concat(theme.quizSavingColor || 'inherit', ";margin:").concat(theme.quizSavingMargin || 'inherit', "}\n\n.exAHi_dxna{align-items:center;display:flex;height:100%;margin-right:").concat(theme.buttonsHolderMargin || 'inherit', "}\n\n.exAHi_cLWx{font-size:").concat(theme.menuIconFontSize || 'inherit', ";margin-right:").concat(theme.menuIconMargin || 'inherit', ";vertical-align:middle}");
  },
  'quizSaving': 'exAHi_cKjJ',
  'buttonsHolder': 'exAHi_dxna',
  'menuIcon': 'exAHi_cLWx'
};
var BuildingButtons = (_dec = (0, _lib.default)(_theme.default, styles), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(BuildingButtons, _Component);

  function BuildingButtons() {
    var _getPrototypeOf2;

    var _this;

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

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

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(BuildingButtons)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.openBanksTray = function () {
      _this.props.setBanksTrayButtonRef(_this.banksTrayButton);

      _this.props.openBanksTray();
    };

    return _this;
  }

  (0, _createClass2.default)(BuildingButtons, [{
    key: "renderSavingMessage",
    value: function renderSavingMessage() {
      if (this.props.quizSaving) {
        return _react.default.createElement("div", {
          className: styles.quizSaving
        }, "Speichervorgang l\xE4uft\xA0...");
      }
    }
  }, {
    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(_react.default.createElement(_MenuItem.default, {
        key: "import",
        disabled: !this.props.canImport,
        onSelect: this.props.openModal,
        "data-automation": "sdk-import-content-menuitem"
      }, _react.default.createElement(_IconImportContent.default, {
        className: styles.menuIcon,
        "data-automation": "sdk-import-content-icon"
      }), "Inhalte importieren"));

      if (this.props.enableItemBanking) {
        menuItems.push(_react.default.createElement(_MenuItem.default, {
          key: "banks",
          onSelect: this.props.navigateToBanks,
          "data-automation": "sdk-manage-item-banks-menuitem"
        }, _react.default.createElement(_IconBank.default, {
          className: styles.menuIcon,
          "data-automation": "sdk-manage-item-banks-icon"
        }), "Objekt-Pools verwalten"));
      }

      if (menuItems.length < 1) return;
      return _react.default.createElement(_Menu.default, {
        trigger: _react.default.createElement(_Button.default, {
          variant: "icon",
          icon: _IconMore.default,
          "data-automation": "sdk-more-quiz-actions-button"
        }, _react.default.createElement(_ScreenReaderContent.default, null, "Mehr Quizaktionen"))
      }, menuItems);
    }
  }, {
    key: "render",
    value: function render() {
      return _react.default.createElement("div", {
        className: styles.buttonsHolder
      }, this.renderSavingMessage(), this.renderMenu());
    }
  }]);
  BuildingButtons.displayName = "BuildingButtons";
  return BuildingButtons;
}(_react.Component), _class2.propTypes = {
  app: _propTypes.default.string,
  canImport: _propTypes.default.bool.isRequired,
  enableItemBanking: _propTypes.default.bool,
  navigateToBanks: _propTypes.default.func.isRequired,
  openBanksTray: _propTypes.default.func.isRequired,
  openModal: _propTypes.default.func.isRequired,
  quizSaving: _propTypes.default.bool,
  setBanksTrayButtonRef: _propTypes.default.func.isRequired
}, _class2.defaultProps = {
  quizSaving: false,
  app: null,
  enableItemBanking: true
}, _temp)) || _class);
exports.default = BuildingButtons;