<template>
  <div :class="{'rt-detail-header-wrapper':!noBackgroundImage}">
    <div class="detail-header-content">
      <div class="content-top">
        <div v-if="hasAvatar" class="content-top--left">
          <slot name="avatar"></slot>
        </div>
        <div class="content-top--right">
          <div class="content-title-wrapper">
            <slot name="tag" />
            <slot name="title">
              <span v-if="!biggerTitle" class="title-text">{{title}}</span>
              <span v-else class="bigger-title-text">{{title}}</span>
            </slot>
            <slot name="rightTag" />
          </div>
          <div class="content-subtitle-wrapper" :class="labelNewLine?'label-new-line':''">
            <slot name="subtitle">
              <span class="subtitle-text">{{subtitle}}</span>
              <span v-if="label" class="subtitle-label">{{label}}</span>
            </slot>
          </div>
        </div>
      </div>
      <div class="content-bottom">
        <slot />
      </div>
      <div v-if="hasStatus" class="content-status">
        <slot name="status" />
      </div>
      <div v-if="hasExtra" class="content-extra">
        <slot name="extra" />
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'rtDetailHeader',
  props: {
    title: String,
    subtitle: String,
    label: String,
    biggerTitle: {
      type: Boolean,
      default: false
    },
    noBackgroundImage: {
      type: Boolean,
      default: false
    },
    // 是否以行的形式全部显示, 文字过长换行显示
    labelNewLine: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    hasAvatar() {
      return this.$slots.avatar;
    },
    hasStatus() {
      return this.$slots.status;
    },
    hasExtra() {
      return this.$slots.extra;
    }
  }
};
</script>
<style lang="less">
.rt-detail-header-wrapper {
  width: 100%;
  background: url('../../assets/imgs/rt_detail_header_bg.png') no-repeat;
  background-size: 100% 75%;
  padding-top: 25px;
  margin-bottom: 15px;
  .content-title-wrapper {
    padding: 6px 0 7px;
    display: flex;
    align-items: center;
    font-weight: 500;
    font-size: 15px;
    color: #222;
    line-height: 1.2;
    width: 82%;
  }
  .content-subtitle-wrapper {
    align-items: center;
    font-weight: 400;
    font-size: 13px;
    color: #888;
    .subtitle-label {
      padding: 2px 8px;
      background: linear-gradient(-13deg, #53a4fc, #53c6fc);
      border-radius: 1px 5px 5px 5px;
      font-size: 11px;
      color: #ffffff;
      margin-left: 5px;
    }
    &.label-new-line {
      display: inline;
      white-space: normal;
      word-break: break-all;
      .subtitle-label {
        display: inline-block;
        width: fit-content;
      }
    }
    &:not(.label-new-line) {
      display: flex;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      .subtitle-text {
        display: inline;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .subtitle-label {
        display: inline;
      }
    }
  }
  .title-text {
    font-size: 16px;
  }
  .bigger-title-text {
    font-size: 32px;
  }
  .detail-header-content {
    position: relative;
    background: #fff;
    border-radius: 5px;
    padding: 10px 10px 5px;
    margin: 0 10px;
    box-shadow: 0px 1px 5px 1px rgba(167, 210, 255, 0.15);
    .content-top {
      margin-bottom: 25px;
      display: flex;
      .content-top--left {
        flex: 1;
      }
      .content-top--right {
        flex: 5;
        text-align: left;
      }
    }
    .content-bottom {
      position: relative;
    }
    .content-status {
      position: absolute;
      right: -4px;
      top: 16px;
    }
  }
  .rt-attr__text--primary {
    color: #222;
  }
}
</style>

