<template>
  <div class="collapse-item">
    <div class="collapse-item__header" @click="toggle">
      <div class="collapse-item__header--left">
        <el-icon class="collapse-item__icon" v-if="!opacityIcon">
          <component :is="isActive ? ArrowUp : ArrowDown" />
        </el-icon>
        <span style="font-weight: 550">{{ name }}</span>
        <slot name="view-operation" />
      </div>
      <div class="collapse-item__header--right">
        <slot name="right-header" />
      </div>
    </div>
    <div v-show="isActive" class="collapse-item__main">
      <slot name="main-table" />
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { ArrowUp, ArrowDown } from '@element-plus/icons-vue';

  defineProps<{
    name: string;
    isActive?: boolean;
    opacityIcon?: boolean;
  }>();

  const emit = defineEmits(['toggle']);

  const toggle = () => {
    emit('toggle');
  };
</script>

<style lang="scss" scoped>
  .collapse-item {
    width: 100%;
    background: #f2f8ff;
    border-radius: 4px;
    margin-bottom: 8px;
    padding-bottom: 20px;
    &__header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 20px 25px 0 25px;
      font-size: 18px;
      color: rgba($text-color, 0.85);
      cursor: pointer;
      &--left {
        @include flex-center;
        gap: 20px;
      }
    }
    &__main {
      padding: 20px 10px 0 10px;
    }
  }
</style>
