"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _search = _interopRequireDefault(require("@alifd/next/lib/search"));
var _pagination = _interopRequireDefault(require("@alifd/next/lib/pagination"));
var _icon = _interopRequireDefault(require("@alifd/next/lib/icon"));
var _button = _interopRequireDefault(require("@alifd/next/lib/button"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _react = _interopRequireDefault(require("react"));
var _classnames2 = _interopRequireDefault(require("classnames"));
var _webRowOrder = _interopRequireDefault(require("./webRowOrder"));
var _webLinkBar = _interopRequireDefault(require("./webLinkBar"));
var _excluded = ["isDisabled", "title", "type", "disabled", "callback"];
var WebToolbar = /*#__PURE__*/function (_React$Component) {
  (0, _inheritsLoose2["default"])(WebToolbar, _React$Component);
  function WebToolbar() {
    return _React$Component.apply(this, arguments) || this;
  }
  var _proto = WebToolbar.prototype;
  _proto.render = function render() {
    var _classnames;
    var _this$props = this.props,
      nextTablePrefix = _this$props.nextTablePrefix,
      onSearch = _this$props.onSearch,
      onActionClick = _this$props.onActionClick,
      _this$props$locale = _this$props.locale,
      locale = _this$props$locale === void 0 ? {} : _this$props$locale,
      showActionBar = _this$props.showActionBar,
      actionBar = _this$props.actionBar,
      showLinkBar = _this$props.showLinkBar,
      linkBar = _this$props.linkBar,
      showSearch = _this$props.showSearch,
      searchBarPlaceholder = _this$props.searchBarPlaceholder,
      showCustomColumn = _this$props.showCustomColumn,
      onClickCustomColumn = _this$props.onClickCustomColumn,
      rowOrder = _this$props.rowOrder,
      customBarItem = _this$props.customBarItem,
      showMiniPager = _this$props.showMiniPager,
      paginationProps = _this$props.paginationProps,
      noPadding = _this$props.noPadding;
    var _ref = paginationProps || {},
      currentPage = _ref.currentPage,
      pageSize = _ref.pageSize,
      totalCount = _ref.totalCount,
      onChange = _ref.onChange,
      onPageSizeChange = _ref.onPageSizeChange;
    var renderCustomBarItem = !!(customBarItem && customBarItem.render);
    var renderCustomBarItemRight = !!(customBarItem && customBarItem.rightRender);
    var renderCustomBarItemBottom = !!(customBarItem && customBarItem.bottomRender);
    var renderActionBar = !!(showActionBar && actionBar && actionBar.length);
    var renderLeft = renderActionBar || renderCustomBarItem;
    var renderLinkBar = !!(showLinkBar && linkBar && linkBar.length);
    var renderRight = renderLinkBar || rowOrder || showCustomColumn || showMiniPager || showSearch || renderCustomBarItemRight;
    var renderToolbar = renderLeft || renderRight;
    if (!renderToolbar) {
      return null;
    }
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames2["default"])(nextTablePrefix + "web-toolbar", (_classnames = {}, _classnames[nextTablePrefix + "no-padding"] = noPadding, _classnames))
    }, renderLeft ? /*#__PURE__*/_react["default"].createElement("div", {
      className: nextTablePrefix + "left-wrap"
    }, renderActionBar ? actionBar.map(function (action, index) {
      var isDisabled = action.isDisabled,
        title = action.title,
        type = action.type,
        disabled = action.disabled,
        callback = action.callback,
        rest = (0, _objectWithoutPropertiesLoose2["default"])(action, _excluded);
      var buttonType = type ? type : index === 0 ? 'secondary' : 'normal';
      var disable = disabled !== undefined ? disabled : isDisabled ? !!isDisabled() : false;
      return /*#__PURE__*/_react["default"].createElement(_button["default"], (0, _extends2["default"])({}, rest, {
        className: nextTablePrefix + "button",
        type: buttonType,
        disabled: disable,
        key: buttonType + "-" + (disable ? "0" : "1") + "-" + index,
        onClick: function onClick() {
          onActionClick && onActionClick(action, index);
        }
      }), title);
    }) : null, renderCustomBarItem ? /*#__PURE__*/_react["default"].createElement("div", {
      className: nextTablePrefix + "custom"
    }, customBarItem.render()) : null) : null, renderRight ? /*#__PURE__*/_react["default"].createElement("div", {
      className: nextTablePrefix + "right-wrap"
    }, renderLinkBar ? /*#__PURE__*/_react["default"].createElement(_webLinkBar["default"], {
      nextTablePrefix: nextTablePrefix,
      linkBar: linkBar,
      onActionClick: onActionClick
    }) : null, rowOrder ? /*#__PURE__*/_react["default"].createElement(_webRowOrder["default"], (0, _extends2["default"])({}, rowOrder, {
      nextTablePrefix: nextTablePrefix
    })) : null, showCustomColumn ? /*#__PURE__*/_react["default"].createElement("div", {
      className: nextTablePrefix + "custom-column",
      onClick: onClickCustomColumn
    }, /*#__PURE__*/_react["default"].createElement(_icon["default"], {
      className: nextTablePrefix + "icon",
      type: "custom-column",
      size: "small"
    }), /*#__PURE__*/_react["default"].createElement("span", {
      className: nextTablePrefix + "text"
    }, locale.customColumn)) : null, showMiniPager ? /*#__PURE__*/_react["default"].createElement("div", {
      className: nextTablePrefix + "pagination"
    }, /*#__PURE__*/_react["default"].createElement(_pagination["default"], {
      current: currentPage,
      pageSize: pageSize,
      total: totalCount,
      onChange: onChange,
      onPageSizeChange: onPageSizeChange,
      type: "simple",
      size: "small",
      shape: "arrow-only"
    })) : null, showSearch ? /*#__PURE__*/_react["default"].createElement(_search["default"], {
      className: nextTablePrefix + "search",
      shape: "simple",
      hasClear: true,
      placeholder: searchBarPlaceholder,
      onSearch: onSearch
    }) : null, renderCustomBarItemRight ? /*#__PURE__*/_react["default"].createElement("div", {
      className: nextTablePrefix + "custom-right"
    }, customBarItem.rightRender()) : null) : null, /*#__PURE__*/_react["default"].createElement("div", {
      style: {
        clear: 'both'
      }
    }), renderCustomBarItemBottom ? /*#__PURE__*/_react["default"].createElement("div", {
      className: nextTablePrefix + "custom-bottom"
    }, customBarItem.bottomRender()) : null);
  };
  return WebToolbar;
}(_react["default"].Component);
exports["default"] = WebToolbar;