<template>
  <div class="title-box">
    <div class="title-box-wrapper">
      <!-- 标题 -->
      <div class="title">
        <img src="@/assets/scream/title-icon.png" />
        <div class="text">{{ title }}</div>
      </div>
      <div class="title-box-operate">
        <!-- 塘口筛选 -->
        <div v-if="isSelectShow" class="select-pond screen-select">
          <div class="user-title">塘口筛选：</div>
          <el-select v-model="value" placeholder="请选择塘口" size="small" clearable @change="handleChange" popper-class="optionCls" style="width: 140px">
            <el-option v-for="item in options" :key="item.id" :label="item.pondName" :value="item.id" />
          </el-select>
        </div>
        <!-- 展开折叠 -->
        <div v-if="isExpandedShow" @click="toggleExpand" class="expand-collapse-btn">
          {{ Expanded ? "收起" : "展开" }}
          <el-icon v-if="Expanded"><ArrowUpBold /></el-icon>
          <el-icon v-else><ArrowDownBold /></el-icon>
        </div>
      </div>
    </div>
    <el-divider />
  </div>
</template>

<script setup name="BoxHeader">
const props = defineProps({
  title: {
    type: String,
    default: "标题",
  },
  isSelectShow: {
    type: Boolean,
    default: true,
  },
  isExpanded: {
    type: Boolean,
    default: true,
  },
  isExpandedShow: {
    type: Boolean,
    default: true,
  },
  options: {
    type: Array,
    default: () => [
      {
        id: "Option1",
        pondName: "塘口1",
      },
      {
        id: "Option2",
        pondName: "塘口2",
      },
      {
        id: "Option3",
        pondName: "塘口3",
      },
      {
        id: "Option4",
        pondName: "塘口4",
      },
    ],
  },
})
const emit = defineEmits(["change", "expand"])

const value = ref("")

const handleChange = value => {
  emit("change", value)
}

const Expanded = ref(true)

watch(
  () => props.isExpanded,
  value => {
    Expanded.value = value
  }
)

const toggleExpand = () => {
  emit("expand", !Expanded.value)
}
</script>

<style lang="scss" scoped>
.title-box {
  width: 100%;

  padding: 12px 15px 5px 15px;
  font-weight: 600;
  letter-spacing: 3px;
  font-size: 18px;
  color: #ffffff;
  :deep(.el-divider--horizontal) {
    margin: 2px 0 0 0;
  }

  .title-box-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .title {
    display: flex;
    align-items: center;
    height: 30px;
    line-height: 30px;

    img {
      width: 15px;
      height: 25px;
    }
  }
}

.title-box-operate {
  display: flex;
  align-items: center;
}

// 塘口选择器
.select-pond {
  display: flex;
  align-items: center;
  color: #ffffff;
  font-size: 14px;
  font-weight: 500;
  margin-right: 15px;
}

// 展开收缩按钮样式
.expand-collapse-btn {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  color: #ffffff;
  font-size: 14px;
  font-weight: 500;
}
</style>

<style lang="scss">
.optionCls.is-light {
  ::before {
    background: none !important;
  }
}
.optionCls {
  border: none !important;
  ::before {
    border: none !important;
  }
  .el-scrollbar {
    .el-select-dropdown__list {
      background: rgb(21, 30, 89) !important;
    }
    .el-select-dropdown__item {
      color: #fff !important;
    }
    .el-select-dropdown__item.is-hovering {
      background-color: #60a7ee !important;
    }
  }
}
</style>
