<template>
  <ElCollapse class="courseCollapse" accordion v-model="myActiveCollapse">
    <ElCollapseItem v-for="item in props.courseList" :key="item.id" :name="item.id">
      <template #title>
        <div class="courseCollapseHead">
          <div class="tip"></div>
          <div class="list"></div>
          <div class="courseCollapseHeadTit">
            {{ item.name }}
          </div>
        </div>
      </template>
      <div class="courseCollapseCon">
        <div
          class="itemCon"
          :class="{ active: myActiveCollapseId === itemV.id }"
          v-for="itemV in item.lessonCoursewareDetailKnowledgeDetailList"
          :key="itemV.id"
          @click="handleCollapseItem(itemV)"
        >
          <div class="itemName">{{ itemV.name }}</div>
        </div>
      </div>
    </ElCollapseItem>
  </ElCollapse>
</template>

<script setup lang="ts">
import { ElCollapse, ElCollapseItem } from "element-plus"
import { ref, watch } from "vue"

const props = defineProps<{
  activeCollapse: string
  activeCollapseId: string
  courseList: any[]
}>()

const emits = defineEmits<{
  (event: "handleCollapseItem", item: Record<string, any>): void
}>()

const myActiveCollapse = ref(props.activeCollapse)
const myActiveCollapseId = ref(props.activeCollapseId)
watch(
  () => props.activeCollapse,
  () => {
    myActiveCollapse.value = props.activeCollapse
  }
)
watch(
  () => props.activeCollapseId,
  () => {
    myActiveCollapseId.value = props.activeCollapseId
  }
)

function handleCollapseItem(item: Record<string, any>) {
  emits("handleCollapseItem", item)
}
</script>

<style lang="scss" scoped>
.courseCollapse {
  --el-collapse-header-height: 56px !important;
  border: none;
  ::v-deep(.el-collapse-item) {
    padding: 0 8px;
    &.is-active {
      background: #f5f6fa;
      border-radius: 10px;
      .el-collapse-item__header,
      .el-collapse-item__wrap {
        background-color: transparent;
      }
      .courseCollapseHead {
        .tip {
          background: url("./imgs/actJ.png") no-repeat;
          background-size: 16px 16px;
        }
        .list {
          background-image: url("./imgs//actList.png");
        }
        .courseCollapseHeadTit {
          font-weight: 600;
          color: #131415;
        }
      }
    }
    .el-collapse-item__header {
      border-bottom: none;
    }
    .el-collapse-item__arrow {
      display: none;
    }
    .el-collapse-item__wrap {
      border-bottom: none;
      .el-collapse-item__content {
        padding-bottom: 12px;
      }
    }
  }
  .courseCollapseHead {
    display: flex;
    align-items: center;
    width: 100%;
    .tip {
      margin-left: 8px;
      width: 16px;
      height: 16px;
      background: url("./imgs/j.png") no-repeat;
      background-size: 8px 12px;
      background-position: center;
      flex-shrink: 0;
    }
    .list {
      margin: 0 8px;
      width: 16px;
      height: 18px;
      background: url("./imgs/list.png") no-repeat;
      background-size: 100% 100%;
      flex-shrink: 0;
    }
    .courseCollapseHeadTit {
      font-weight: 400;
      font-size: 16px;
      color: #8b8d98;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  .courseCollapseCon {
    .itemCon {
      width: 100%;
      height: 40px;
      border-radius: 6px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 8px;
      cursor: pointer;
      &:first-child {
        margin-top: 0;
      }
      &:hover {
        .itemName {
          color: #0482ff;
        }
      }
      &.active {
        background: rgba(16, 31, 87, 0.06);
        .itemName {
          font-weight: 600;
          color: #0482ff;
        }
      }
    }
    .itemName {
      margin-left: 56px;
      margin-right: 10px;
      font-weight: 400;
      font-size: 14px;
      color: #131415;
      line-height: 20px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}
</style>
