<template>
  <div class="ln-page container-height">
    <!-- ===== AURORA BACKGROUND ===== -->
    <div class="ln-aurora-bg" aria-hidden="true">
      <div class="ln-orb ln-orb-1"></div>
      <div class="ln-orb ln-orb-2"></div>
      <div class="ln-orb ln-orb-3"></div>
      <div class="ln-grid-overlay"></div>
      <div class="ln-noise-texture"></div>
    </div>

    <!-- ===== MAIN CONTENT ===== -->
    <div class="ln-content">
      <!-- Breadcrumb -->
      <div class="ln-breadcrumb-wrapper">
        <Breadcrumb />
      </div>

      <!-- Page Header -->
      <div class="ln-header">
        <div class="ln-header-content">
          <div class="ln-title-wrapper">
            <!-- <div class="ln-title-line"></div> -->
            <h1 class="ln-title">{{$t('common.xuxibiji')}}</h1>
          </div>
          <p class="ln-subtitle">{{$t('common.learnNoteSubtitle')}}</p>
        </div>
      </div>

      <!-- Main Layout -->
      <div class="ln-layout">
        <!-- Left Sidebar - Course List -->
        <aside class="ln-sidebar">
          <div class="ln-sidebar-inner">
            <div class="ln-sidebar-header">
              <div class="ln-section-line"></div>
              <h3 class="ln-section-title">{{$t('common.learnNoteList')}}</h3>
              <span class="ln-course-count">{{ list.length }}</span>
            </div>

            <div class="ln-course-list">
              <div
                v-for="(item, index) in list"
                :key="item.courseId"
                class="ln-course-card"
                :class="{ 'active': item.courseId === selectedItem.courseId }"
                @click="selectedItem = item"
                :style="{ animationDelay: `${index * 50}ms` }"
              >
                <div class="ln-course-cover">
                  <img :src="item.coverImageUrl" alt="" v-if="item.coverImageUrl" class="ln-cover-image">
                  <div class="ln-cover-overlay"></div>
                  <div class="ln-cover-glow"></div>
                </div>

                <div class="ln-course-info">
                  <h4 class="ln-course-title">{{ item.courseTitle }}</h4>
                  <p class="ln-course-intro" v-if="item.courseIntro">{{ item.courseIntro }}</p>
                  
                  <div class="ln-course-actions" v-if="item.courseId != -1" @click.stop.prevent>
                    <button class="ln-study-btn" @click="goDetail(item)">
                      <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">
                        <path d="M8 5v14l11-7z"/>
                      </svg>
                      <span>{{$t('common.lijixuexi')}}</span>
                    </button>
                  </div>
                </div>

                <div class="ln-card-indicator"></div>
              </div>
            </div>

            <div v-if="list.length === 0" class="ln-empty-state">
              <el-empty :image-size="120" :description="$t('common.noData')" />
            </div>
          </div>
        </aside>

        <!-- Right Content - Notes -->
        <main class="ln-main">
          <div class="ln-main-inner">
            <Xuxibiji :info="selectedItem" />
          </div>
        </main>
      </div>
    </div>
  </div>
</template>

<script setup>
import playIcon from '@/assets/imgs/bofang.png'
import Xuxibiji from '@/pages/LearningSystem/components/xuxibiji.vue'
import Breadcrumb from '@/components/Breadcrumb.vue'
import { getCourseWithNotesList } from '@/api/course.js'
import { isLogin, openFullScreenLoading } from '@/utils/util.js'

import { useI18n } from 'vue-i18n' 
const { t } = useI18n() 

import { ref, onMounted, inject } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useAppStore } from '@/pinia/appStore'
const appStore = useAppStore()
const route = useRoute()
const router = useRouter()
const list = ref([])
const selectedItem = ref({})
const openLoginDialog = inject('openLoginDialog')

onMounted(() => {
  getList();
});

const getList = async () => {
  let token = localStorage.getItem('token');
  if(!token) return;
  
  const loading = openFullScreenLoading();
  getCourseWithNotesList().then(res => {
    loading.close();
    if(res.code === 200){
      list.value = [
        {
          courseId:'-1',
          courseTitle:t('common.personalNotes'),
          coverImageUrl: appStore.userInfo?.userAvatar || '',
          courseIntro:''
        },
        ...res.rows
      ]
      if(list.value.length > 0){
        selectedItem.value = list.value[0]
      }
    }
  })
};

const goDetail = (item) => {
  if(!isLogin({callback: openLoginDialog, t})){
    return;
  }
  router.push({
    path: `/learning-system/detail/${item.courseId}`,
    query: {
      courseId: item.courseId,
      metaTitle: item.courseTitle || '课程详情'
    }
  })
};
</script>

