<template>
  <el-header
    :height="headerHeight"
    class="custom-title-header"
    :class="{'has-height': headerHeight}"
  >
    <h4
      class="custom-title"
      :style="{
        '--titleColor': titleColor,
        '--titleFontSize': titleFontSize,
        '--borderColor': borderColor,
        '--borderHeight': borderHeight
      }"
    >
      {{ title }}
    </h4>
    <div class="header-right__wrap" v-if="isShowOperateBtn">
      <el-button
        type="text"
        v-for="(btn, index) in buttonList"
        :key="index"
        :icon="btn.icon"
        :class="{'btn-icon': btn.icon, 'btn-value': btn.value}"
        @click="handleButton(btn)"
        >{{ btn[buttonValue] }}</el-button
      >
    </div>
  </el-header>
</template>

<script>
export default {
  name: 'CustomTitle',
  props: {
    title: {
      type: String,
      default: '基本信息'
    },
    titleColor: {
      type: String,
      default: '#333'
    },
    borderColor: {
      type: String,
      default: '#409EFF'
    },
    titleFontSize: {
      type: String,
      default: '16px'
    },
    borderHeight: {
      type: String,
      default: '16px'
    },
    headerHeight: {
      type: String,
      default: ''
    },
    isShowOperateBtn: {
      type: Boolean,
      default: false
    },
    buttonList: {
      type: Array,
      default: () => {
        return [
          {key: 'refresh', value: '', icon: 'el-icon-refresh-right'},
          {key: 'delete', value: '', icon: 'el-icon-close'}
        ]
      }
    },
    //按钮显示名称和key
    buttonConfig: {
      type: Object,
      default: () => {
        return {
          key: 'key',
          value: 'value'
        }
      }
    }
  },
  computed: {
    buttonKey() {
      return this.buttonConfig.key
    },
    buttonValue() {
      return this.buttonConfig.value
    }
  },
  methods: {
    handleButton(btn) {
      this.$emit('click-button', btn)
    }
  }
}
</script>

<style lang="scss" scoped>
.custom-title-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0;
  .header-right__wrap {
    .btn-icon {
      font-size: 16px;
      color: #666;
      font-weight: bold;
    }
    .btn-value {
      color: #999;
    }
  }
}
.has-height {
  padding: 0 24px;
  border-bottom: 1px solid #eee;
  .custom-title {
    margin: 0;
  }
}
.custom-title {
  color: var(--titleColor);
  font-size: var(--titleFontSize);
  font-weight: bold;
  position: relative;
  padding-left: 12px;
  margin: 24px 0;
  &::before {
    position: absolute;
    content: '';
    width: 4px;
    height: var(--borderHeight);
    background: var(--borderColor);
    top: 4px;
    left: 0;
  }
}
</style>
