<template>
  <div :class="{ 'tf-title': true, 'tf-title--collapse': isCollapse !== undefined }" @click="isCollapse = !isCollapse">
    <div :class="{ content: true, 'content--bold': isBold }"><slot /></div>
    <div class="append"><slot name="append" /></div>
    <i
      v-if="isCollapse !== undefined"
      :class="{ icon: true, 'el-icon-arrow-up': true, 'icon--down': isCollapse === false }"
    />
  </div>
</template>
<script lang="ts">
  import { Vue, Component, Prop, PropSync } from 'vue-property-decorator'

  @Component({ name: 'TfTitle' })
  export default class TfTitle extends Vue {
    @Prop({ type: Boolean, default: true }) isBold!: boolean
    @PropSync('collapse', { type: Boolean, default: undefined }) isCollapse!: boolean
  }
</script>

<style lang="scss" scoped>
  .tf-title {
    padding: 4px 0 4px 14px;
    margin-bottom: $gutter;
    font-size: $--font-size-medium;
    position: relative;
    text-transform: capitalize;
    display: flex;
    align-items: center;
    justify-content: space-between;
    &--top {
      align-items: center;
    }

    &::before {
      content: '';
      display: block;
      width: 4px;
      height: $--font-size-medium;
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      background-color: $--color-primary;
    }
    &--collapse {
      padding: 10px $--font-size-medium 10px $--font-size-medium * 2;
      background-color: rgba($--color-primary, 0.16);
      cursor: pointer;
      line-height: 1.25;
      &::before {
        left: $--font-size-medium;
      }
    }
    .content {
      flex: 1 1 auto;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
      font-weight: 600;
      display: flex;
      align-items: center;
    }
    .append {
      flex: 0 0 auto;
    }
    a {
      user-select: none;
      &:hover {
        color: $--color-primary;
      }
    }
    .icon {
      flex: 0 0 auto;
      color: $--color-primary;
      font-size: $--font-size-medium;
      transform: rotate(0);
      transition: transform ease 300ms;
      &--down {
        transform: rotate(180deg);
      }
    }
  }
</style>
