"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _utils = require("../../utils");
var _classnames = _interopRequireDefault(require("classnames"));
var _constants = require("../../constants");
var _Button = _interopRequireDefault(require("../Button"));
var _Icon = _interopRequireDefault(require("../Icon"));
var _jsxRuntime = require("react/jsx-runtime");
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

const Header = _ref => {
  let {
    baseClassName = `${_constants.CLS_PREFIX}drawer-header`,
    onClose,
    children,
    backButton = false,
    hideButton = false,
    tabs,
    ...props
  } = _ref;
  const renderBackButton = () => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
    ghost: true,
    className: (0, _classnames.default)(`${baseClassName}__button`, `${baseClassName}__button--back`),
    size: "lg",
    icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
      name: "chevron-left",
      flipHorizontal: (0, _utils.isRtl)(),
      className: `${baseClassName}__icon`
    }),
    onClick: onClose
  });
  const renderHideButton = () => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
    ghost: true,
    className: (0, _classnames.default)(`${baseClassName}__button`, `${baseClassName}__button--hide`),
    size: "lg",
    icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
      className: `${baseClassName}__icon`,
      name: "minimize"
    }),
    onClick: onClose
  });
  const renderCloseButton = function () {
    let {
      disabled = false
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
      ghost: true,
      className: (0, _classnames.default)(`${baseClassName}__button`, `${baseClassName}__button--close`),
      size: "lg",
      icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
        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__*/(0, _jsxRuntime.jsxs)("div", {
        className: `${baseClassName}__actions`,
        children: [renderHideButton(), renderCloseButton({
          disabled: true
        })]
      });
    } else {
      suffix = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: `${baseClassName}__actions`,
        children: renderCloseButton()
      });
    }
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: baseClassName,
    ...props,
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: `${baseClassName}__inner`,
      children: [prefix, /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: `${baseClassName}__content`,
        children: [children, tabs && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: `${baseClassName}__tabs`,
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
            className: `${baseClassName}__tabs-inner`,
            children: tabs
          })
        })]
      }), suffix]
    })
  });
};
var _default = exports.default = Header;