<template>
  <div class="student-preview" :class="{ 'fullscreen': fullscreen }">
    <!-- PPT 预览模式：16:9 比例容器 -->
    <div v-if="!fullscreen" class="preview-wrapper">
      <div class="preview-card">
        <!-- 标题区 -->
        <div v-if="title || subtitle || progress" class="title-area">
          <h1 v-if="title" class="preview-title">
            <span v-if="titleIcon" class="title-icon">{{ titleIcon }}</span>
            {{ title }}
          </h1>
          <p v-if="subtitle" class="preview-subtitle">{{ subtitle }}</p>
          <p v-if="progress" class="preview-progress">{{ progress }}</p>
        </div>

        <!-- 内容区 -->
        <div class="content-area">
          <slot />
        </div>

        <!-- 操作区 -->
        <div v-if="$slots.action" class="action-area">
          <slot name="action" />
        </div>
      </div>
    </div>

    <!-- 全屏模式 -->
    <div v-else class="fullscreen-wrapper">
      <div v-if="title || subtitle || progress" class="title-area">
        <h1 v-if="title" class="preview-title">
          <span v-if="titleIcon" class="title-icon">{{ titleIcon }}</span>
          {{ title }}
        </h1>
        <p v-if="subtitle" class="preview-subtitle">{{ subtitle }}</p>
        <p v-if="progress" class="preview-progress">{{ progress }}</p>
      </div>

      <div class="content-area fullscreen-content">
        <slot />
      </div>

      <div v-if="$slots.action" class="action-area">
        <slot name="action" />
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
interface Props {
  title?: string
  subtitle?: string
  titleIcon?: string
  progress?: string
  fullscreen?: boolean
}

withDefaults(defineProps<Props>(), {
  fullscreen: false,
})
</script>

<style lang="scss" scoped>
.student-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
  border-radius: 16px;
}

.preview-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #f9fafb;
}

.preview-card {
  width: 100%;
  max-width: 900px;
  aspect-ratio: 16 / 9;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.fullscreen-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

.title-area {
  padding: 24px 32px 16px;
  text-align: center;
  border-bottom: 1px solid #f9fafb;
}

.preview-title {
  font-size: 20px;
  font-weight: 600;
  color: #111827;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
}

.title-icon {
  font-size: 24px;
}

.preview-subtitle {
  font-size: 14px;
  color: #9ca3af;
  margin: 4px 0 0;
}

.preview-progress {
  font-size: 12px;
  color: #9ca3af;
  margin: 8px 0 0;
}

.content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 32px;
  overflow: auto;
}

.fullscreen-content {
  overflow: auto;
}

.action-area {
  padding: 16px 32px;
  border-top: 1px solid #f9fafb;
  background: #fafbfc;
}
</style>
