"use strict";

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

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

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

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

var _utils = require("../../utils");

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

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

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

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

var _Button = _interopRequireDefault(require("../Button"));

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }

// Copyright 1999-2021. Plesk International GmbH. All rights reserved.
class Header extends _react.Component {
  componentDidMount() {
    this.isRtl = (0, _utils.isRtl)();
  }

  renderBackButton() {
    const {
      baseClassName,
      onClose
    } = this.props;
    return /*#__PURE__*/_react.default.createElement(_Button.default, {
      ghost: true,
      className: (0, _classnames.default)(`${baseClassName}__button`, `${baseClassName}__button--back`),
      size: "lg",
      icon: /*#__PURE__*/_react.default.createElement(_Icon.default, {
        name: "chevron-left",
        flipHorizontal: this.isRtl,
        className: `${baseClassName}__icon`
      }),
      onClick: onClose
    });
  }

  renderHideButton() {
    const {
      baseClassName,
      onClose
    } = this.props;
    return /*#__PURE__*/_react.default.createElement(_Button.default, {
      ghost: true,
      className: (0, _classnames.default)(`${baseClassName}__button`, `${baseClassName}__button--hide`),
      size: "lg",
      icon: /*#__PURE__*/_react.default.createElement(_Icon.default, {
        className: `${baseClassName}__icon`,
        name: "minimize"
      }),
      onClick: onClose
    });
  }

  renderCloseButton({
    disabled = false
  } = {}) {
    const {
      baseClassName,
      onClose
    } = this.props;
    return /*#__PURE__*/_react.default.createElement(_Button.default, {
      ghost: true,
      className: (0, _classnames.default)(`${baseClassName}__button`, `${baseClassName}__button--close`),
      size: "lg",
      icon: /*#__PURE__*/_react.default.createElement(_Icon.default, {
        name: 'cross-mark',
        className: `${baseClassName}__icon`
      }),
      onClick: onClose,
      disabled: disabled
    });
  }

  render() {
    const {
      baseClassName,
      onClose,
      children,
      backButton,
      hideButton,
      tabs,
      ...props
    } = this.props;
    let prefix;
    let suffix;

    if (onClose) {
      switch (true) {
        case backButton:
          prefix = this.renderBackButton();
          break;

        case hideButton:
          suffix = /*#__PURE__*/_react.default.createElement("div", {
            className: `${baseClassName}__actions`
          }, this.renderHideButton(), this.renderCloseButton({
            disabled: true
          }));
          break;

        default:
          suffix = /*#__PURE__*/_react.default.createElement("div", {
            className: `${baseClassName}__actions`
          }, this.renderCloseButton());
          break;
      }
    }

    return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
      className: baseClassName
    }, props), /*#__PURE__*/_react.default.createElement("div", {
      className: `${baseClassName}__inner`
    }, prefix, /*#__PURE__*/_react.default.createElement("div", {
      className: `${baseClassName}__content`
    }, children, tabs && /*#__PURE__*/_react.default.createElement("div", {
      className: `${baseClassName}__tabs`
    }, /*#__PURE__*/_react.default.createElement("div", {
      className: `${baseClassName}__tabs-inner`
    }, tabs))), suffix));
  }

}

exports.default = Header;
(0, _defineProperty2.default)(Header, "propTypes", {
  baseClassName: _propTypes.default.string,
  onClose: _propTypes.default.func,
  children: _propTypes.default.node.isRequired,
  backButton: _propTypes.default.bool,
  hideButton: _propTypes.default.bool,
  tabs: _propTypes.default.node
});
(0, _defineProperty2.default)(Header, "defaultProps", {
  onClose: null,
  baseClassName: `${_constants.CLS_PREFIX}drawer-header`,
  backButton: false,
  hideButton: false,
  tabs: undefined
});