"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var React = _interopRequireWildcard(require("react"));

var _configProvider = require("../config-provider");

var _icon = _interopRequireDefault(require("../icon"));

var _classnames2 = _interopRequireDefault(require("classnames"));

var _divider = _interopRequireDefault(require("../divider"));

var _breadcrumb = _interopRequireDefault(require("../breadcrumb"));

var _wave = _interopRequireDefault(require("../_util/wave"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var renderBack = function renderBack(prefixCls, backIcon, onBack) {
  return null;

  if (!backIcon || !onBack) {
    return null;
  }

  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-back-icon"),
    onClick: function onClick(e) {
      if (onBack) {
        onBack(e);
      }
    }
  }, /*#__PURE__*/React.createElement(_wave["default"], null, backIcon), /*#__PURE__*/React.createElement(_divider["default"], {
    type: "vertical"
  }));
};

var renderBreadcrumb = function renderBreadcrumb(breadcrumb) {
  return /*#__PURE__*/React.createElement(_breadcrumb["default"], breadcrumb);
};

var renderHeader = function renderHeader(prefixCls, props) {
  var breadcrumb = props.breadcrumb,
      backIcon = props.backIcon,
      onBack = props.onBack;

  if (breadcrumb && breadcrumb.routes && breadcrumb.routes.length > 2) {
    return renderBreadcrumb(breadcrumb);
  }

  return renderBack(prefixCls, backIcon, onBack);
}; // remove
// {tags && <span className={`${titlePrefixCls}-tags`}>{tags}</span>}
// {extra && <span className={`${titlePrefixCls}-extra`}>{extra}</span>}


var renderTitle = function renderTitle(prefixCls, props) {
  // tags,  extra
  var title = props.title,
      subTitle = props.subTitle;
  var titlePrefixCls = "".concat(prefixCls, "-title-view");
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-title-view")
  }, /*#__PURE__*/React.createElement("h1", {
    className: "".concat(titlePrefixCls, "-title")
  }, title), subTitle && /*#__PURE__*/React.createElement("span", {
    className: "".concat(titlePrefixCls, "-sub-title")
  }, subTitle));
};

var renderFooter = function renderFooter(prefixCls, footer) {
  if (footer) {
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-footer")
    }, footer);
  }

  return null;
};

var PageHeader = function PageHeader(props) {
  return /*#__PURE__*/React.createElement(_configProvider.ConfigConsumer, null, function (_ref) {
    var getPrefixCls = _ref.getPrefixCls;
    var customizePrefixCls = props.prefixCls,
        style = props.style,
        footer = props.footer,
        children = props.children,
        customizeClassName = props.className;
    var prefixCls = getPrefixCls('page-header', customizePrefixCls);
    var className = (0, _classnames2["default"])(prefixCls, _defineProperty({}, "".concat(prefixCls, "-has-footer"), footer), customizeClassName);
    return /*#__PURE__*/React.createElement("div", {
      className: className,
      style: style
    }, renderHeader(prefixCls, props), renderTitle(prefixCls, props), children && /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-content-view")
    }, children), renderFooter(prefixCls, footer));
  });
};

PageHeader.defaultProps = {
  backIcon: /*#__PURE__*/React.createElement(_icon["default"], {
    type: "arrow-left"
  })
};
var _default = PageHeader;
exports["default"] = _default;