"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 = exports.PageHeaderProps = void 0;

var _vue = _interopRequireWildcard(require("vue"));

var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));

var _propsUtil = require("../_util/props-util");

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

var _ArrowLeftOutlined = _interopRequireDefault(require("@ant-design/icons-vue/ArrowLeftOutlined"));

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

var _avatar = _interopRequireDefault(require("../avatar"));

var _transButton = _interopRequireDefault(require("../_util/transButton"));

var _LocaleReceiver = _interopRequireDefault(require("../locale-provider/LocaleReceiver"));

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 PageHeaderProps = {
  backIcon: _vueTypes.default.any,
  prefixCls: _vueTypes.default.string,
  title: _vueTypes.default.any,
  subTitle: _vueTypes.default.any,
  breadcrumb: _vueTypes.default.object,
  tags: _vueTypes.default.any,
  footer: _vueTypes.default.any,
  extra: _vueTypes.default.any,
  avatar: _vueTypes.default.object,
  ghost: _vueTypes.default.bool,
  onBack: _vueTypes.default.func
};
exports.PageHeaderProps = PageHeaderProps;

var renderBack = function renderBack(instance, prefixCls, backIcon, onBack) {
  if (!backIcon || !onBack) {
    return null;
  }

  return _vue.createVNode(_LocaleReceiver.default, {
    "componentName": "PageHeader",
    "children": function children(_ref) {
      var back = _ref.back;
      return _vue.createVNode("div", {
        "class": "".concat(prefixCls, "-back")
      }, [_vue.createVNode(_transButton.default, {
        "onClick": function onClick(e) {
          instance.$emit('back', e);
        },
        "class": "".concat(prefixCls, "-back-button"),
        "aria-label": back
      }, {
        default: function _default() {
          return [backIcon];
        }
      })]);
    }
  }, null);
};

var renderBreadcrumb = function renderBreadcrumb(breadcrumb) {
  return _vue.createVNode(_breadcrumb.default, breadcrumb, null);
};

var renderTitle = function renderTitle(prefixCls, instance) {
  var avatar = instance.avatar;
  var title = (0, _propsUtil.getComponent)(instance, 'title');
  var subTitle = (0, _propsUtil.getComponent)(instance, 'subTitle');
  var tags = (0, _propsUtil.getComponent)(instance, 'tags');
  var extra = (0, _propsUtil.getComponent)(instance, 'extra');
  var backIcon = (0, _propsUtil.getComponent)(instance, 'backIcon') !== undefined ? (0, _propsUtil.getComponent)(instance, 'backIcon') : _vue.createVNode(_ArrowLeftOutlined.default, null, null);
  var onBack = instance.onBack;
  var headingPrefixCls = "".concat(prefixCls, "-heading");

  if (title || subTitle || tags || extra) {
    var backIconDom = renderBack(instance, prefixCls, backIcon, onBack);
    return _vue.createVNode("div", {
      "class": headingPrefixCls
    }, [backIconDom, avatar && _vue.createVNode(_avatar.default, avatar, null), title && _vue.createVNode("span", {
      "class": "".concat(headingPrefixCls, "-title")
    }, [title]), subTitle && _vue.createVNode("span", {
      "class": "".concat(headingPrefixCls, "-sub-title")
    }, [subTitle]), tags && _vue.createVNode("span", {
      "class": "".concat(headingPrefixCls, "-tags")
    }, [tags]), extra && _vue.createVNode("span", {
      "class": "".concat(headingPrefixCls, "-extra")
    }, [extra])]);
  }

  return null;
};

var renderFooter = function renderFooter(prefixCls, footer) {
  if (footer) {
    return _vue.createVNode("div", {
      "class": "".concat(prefixCls, "-footer")
    }, [footer]);
  }

  return null;
};

var renderChildren = function renderChildren(prefixCls, children) {
  return _vue.createVNode("div", {
    "class": "".concat(prefixCls, "-content")
  }, [children]);
};

var PageHeader = {
  name: 'APageHeader',
  props: PageHeaderProps,
  setup: function setup() {
    return {
      configProvider: (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps)
    };
  },
  render: function render() {
    var _this$configProvider = this.configProvider,
        getPrefixCls = _this$configProvider.getPrefixCls,
        pageHeader = _this$configProvider.pageHeader;
    var props = (0, _propsUtil.getOptionProps)(this);
    var customizePrefixCls = props.prefixCls,
        breadcrumb = props.breadcrumb;
    var footer = (0, _propsUtil.getComponent)(this, 'footer');
    var children = (0, _propsUtil.getSlot)(this);
    var ghost = true; // Use `ghost` from `props` or from `ConfigProvider` instead.

    if ('ghost' in props) {
      ghost = props.ghost;
    } else if (pageHeader && 'ghost' in pageHeader) {
      ghost = pageHeader.ghost;
    }

    var prefixCls = getPrefixCls('page-header', customizePrefixCls);
    var breadcrumbDom = breadcrumb && breadcrumb.routes ? renderBreadcrumb(breadcrumb) : null;
    var className = [prefixCls, _defineProperty({
      'has-breadcrumb': breadcrumbDom,
      'has-footer': footer
    }, "".concat(prefixCls, "-ghost"), ghost)];
    return _vue.createVNode("div", {
      "class": className
    }, [breadcrumbDom, renderTitle(prefixCls, this), children.length ? renderChildren(prefixCls, children) : null, renderFooter(prefixCls, footer)]);
  }
};
/* istanbul ignore next */

PageHeader.install = function (app) {
  app.component(PageHeader.name, PageHeader);
};

var _default2 = PageHeader;
exports.default = _default2;