"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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"));

// Copyright 1999-2019. 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)("".concat(baseClassName, "__button"), "".concat(baseClassName, "__button--back")),
      size: "lg",
      icon: /*#__PURE__*/_react.default.createElement(_Icon.default, {
        name: "chevron-left",
        flipHorizontal: this.isRtl,
        className: "".concat(baseClassName, "__icon")
      }),
      onClick: onClose
    });
  }

  renderHideButton() {
    const {
      baseClassName,
      onClose
    } = this.props;
    return /*#__PURE__*/_react.default.createElement(_Button.default, {
      ghost: true,
      className: (0, _classnames.default)("".concat(baseClassName, "__button"), "".concat(baseClassName, "__button--hide")),
      size: "lg",
      icon: /*#__PURE__*/_react.default.createElement(_Icon.default, {
        className: "".concat(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)("".concat(baseClassName, "__button"), "".concat(baseClassName, "__button--close")),
      size: "lg",
      icon: /*#__PURE__*/_react.default.createElement(_Icon.default, {
        name: 'cross-mark',
        className: "".concat(baseClassName, "__icon")
      }),
      onClick: onClose,
      disabled: disabled
    });
  }

  render() {
    const {
      baseClassName,
      onClose,
      children,
      backButton,
      hideButton,
      ...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: "".concat(baseClassName, "__actions")
          }, this.renderHideButton(), this.renderCloseButton({
            disabled: true
          }));
          break;

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

    return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
      className: baseClassName
    }, props), /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(baseClassName, "__inner")
    }, prefix, /*#__PURE__*/_react.default.createElement("div", {
      className: "".concat(baseClassName, "__content")
    }, children), 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
});
(0, _defineProperty2.default)(Header, "defaultProps", {
  onClose: null,
  baseClassName: "".concat(_constants.CLS_PREFIX, "drawer-header"),
  backButton: false,
  hideButton: false
});