'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = 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 _classnames2 = require('classnames');

var _classnames3 = _interopRequireDefault(_classnames2);

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

var _Button2 = _interopRequireDefault(_Button);

var _IconEditLine = require('instructure-icons/lib/Line/IconEditLine');

var _IconEditLine2 = _interopRequireDefault(_IconEditLine);

var _IconTrashLine = require('instructure-icons/lib/Line/IconTrashLine');

var _IconTrashLine2 = _interopRequireDefault(_IconTrashLine);

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

var _ScreenReaderContent2 = _interopRequireDefault(_ScreenReaderContent);

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

var _lib2 = _interopRequireDefault(_lib);

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

var _DragHandle2 = _interopRequireDefault(_DragHandle);

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

var _makeScrollable2 = _interopRequireDefault(_makeScrollable);

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

var _noop2 = _interopRequireDefault(_noop);

var _constants = require('../../../../constants');

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.ActionButtons__styles__buttons {\n  flex: 0 0 auto;\n  display: inline-flex;\n  text-align: right;\n  z-index: ' + theme.buttonsZIndex + ';\n  color: ' + theme.buttonsColor + ';\n  font-size: 1.1rem;\n  padding: 0 ' + theme.buttonsPadding + ';\n}\n\n[dir="ltr"] .ActionButtons__styles__buttons {\n  text-align: right;\n}\n\n[dir="rtl"] .ActionButtons__styles__buttons {\n  text-align: right;\n}\n\n.ActionButtons__styles__edit.ActionButtons__styles__hide {\n  display: none;\n}\n';
  },
  'buttons': 'ActionButtons__styles__buttons',
  'edit': 'ActionButtons__styles__edit',
  'hide': 'ActionButtons__styles__hide'
};


var ScrollTargetButton = (0, _makeScrollable2.default)(_Button2.default);

var ActionButtons = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(ActionButtons, _Component);

  function ActionButtons() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = ActionButtons.__proto__ || Object.getPrototypeOf(ActionButtons)).call.apply(_ref, [this].concat(args))), _this), _this.connectDragSource = function (dragHandle) {
      if (_this.props.shouldDisableDragHandle) {
        return dragHandle;
      }
      return _this.props.connectDragSource(dragHandle);
    }, _this.onButtonFocus = function (e) {
      e.stopPropagation();
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(ActionButtons, [{
    key: 'render',
    value: function render() {
      var _classnames;

      var editClasses = (0, _classnames3.default)((_classnames = {}, (0, _defineProperty3.default)(_classnames, styles.edit, true), (0, _defineProperty3.default)(_classnames, styles.hide, !this.props.shouldRenderEdit), _classnames));
      return _react2.default.createElement(
        'div',
        { tabIndex: '-1', onFocus: this.onButtonFocus, className: styles.buttons },
        _react2.default.createElement(
          'div',
          { className: editClasses },
          _react2.default.createElement(
            ScrollTargetButton,
            {
              as: 'div',
              onClick: this.props.switchOnEditing,
              scrollKey: this.props.scrollKey,
              variant: 'icon',
              icon: _IconEditLine2.default,
              size: 'small',
              'data-automation': 'sdk-edit-question-button',
              shouldFocusOnMount: this.props.shouldFocusOnMount
            },
            _react2.default.createElement(
              _ScreenReaderContent2.default,
              null,
              this.props.quizEntry.generateScreenReaderText(this.props.displayPosition, _constants.EDIT)
            )
          )
        ),
        this.connectDragSource(_react2.default.createElement(
          'div',
          null,
          _react2.default.createElement(_DragHandle2.default, {
            displayPosition: this.props.displayPosition,
            quizEntry: this.props.quizEntry,
            quizEntries: this.props.quizEntries,
            disabled: this.props.shouldDisableDragHandle
          })
        )),
        _react2.default.createElement(
          _Button2.default,
          {
            as: 'div',
            onClick: this.props.onDelete,
            disabled: this.props.shouldDisableDeleteButton,
            variant: 'icon',
            icon: _IconTrashLine2.default,
            size: 'small',
            'data-automation': 'sdk-delete-question-button'
          },
          _react2.default.createElement(
            _ScreenReaderContent2.default,
            null,
            this.props.quizEntry.generateScreenReaderText(this.props.displayPosition, _constants.REMOVE)
          )
        )
      );
    }
  }]);
  ActionButtons.displayName = 'ActionButtons'
  ;
  return ActionButtons;
}(_react.Component), _class2.propTypes = {
  connectDragSource: _propTypes2.default.func.isRequired,
  displayPosition: _propTypes2.default.number.isRequired,
  onDelete: _propTypes2.default.func.isRequired,
  quizEntries: _reactImmutableProptypes2.default.listOf(_reactImmutableProptypes2.default.record).isRequired,
  quizEntry: _reactImmutableProptypes2.default.record.isRequired,
  scrollKey: _propTypes2.default.string,
  shouldDisableDragHandle: _propTypes2.default.bool,
  shouldDisableDeleteButton: _propTypes2.default.bool,
  shouldRenderEdit: _propTypes2.default.bool,
  switchOnEditing: _propTypes2.default.func,
  shouldFocusOnMount: _propTypes2.default.bool
}, _class2.defaultProps = {
  scrollKey: void 0,
  shouldDisableDragHandle: false,
  shouldDisableDeleteButton: false,
  shouldRenderDelete: true,
  shouldRenderEdit: true,
  switchOnEditing: _noop2.default,
  shouldFocusOnMount: false
}, _temp2)) || _class);
exports.default = ActionButtons;