"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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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 _reactImmutableProptypes = _interopRequireDefault(require("react-immutable-proptypes"));

var _classnames2 = _interopRequireDefault(require("classnames"));

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

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

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

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

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

var _DragHandle = _interopRequireDefault(require("../../../../common/components/shared/drag_and_drop/DragHandle"));

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

var _noop = _interopRequireDefault(require("../../../../common/util/noop"));

var _constants = require("@instructure/quiz-common/lib/constants");

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

var _dec, _class, _class2, _temp;

var styles = {
  componentId: 'hXnXu',
  template: function template(theme) {
    return "\n\n.hXnXu_exDh{color:".concat(theme.buttonsColor || 'inherit', ";display:inline-flex;flex:0 0 auto;font-size:1.1rem;padding:0 ").concat(theme.buttonsPadding || 'inherit', ";text-align:right;z-index:").concat(theme.buttonsZIndex || 'inherit', "}\n\n[dir=ltr] .hXnXu_exDh,[dir=rtl] .hXnXu_exDh{text-align:right}\n\n.hXnXu_fwKS.hXnXu_bBLs{display:none}");
  },
  'buttons': 'hXnXu_exDh',
  'edit': 'hXnXu_fwKS',
  'hide': 'hXnXu_bBLs'
};
var ScrollTargetButton = (0, _makeScrollable.default)(_Button.default);
var ActionButtons = (_dec = (0, _lib.default)(_theme.default, styles), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(ActionButtons, _Component);

  function ActionButtons() {
    var _getPrototypeOf2;

    var _this;

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

    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)(ActionButtons)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.connectDragSource = function (dragHandle) {
      if (_this.props.shouldDisableDragHandle) {
        return dragHandle;
      }

      return _this.props.connectDragSource(dragHandle);
    };

    _this.onButtonFocus = function (e) {
      e.stopPropagation();
    };

    _this.switchOnEditing = function () {
      _this.props.switchOnEditing();
    };

    return _this;
  }

  (0, _createClass2.default)(ActionButtons, [{
    key: "shouldFocusOnMount",
    value: function shouldFocusOnMount() {
      return this.props.shouldFocusOnMount && !this.props.editingAddContentPopover;
    }
  }, {
    key: "render",
    value: function render() {
      var _classnames;

      var editClasses = (0, _classnames2.default)((_classnames = {}, (0, _defineProperty2.default)(_classnames, styles.edit, true), (0, _defineProperty2.default)(_classnames, styles.hide, !this.props.shouldRenderEdit), _classnames));
      return _react.default.createElement("div", {
        tabIndex: "-1",
        onFocus: this.onButtonFocus,
        className: styles.buttons
      }, _react.default.createElement("div", {
        className: editClasses
      }, _react.default.createElement(ScrollTargetButton, {
        as: "div",
        onClick: this.switchOnEditing,
        scrollKey: this.props.scrollKey,
        variant: "icon",
        icon: _IconEdit.default,
        size: "small",
        "data-automation": "sdk-edit-question-button",
        shouldFocusOnMount: this.shouldFocusOnMount()
      }, _react.default.createElement(_ScreenReaderContent.default, null, this.props.quizEntry.generateScreenReaderText(this.props.displayPosition, _constants.EDIT)))), this.connectDragSource(_react.default.createElement("div", null, _react.default.createElement(_DragHandle.default, {
        displayPosition: this.props.displayPosition,
        quizEntry: this.props.quizEntry,
        quizEntries: this.props.quizEntries,
        disabled: this.props.shouldDisableDragHandle
      }))), _react.default.createElement(_Button.default, {
        as: "div",
        onClick: this.props.onDelete,
        disabled: this.props.shouldDisableDeleteButton,
        variant: "icon",
        icon: _IconTrash.default,
        size: "small",
        "data-automation": "sdk-delete-question-button"
      }, _react.default.createElement(_ScreenReaderContent.default, null, this.props.quizEntry.generateScreenReaderText(this.props.displayPosition, _constants.REMOVE))));
    }
  }]);
  ActionButtons.displayName = "ActionButtons";
  return ActionButtons;
}(_react.Component), _class2.propTypes = {
  connectDragSource: _propTypes.default.func.isRequired,
  displayPosition: _propTypes.default.number.isRequired,
  editingAddContentPopover: _propTypes.default.bool.isRequired,
  onDelete: _propTypes.default.func.isRequired,
  quizEntries: _reactImmutableProptypes.default.listOf(_reactImmutableProptypes.default.record).isRequired,
  quizEntry: _reactImmutableProptypes.default.record.isRequired,
  scrollKey: _propTypes.default.string,
  shouldDisableDragHandle: _propTypes.default.bool,
  shouldDisableDeleteButton: _propTypes.default.bool,
  shouldRenderEdit: _propTypes.default.bool,
  switchOnEditing: _propTypes.default.func,
  shouldFocusOnMount: _propTypes.default.bool
}, _class2.defaultProps = {
  scrollKey: void 0,
  shouldDisableDragHandle: false,
  shouldDisableDeleteButton: false,
  shouldRenderDelete: true,
  shouldRenderEdit: true,
  switchOnEditing: _noop.default,
  shouldFocusOnMount: false
}, _temp)) || _class);
exports.default = ActionButtons;