<template>
  <div class="other-course">
    <div class="section-header">
      <div class="header-line"></div>
      <h3 class="section-title">{{$t('common.qitakechengtuijian')}}</h3>
    </div>
    
    <div class="course-list">
      <div 
        v-for="item in list" 
        :key="item.courseId" 
        class="course-card"
        @click="goDetail(item)"
      >
        <div class="course-image-wrapper">
          <img :src="item.coverImageUrl" alt="" class="course-image">
          <div class="image-overlay"></div>
        </div>
        
        <div class="course-content">
          <h4 class="course-title">{{ item.courseTitle }}</h4>
          
          <div class="course-meta">
            <el-tag 
              type="primary" 
              size="small" 
              class="skill-tag"
              v-if="item.skillTagName"
            >
              {{item.skillTagName}}
            </el-tag>
            
            <div class="view-count">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="eye-icon">
                <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
                <circle cx="12" cy="12" r="3"/>
              </svg>
              <span>{{ item.viewCount }} {{ $t('common.renkanguo') }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <div v-if="list.length === 0" class="empty-state">
      <el-empty :image-size="120" :description="$t('common.noData')" />
    </div>
  </div>
</template>
<script setup>
import { getCourseList } from '@/api/course.js'
import { ref, onMounted, watch, reactive, onActivated } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter();


const props =defineProps({
  info: {
    type: Object,
    default: () => ({})
  }
})

const list = ref([]);
const searchFom = reactive({
  skillTag: '',
  pageNum: 1,
  pageSize: 5,
})

watch(() => props.info.skillTag, (newVal, oldVal) => {
  if(newVal !== oldVal){
    // 课程ID变化时，重置分页参数
    searchFom.skillTag = newVal
    getList('init');
  }
})

onActivated(() => {
  searchFom.skillTag = props.info.skillTag;
  getList('init');
})
// onMounted(() => {
//   getList();
// });
const getList = async (type) => {
  const res = await getCourseList(searchFom)
  if(res.code === 200){
    list.value = res.rows || [];
  }
};
const goDetail = (item) => {
  //增加参数名称
  router.push({
    path: `/learning-system/detail/${item.courseId}`,
    query: {
      courseId: item.courseId,
      metaTitle: item.courseTitle || '课程详情'
    }
  })
};
</script>
<style scoped lang="scss">
.other-course {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 
    0 8px 32px rgba(79, 70, 229, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  
  .section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    
    .header-line {
      width: 4px;
      height: 24px;
      background: linear-gradient(135deg, #4f46e5, #7c3aed);
      border-radius: 2px;
      box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
    }
    
    .section-title {
      font-size: 18px;
      font-weight: 700;
      color: #1f2937;
      margin: 0;
      letter-spacing: -0.02em;
    }
  }
  
  .course-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
  
  .course-card {
    display: flex;
    gap: 16px;
    padding: 16px;
    background: rgba(249, 250, 251, 0.8);
    border: 1px solid rgba(229, 231, 235, 0.6);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    
    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: linear-gradient(135deg, rgba(79, 70, 229, 0.05), rgba(124, 58, 237, 0.05));
      opacity: 0;
      transition: opacity 0.3s ease;
    }
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: 
        0 12px 28px rgba(79, 70, 229, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
      border-color: rgba(79, 70, 229, 0.3);
      
      &::before {
        opacity: 1;
      }
      
      .course-image-wrapper {
        .image-overlay {
          opacity: 0.15;
        }
      }
      
      .course-title {
        color: #4f46e5;
      }
    }
    
    .course-image-wrapper {
      position: relative;
      width: 140px;
      height: 80px;
      flex-shrink: 0;
      border-radius: 12px;
      overflow: hidden;
      
      .course-image {
        width: 100%;
        height: 100%;
        object-fit: cover;
        transition: transform 0.3s ease;
      }
      
      .image-overlay {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(135deg, #4f46e5, #7c3aed);
        opacity: 0;
        transition: opacity 0.3s ease;
      }
      
      &:hover .course-image {
        transform: scale(1.05);
      }
    }
    
    .course-content {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      min-width: 0;
      
      .course-title {
        font-size: 15px;
        font-weight: 600;
        color: #374151;
        margin: 0 0 8px 0;
        line-height: 1.4;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        transition: color 0.3s ease;
      }
      
      .course-meta {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        
        .skill-tag {
          font-size: 11px;
          font-weight: 500;
          border-radius: 6px;
          padding: 4px 10px;
          background: rgba(79, 70, 229, 0.1);
          border-color: rgba(79, 70, 229, 0.2);
          color: #4f46e5;
        }
        
        .view-count {
          display: flex;
          align-items: center;
          gap: 6px;
          font-size: 12px;
          color: #9ca3af;
          
          .eye-icon {
            width: 14px;
            height: 14px;
            stroke: #9ca3af;
          }
        }
      }
    }
  }
  
  .empty-state {
    padding: 40px 20px;
    text-align: center;
  }
}

@media (max-width: 768px) {
  .other-course {
    padding: 20px;
    border-radius: 16px;
    
    .section-header {
      margin-bottom: 20px;
      
      .header-line {
        height: 20px;
      }
      
      .section-title {
        font-size: 16px;
      }
    }
    
    .course-list {
      gap: 12px;
    }
    
    .course-card {
      padding: 14px;
      gap: 14px;
      
      .course-image-wrapper {
        width: 120px;
        height: 68px;
        border-radius: 10px;
      }
      
      .course-content {
        .course-title {
          font-size: 14px;
        }
        
        .course-meta {
          flex-wrap: wrap;
          gap: 8px;
          
          .skill-tag {
            font-size: 10px;
            padding: 3px 8px;
          }
          
          .view-count {
            font-size: 11px;
            
            .eye-icon {
              width: 12px;
              height: 12px;
            }
          }
        }
      }
    }
  }
}

@media (max-width: 480px) {
  .other-course {
    padding: 16px;
    border-radius: 14px;
    
    .course-card {
      flex-direction: column;
      padding: 12px;
      
      .course-image-wrapper {
        width: 100%;
        height: 160px;
      }
      
      .course-content {
        .course-meta {
          flex-direction: column;
          align-items: flex-start;
        }
      }
    }
  }
}
</style>