<style scoped lang="scss">
/* ===== PAGE CONTAINER ===== */
.ln-page {
  position: relative;
  min-height: 100vh;
  background: linear-gradient(160deg, #eef2ff 0%, #ede9fe 28%, #e8e4ff 52%, #f3e8ff 72%, #fce7f3 100%);
  overflow-x: hidden;
}

/* ===== AURORA BACKGROUND ===== */
.ln-aurora-bg {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.ln-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  animation: float 20s ease-in-out infinite;
}

.ln-orb-1 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(79, 70, 229, 0.15), transparent 70%);
  top: -200px;
  right: -100px;
  animation-delay: 0s;
}

.ln-orb-2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(124, 58, 237, 0.12), transparent 70%);
  bottom: -150px;
  left: -100px;
  animation-delay: -7s;
}

.ln-orb-3 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(236, 72, 153, 0.1), transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -14s;
}

@keyframes float {
  0%, 100% {
    transform: translate(0, 0) scale(1);
  }
  33% {
    transform: translate(30px, -30px) scale(1.1);
  }
  66% {
    transform: translate(-20px, 20px) scale(0.9);
  }
}

.ln-grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    linear-gradient(rgba(79, 70, 229, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79, 70, 229, 0.03) 1px, transparent 1px);
  background-size: 50px 50px;
  opacity: 0.5;
}

.ln-noise-texture {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
  opacity: 0.03;
  mix-blend-mode: overlay;
}

/* ===== MAIN CONTENT ===== */
.ln-content {
  position: relative;
  z-index: 1;
  padding: 0 24px 40px;
  max-width: 1428px;
  margin: 0 auto;
}

/* ===== BREADCRUMB ===== */
.ln-breadcrumb-wrapper {
  padding: 20px 0;
  animation: fadeInDown 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== PAGE HEADER ===== */
.ln-header {
  margin-bottom: 32px;
  animation: fadeInUp 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ln-header-content {
  text-align: center;
}

.ln-title-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.ln-title-line {
  width: 5px;
  height: 36px;
  background: linear-gradient(180deg, #4f46e5, #7c3aed);
  border-radius: 3px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

.ln-title {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #1f2937 0%, #4f46e5 50%, #7c3aed 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
  line-height: 1.2;
}

.ln-subtitle {
  font-size: 16px;
  color: #6b7280;
  margin: 0;
  letter-spacing: 0.02em;
  font-weight: 400;
}

/* ===== MAIN LAYOUT ===== */
.ln-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  animation: fadeIn 1s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ===== SIDEBAR ===== */
.ln-sidebar {
  position: relative;
}

.ln-sidebar-inner {
  position: sticky;
  top: 20px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 
    0 8px 32px rgba(79, 70, 229, 0.08),
    0 2px 8px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  
  &::-webkit-scrollbar {
    width: 6px;
  }
  
  &::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 3px;
  }
  
  &::-webkit-scrollbar-thumb {
    background: rgba(79, 70, 229, 0.15);
    border-radius: 3px;
    
    &:hover {
      background: rgba(79, 70, 229, 0.25);
    }
  }
}

.ln-sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(229, 231, 235, 0.6);
}

.ln-section-line {
  width: 4px;
  height: 20px;
  background: linear-gradient(180deg, #4f46e5, #7c3aed);
  border-radius: 2px;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.ln-section-title {
  font-size: 18px;
  font-weight: 700;
  color: #1f2937;
  margin: 0;
  letter-spacing: -0.02em;
  flex: 1;
}

.ln-course-count {
  font-size: 13px;
  font-weight: 600;
  color: #4f46e5;
  background: rgba(79, 70, 229, 0.1);
  padding: 4px 12px;
  border-radius: 12px;
}

/* ===== COURSE LIST ===== */
.ln-course-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ln-course-card {
  position: relative;
  display: flex;
  gap: 14px;
  padding: 14px;
  background: rgba(249, 250, 251, 0.6);
  border: 1px solid rgba(229, 231, 235, 0.5);
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  animation: slideInRight 0.6s cubic-bezier(0.16, 1, 0.3, 1) backwards;
  
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.03), rgba(124, 58, 237, 0.03));
    opacity: 0;
    transition: opacity 0.4s ease;
  }
  
  &:hover {
    transform: translateX(6px);
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(79, 70, 229, 0.2);
    box-shadow: 
      0 8px 24px rgba(79, 70, 229, 0.12),
      0 2px 8px rgba(0, 0, 0, 0.06),
      inset 0 1px 0 rgba(255, 255, 255, 0.9);
    
    &::before {
      opacity: 1;
    }
    
    .ln-cover-image {
      transform: scale(1.08);
    }
    
    .ln-cover-glow {
      opacity: 0.3;
    }
    
    .ln-course-title {
      color: #4f46e5;
    }
    
    .ln-card-indicator {
      opacity: 1;
      transform: translateY(-50%) scaleY(1);
    }
  }
  
  &.active {
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.08), rgba(124, 58, 237, 0.08));
    border-color: rgba(79, 70, 229, 0.25);
    box-shadow: 
      0 8px 24px rgba(79, 70, 229, 0.15),
      0 2px 8px rgba(0, 0, 0, 0.06),
      inset 0 1px 0 rgba(255, 255, 255, 0.8);
    
    .ln-course-title {
      color: #4f46e5;
      font-weight: 700;
    }
    
    .ln-card-indicator {
      opacity: 1;
      transform: translateY(-50%) scaleY(1);
    }
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.ln-course-cover {
  position: relative;
  width: 120px;
  height: 68px;
  flex-shrink: 0;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
  
  .ln-cover-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  }
  
  .ln-cover-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.1), rgba(124, 58, 237, 0.1));
    opacity: 0;
    transition: opacity 0.4s ease;
  }
  
  .ln-cover-glow {
    position: absolute;
    top: -50%;
    left: -50%;
    right: -50%;
    bottom: -50%;
    background: radial-gradient(circle at center, rgba(79, 70, 229, 0.3), transparent 60%);
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
  }
}

