import * as _vue from "vue";

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; }

import { inject } from 'vue';
import PropTypes from '../_util/vue-types';
import { getComponent, getOptionProps, getSlot } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
import ArrowLeftOutlined from '@ant-design/icons-vue/ArrowLeftOutlined';
import Breadcrumb from '../breadcrumb';
import Avatar from '../avatar';
import TransButton from '../_util/transButton';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
export var PageHeaderProps = {
  backIcon: PropTypes.any,
  prefixCls: PropTypes.string,
  title: PropTypes.any,
  subTitle: PropTypes.any,
  breadcrumb: PropTypes.object,
  tags: PropTypes.any,
  footer: PropTypes.any,
  extra: PropTypes.any,
  avatar: PropTypes.object,
  ghost: PropTypes.bool,
  onBack: PropTypes.func
};

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

  return _vue.createVNode(LocaleReceiver, {
    "componentName": "PageHeader",
    "children": function children(_ref) {
      var back = _ref.back;
      return _vue.createVNode("div", {
        "class": "".concat(prefixCls, "-back")
      }, [_vue.createVNode(TransButton, {
        "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, breadcrumb, null);
};

var renderTitle = function renderTitle(prefixCls, instance) {
  var avatar = instance.avatar;
  var title = getComponent(instance, 'title');
  var subTitle = getComponent(instance, 'subTitle');
  var tags = getComponent(instance, 'tags');
  var extra = getComponent(instance, 'extra');
  var backIcon = getComponent(instance, 'backIcon') !== undefined ? getComponent(instance, 'backIcon') : _vue.createVNode(ArrowLeftOutlined, 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, 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: inject('configProvider', ConfigConsumerProps)
    };
  },
  render: function render() {
    var _this$configProvider = this.configProvider,
        getPrefixCls = _this$configProvider.getPrefixCls,
        pageHeader = _this$configProvider.pageHeader;
    var props = getOptionProps(this);
    var customizePrefixCls = props.prefixCls,
        breadcrumb = props.breadcrumb;
    var footer = getComponent(this, 'footer');
    var children = 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);
};

export default PageHeader;