// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

import { isRtl } from '../../utils';
import classNames from 'classnames';
import { CLS_PREFIX } from '../../constants';
import Button from '../Button';
import Icon from '../Icon';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
const Header = _ref => {
  let {
    baseClassName = `${CLS_PREFIX}drawer-header`,
    onClose,
    children,
    backButton = false,
    hideButton = false,
    tabs,
    ...props
  } = _ref;
  const renderBackButton = () => /*#__PURE__*/_jsx(Button, {
    ghost: true,
    className: classNames(`${baseClassName}__button`, `${baseClassName}__button--back`),
    size: "lg",
    icon: /*#__PURE__*/_jsx(Icon, {
      name: "chevron-left",
      flipHorizontal: isRtl(),
      className: `${baseClassName}__icon`
    }),
    onClick: onClose
  });
  const renderHideButton = () => /*#__PURE__*/_jsx(Button, {
    ghost: true,
    className: classNames(`${baseClassName}__button`, `${baseClassName}__button--hide`),
    size: "lg",
    icon: /*#__PURE__*/_jsx(Icon, {
      className: `${baseClassName}__icon`,
      name: "minimize"
    }),
    onClick: onClose
  });
  const renderCloseButton = function () {
    let {
      disabled = false
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    return /*#__PURE__*/_jsx(Button, {
      ghost: true,
      className: classNames(`${baseClassName}__button`, `${baseClassName}__button--close`),
      size: "lg",
      icon: /*#__PURE__*/_jsx(Icon, {
        name: "cross-mark",
        className: `${baseClassName}__icon`
      }),
      onClick: onClose,
      disabled: disabled
    });
  };
  let prefix;
  let suffix;
  if (onClose) {
    if (backButton) {
      prefix = renderBackButton();
    } else if (hideButton) {
      suffix = /*#__PURE__*/_jsxs("div", {
        className: `${baseClassName}__actions`,
        children: [renderHideButton(), renderCloseButton({
          disabled: true
        })]
      });
    } else {
      suffix = /*#__PURE__*/_jsx("div", {
        className: `${baseClassName}__actions`,
        children: renderCloseButton()
      });
    }
  }
  return /*#__PURE__*/_jsx("div", {
    className: baseClassName,
    ...props,
    children: /*#__PURE__*/_jsxs("div", {
      className: `${baseClassName}__inner`,
      children: [prefix, /*#__PURE__*/_jsxs("div", {
        className: `${baseClassName}__content`,
        children: [children, tabs && /*#__PURE__*/_jsx("div", {
          className: `${baseClassName}__tabs`,
          children: /*#__PURE__*/_jsx("div", {
            className: `${baseClassName}__tabs-inner`,
            children: tabs
          })
        })]
      }), suffix]
    })
  });
};
export default Header;