.ln-course-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  z-index: 1;
  
  .ln-course-title {
    font-size: 15px;
    font-weight: 600;
    color: #374151;
    margin: 0 0 6px 0;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color 0.3s ease;
  }
  
  .ln-course-intro {
    font-size: 12px;
    color: #9ca3af;
    margin: 0 0 8px 0;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.ln-course-actions {
  display: flex;
  justify-content: flex-end;
  
  .ln-study-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 
      0 4px 12px rgba(79, 70, 229, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.2);
    
    svg {
      width: 12px;
      height: 12px;
      transition: transform 0.3s ease;
    }
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: 
        0 6px 16px rgba(79, 70, 229, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
      
      svg {
        transform: scale(1.2);
      }
    }
    
    &:active {
      transform: translateY(0);
    }
  }
}

.ln-card-indicator {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 4px;
  height: 60%;
  background: linear-gradient(180deg, #4f46e5, #7c3aed);
  border-radius: 0 3px 3px 0;
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 0 12px rgba(79, 70, 229, 0.5);
}

.ln-empty-state {
  padding: 40px 20px;
  text-align: center;
}

/* ===== MAIN CONTENT ===== */
.ln-main {
  position: relative;
  min-width: 0;
}

.ln-main-inner {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 
    0 8px 32px rgba(79, 70, 229, 0.08),
    0 2px 8px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  animation: fadeInUp 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.2s backwards;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
  .ln-layout {
    grid-template-columns: 340px 1fr;
    gap: 20px;
  }
  
  .ln-course-cover {
    width: 100px;
    height: 56px;
  }
}

@media (max-width: 992px) {
  .ln-content {
    padding: 0 20px 32px;
  }
  
  .ln-layout {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .ln-sidebar-inner {
    position: static;
    max-height: none;
  }
  
  .ln-title {
    font-size: 28px;
  }
}

@media (max-width: 768px) {
  .ln-content {
    padding: 0 16px 24px;
  }
  
  .ln-header {
    margin-bottom: 24px;
  }
  
  .ln-title {
    font-size: 24px;
  }
  
  .ln-subtitle {
    font-size: 14px;
  }
  
  .ln-sidebar-inner,
  .ln-main-inner {
    padding: 20px;
    border-radius: 20px;
  }
  
  .ln-course-card {
    padding: 12px;
    gap: 12px;
  }
  
  .ln-course-cover {
    width: 90px;
    height: 50px;
  }
  
  .ln-course-info {
    .ln-course-title {
      font-size: 14px;
    }
    
    .ln-course-intro {
      font-size: 11px;
    }
  }
  
  .ln-study-btn {
    padding: 5px 12px;
    font-size: 11px;
  }
}

@media (max-width: 480px) {
  .ln-content {
    padding: 0 12px 20px;
  }
  
  .ln-title {
    font-size: 20px;
  }
  
  .ln-sidebar-inner,
  .ln-main-inner {
    padding: 16px;
    border-radius: 16px;
  }
  
  .ln-course-card {
    flex-direction: column;
    padding: 12px;
  }
  
  .ln-course-cover {
    width: 100%;
    height: 140px;
  }
  
  .ln-course-info {
    .ln-course-intro {
      display: none;
    }
  }
  
  .ln-course-actions {
    margin-top: 8px;
    
    .ln-study-btn {
      width: 100%;
      justify-content: center;
    }
  }
}
</style>
