import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
// Copyright 1999-2019. Plesk International GmbH. All rights reserved.
import { isRtl } from '../../utils';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { CLS_PREFIX } from '../../constants';
import Button from '../Button';
import Icon from '../Icon';
export default class Header extends Component {
  componentDidMount() {
    this.isRtl = isRtl();
  }

  renderBackButton() {
    const {
      baseClassName,
      onClose
    } = this.props;
    return /*#__PURE__*/React.createElement(Button, {
      ghost: true,
      className: classNames("".concat(baseClassName, "__button"), "".concat(baseClassName, "__button--back")),
      size: "lg",
      icon: /*#__PURE__*/React.createElement(Icon, {
        name: "chevron-left",
        flipHorizontal: this.isRtl,
        className: "".concat(baseClassName, "__icon")
      }),
      onClick: onClose
    });
  }

  renderHideButton() {
    const {
      baseClassName,
      onClose
    } = this.props;
    return /*#__PURE__*/React.createElement(Button, {
      ghost: true,
      className: classNames("".concat(baseClassName, "__button"), "".concat(baseClassName, "__button--hide")),
      size: "lg",
      icon: /*#__PURE__*/React.createElement(Icon, {
        className: "".concat(baseClassName, "__icon"),
        name: "minimize"
      }),
      onClick: onClose
    });
  }

  renderCloseButton({
    disabled = false
  } = {}) {
    const {
      baseClassName,
      onClose
    } = this.props;
    return /*#__PURE__*/React.createElement(Button, {
      ghost: true,
      className: classNames("".concat(baseClassName, "__button"), "".concat(baseClassName, "__button--close")),
      size: "lg",
      icon: /*#__PURE__*/React.createElement(Icon, {
        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.createElement("div", {
            className: "".concat(baseClassName, "__actions")
          }, this.renderHideButton(), this.renderCloseButton({
            disabled: true
          }));
          break;

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

    return /*#__PURE__*/React.createElement("div", _extends({
      className: baseClassName
    }, props), /*#__PURE__*/React.createElement("div", {
      className: "".concat(baseClassName, "__inner")
    }, prefix, /*#__PURE__*/React.createElement("div", {
      className: "".concat(baseClassName, "__content")
    }, children), suffix));
  }

}

_defineProperty(Header, "propTypes", {
  baseClassName: PropTypes.string,
  onClose: PropTypes.func,
  children: PropTypes.node.isRequired,
  backButton: PropTypes.bool,
  hideButton: PropTypes.bool
});

_defineProperty(Header, "defaultProps", {
  onClose: null,
  baseClassName: "".concat(CLS_PREFIX, "drawer-header"),
  backButton: false,
  hideButton: false
});