<template>
  <CourseDetail 
    v-if="courseId"
    :course-id="courseId"
    :show-back-button="true"
    back-button-text="返回"
    @back="handleBack"
    @start-learning="handleStartLearning"
  />
</template>

<script setup lang="ts">
import { computed, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { CourseDetail } from '@/views/public/course/components';
import { courseApi } from '@/apis/study';

defineOptions({
  name: 'CourseDetailView'
});

const router = useRouter();
const route = useRoute();

const courseId = computed(() => route.query.courseId as string || '');

// 返回上一页
function handleBack() {
  router.back();
}
onMounted(() => {
  // 调用接口更新浏览记录
  courseApi.incrementViewCount(courseId.value);
});

// 开始学习课程
function handleStartLearning(courseId: string, chapterIndex: number, nodeIndex: number) {
  // 跳转到课程学习页面
  router.push({
    path: '/study-plan/course-study',
    query: {
      courseId,
      chapterIndex: chapterIndex.toString(),
      nodeIndex: nodeIndex.toString()
    }
  });
}
</script>

<style lang="scss" scoped>

</style>

