import React, { useMemo } from 'react';
import { isFunction } from '@pisell/utils';
import PageHeader from "../../page-header";
import Buttons from "./Buttons";
import "./index.less";
var Header = function Header(_ref) {
  var buttons = _ref.buttons,
    title = _ref.title,
    subTitle = _ref.subTitle,
    showTitle = _ref.showTitle,
    showSubTitle = _ref.showSubTitle;
  var showHeader = useMemo(function () {
    return title && showTitle || (Array.isArray(buttons) ? buttons.length > 0 : buttons) || subTitle && showSubTitle;
  }, [buttons, title, subTitle, showTitle, showSubTitle]);
  var titleNode = useMemo(function () {
    if (isFunction(title)) {
      return title();
    }
    return title;
  }, [title]);
  var buttonsNode = useMemo(function () {
    if (Array.isArray(buttons)) {
      return /*#__PURE__*/React.createElement(Buttons, {
        list: buttons
      });
    }
    return buttons;
  }, [buttons]);
  var subTitleNode = useMemo(function () {
    if (isFunction(subTitle)) {
      return subTitle();
    }
    return subTitle;
  }, [subTitle]);
  return showHeader ? /*#__PURE__*/React.createElement(PageHeader, {
    title: titleNode,
    showTitle: showTitle,
    subTitle: subTitleNode,
    showSubTitle: showSubTitle,
    extra: buttonsNode
  }) : null;
};
export default Header;