<template>
  <section class="AiTitle" :class="{ 'bottomBorder': isShowBottomBorder, AiTitleSub: isHasSub}">
    <i class="iconfont iconBack_Large" v-if="isShowBack" @click="onBackBtnClick"/>
    <div class="fill">
      <div class="ailist-title">
        <div class="ailist-title__left">
          <h2>{{ title }}</h2>
          <p>{{ tips }}</p>
        </div>
        <div class="ailist-title__right">
          <div class="aititle-right__btns">
            <slot name="rightBtn"/>
          </div>
        </div>
      </div>
      <div class="subtitle" v-if="$scopedSlots.sub">
        <slot name="sub"/>
      </div>
    </div>
  </section>
</template>

<script>
  export default {
    name: 'AiTitle',
    model: {
      prop: 'value',
      event: 'change'
    },
    props: {
      title: {
        type: String,
        required: true
      },
      tips: {
        type: String
      },
      instance: {
        type: Function
      },
      value: {
        type: String
      },
      isShowBack: {
        type: Boolean,
        default: false
      },
      isShowBottomBorder: {
        type: Boolean,
        default: false
      }
    },

    computed: {
      isHasSub() {
        return this.$slots.sub
      }
    },

    methods: {
      onBackBtnClick() {
        this.closePage()
        this.$emit('onBackClick')
        this.$emit('back')
      }
    }
  }
</script>

<style scoped lang="scss">
  .AiTitle {
    display: flex;

    .ailist-title {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 48px;

      .ailist-title__left {
        display: flex;
        align-items: center;

        p {
          margin-left: 20px;
          font-size: 14px;
          color: #FA5555;
        }

        & > i {
          width: auto;
          height: auto;
          margin-right: 8px;
          font-size: 16px;
        }

        h2 {
          color: #222;
          font-size: 16px;
          font-weight: 600;
        }
      }

      .ailist-title__right {
        display: flex;
        align-items: center;
      }

      :deep(.el-button ) {
        margin-left: 8px !important;
      }
    }

    &.AiTitleSub {
      height: auto;
      padding: 16px 0;

      .ailist-title {
        height: auto;
        margin-bottom: 3px;
      }
    }

    &.bottomBorder {
      border-bottom: 1px solid #D8DCE3;
    }

    .subtitle {
      width: 100%;
      color: #888888;
      font-size: 12px;
      margin-top: 4px;
    }

    .iconBack_Large {
      line-height: 48px;
      margin-right: 8px;
    }
  }
</style>
