"use strict";

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

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

var _Icon = _interopRequireWildcard(require("./Icon"));

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

var defaultToolbars = [{
  key: 'zoomIn',
  actionType: _Icon.ActionType.zoomIn
}, {
  key: 'zoomOut',
  actionType: _Icon.ActionType.zoomOut
}, {
  key: 'prev',
  actionType: _Icon.ActionType.prev
}, {
  key: 'reset',
  actionType: _Icon.ActionType.reset
}, {
  key: 'next',
  actionType: _Icon.ActionType.next
}, {
  key: 'rotateLeft',
  actionType: _Icon.ActionType.rotateLeft
}, {
  key: 'rotateRight',
  actionType: _Icon.ActionType.rotateRight
}, {
  key: 'scaleX',
  actionType: _Icon.ActionType.scaleX
}, {
  key: 'scaleY',
  actionType: _Icon.ActionType.scaleY
}, {
  key: 'download',
  actionType: _Icon.ActionType.download
}];
exports.defaultToolbars = defaultToolbars;

function deleteToolbarFromKey(toolbars, keys) {
  var targetToolbar = toolbars.filter(function (item) {
    return keys.indexOf(item.key) < 0;
  });
  return targetToolbar;
}

var ViewerToolbar =
/*#__PURE__*/
function (_React$Component) {
  _inherits(ViewerToolbar, _React$Component);

  function ViewerToolbar() {
    var _this;

    _classCallCheck(this, ViewerToolbar);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(ViewerToolbar).call(this));

    _this.renderAction = function (config) {
      var content = null; // default toolbar

      if (typeof _Icon.ActionType[config.actionType] !== 'undefined') {
        content = React.createElement(_Icon["default"], {
          type: config.key
        });
      } // extra toolbar


      if (config.render) {
        content = config.render;
      }

      return React.createElement("li", {
        key: config.key,
        className: "".concat(_this.props.prefixCls, "-btn"),
        onClick: function onClick() {
          _this.handleAction(config);
        },
        "data-key": config.key
      }, content);
    };

    return _this;
  }

  _createClass(ViewerToolbar, [{
    key: "handleAction",
    value: function handleAction(config) {
      this.props.onAction(config);
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      // let attributeNode = this.props.attribute ? (
      //     <p className={`${this.props.prefixCls}-attribute`}>
      //         {this.props.alt && `${this.props.alt}`}
      //         {this.props.noImgDetails || <span className={`${this.props.prefixCls}-img-details`}>
      //             {`(${this.props.width} x ${this.props.height})`}
      //         </span>}
      //     </p>
      // ) : null;
      var toolbars = this.props.toolbars;

      if (!this.props.zoomable) {
        toolbars = deleteToolbarFromKey(toolbars, ['zoomIn', 'zoomOut']);
      }

      if (!this.props.changeable) {
        toolbars = deleteToolbarFromKey(toolbars, ['prev', 'next']);
      }

      if (!this.props.rotatable) {
        toolbars = deleteToolbarFromKey(toolbars, ['rotateLeft', 'rotateRight']);
      }

      if (!this.props.scalable) {
        toolbars = deleteToolbarFromKey(toolbars, ['scaleX', 'scaleY']);
      }

      if (!this.props.downloadable) {
        toolbars = deleteToolbarFromKey(toolbars, ['download']);
      }

      return React.createElement("div", {
        className: "".concat(this.props.prefixCls, "-header")
      }, React.createElement("ul", {
        className: "".concat(this.props.prefixCls, "-toolbar")
      }, toolbars.map(function (item) {
        return _this2.renderAction(item);
      })));
    }
  }]);

  return ViewerToolbar;
}(React.Component);

exports["default"] = ViewerToolbar;