<template>
  <div class="analysis-box-wrapper" :style="{ width: width ? width : '100%', height: height ? height : '100%' }">
    <div class="wrapper-header">
      <div class="header-icon"></div>
      <div class="header-title">
        <div v-if="title">{{ title }}</div>
        <slot v-else name="custom-title"></slot>
      </div>
      <div class="header-btn" v-if="!showAllBtn">
        <slot name="header-btn"></slot>
      </div>
      <div class="header-btn1" v-else>
        <slot name="header-btn"></slot>
      </div>
      <div class="header-right">
        <div class="text-one" :class="{ 'is-active': activeView === 'consensus' }"
          @click="handleTabChange('consensus')">
          {{ "共识观点" }}
        </div>
        <div class="text-two" :class="{ 'is-active': activeView === 'divergence' }"
          @click="handleTabChange('divergence')">
          {{ "分歧观点" }}
        </div>

        <div class="header-right-btn" @click="handleSave" v-if="showAllBtn">
          <img src="@/assets/icons/box-header-icon1.png" alt="">
        </div>

        <div class="header-right-btn" @click="handleCollect">
          <img src="@/assets/icons/box-header-icon3.png" alt="">
        </div>
      </div>
    </div>
    <div class="wrapper-main">
      <slot></slot>
    </div>
  </div>
</template>

<script setup>
import { ElMessage } from 'element-plus'
import { ref, computed } from 'vue'

const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  width: {
    type: String,
    default: ''
  },
  height: {
    type: String,
    default: ''
  },
  showAllBtn: {
    type: Boolean,
    default: true
  },
  // 当业务功能尚未实现时，点击右上角图标仅弹出统一提示
  devTip: {
    type: Boolean,
    default: false
  }
})

const emit = defineEmits(['save', 'download', 'collect', 'tab-change'])

// 共识/分歧：单选，默认共识观点
const activeView = ref('consensus')
const handleTabChange = type => {
  activeView.value = type
  emit('tab-change', type)
}

const handleSave = () => {
  if (props.devTip) {
    ElMessage.warning('当前功能正在开发中，敬请期待！')
    return
  }
  ElMessage.success('保存当前内容')
  // emit('save')
}

const handleDownload = () => {
  if (props.devTip) {
    ElMessage.warning('当前功能正在开发中，敬请期待！')
    return
  }
  ElMessage.success('下载当前内容')
  // emit('download')

}

const handleCollect = () => {
  if (props.devTip) {
    ElMessage.warning('当前功能正在开发中，敬请期待！')
    return
  }
  ElMessage.success('收藏当前内容')
  // emit('collect')

}

</script>

<style lang="scss" scoped>
.analysis-box-wrapper {
  border: 1px solid rgba(234, 236, 238, 1);
  border-radius: 10px;
  box-shadow: 0px 0px 20px 0px rgba(25, 69, 130, 0.1);
  background: rgba(255, 255, 255, 1);

  .wrapper-header {
    height: 45px;
    display: flex;
    padding-right: 14px;
    align-items: center;
    box-sizing: border-box;

    .header-icon {
      width: 8px;
      height: 20px;
      background: var(--color-main-active);
      border-radius: 0 4px 4px 0;
      margin-right: 14px;
    }

    .header-title {
      flex: auto;
      width: 20px;
      // color: var(--color-main-active);
      // font-family: Source Han Sans CN;
      // font-size: 20px;
      // font-weight: 700;
      // line-height: 26px;
      // letter-spacing: 0px;
      height: 100%;

      &>div {
        height: 100%;
        color: var(--color-main-active);
        font-family: Microsoft YaHei;
        font-size: 20px;
        line-height: 45px;
        font-weight: 700;
      }
    }

    // .header-btn {
    //   display: flex;
    //   justify-content: flex-end;
    //   gap: 8px;
    // }

    // .header-btn1 {
    //   position: absolute;
    //   top: 14px;
    //   right: 116px;
    // }

    .header-right {
      height: 28px;
      display: flex;
      justify-content: flex-end;
      gap: 4px;

      .text-one {
        border: 1px solid rgb(230, 231, 232);
        width: 88px;
        height: 32px;
        border-radius: 4px;
        background-color: rgb(255, 255, 255);
        font-family: "Source Han Sans CN", sans-serif;
        font-weight: 400;
        font-size: 18px;
        line-height: 24px;
        letter-spacing: 0px;
        text-align: left;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;

        &.is-active {
          background-color: rgb(246, 250, 255);
          color: rgb(5, 95, 194);
          font-weight: 700;
          border: 1px solid rgb(5, 95, 194);
        }
      }

      .text-two {
        border: 1px solid rgb(230, 231, 232);
        width: 88px;
        height: 32px;
        border-radius: 4px;
        background-color: rgb(255, 255, 255);
        font-family: "Source Han Sans CN", sans-serif;
        font-weight: 400;
        font-size: 18px;
        line-height: 24px;
        letter-spacing: 0px;
        text-align: left;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;

        &.is-active {
          background-color: rgb(246, 250, 255);
          color: rgb(5, 95, 194);
          font-weight: 700;
          border: 1px solid rgb(5, 95, 194);
        }
      }

      .header-right-btn {
        width: 28px;
        height: 28px;
        cursor: pointer;

        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }

  .wrapper-main {
    height: calc(100% - 45px);
    overflow: hidden;
    // overflow-y: auto;
    padding: 5px auto;
  }
}
</style>
