<template>
  <div class="storyboard-video-page">
    <!-- 左侧导航栏 -->
    <aside class="sidebar">
      <div class="logo">
        <img src="/images/backgrounds/logo.svg?v=2" alt="Logo" />
      </div>
      <nav class="nav-menu">
        <div class="nav-item" @click="goToProfile">
          <UserOutlined />
          <span>个人主页</span>
        </div>
        <div class="nav-item" @click="goToSubscription">
          <CompassOutlined />
          <span>会员订阅</span>
        </div>
        <div class="nav-item" @click="goToMyWorks">
          <FileOutlined />
          <span>我的作品</span>
        </div>
        <div class="nav-divider"></div>
        <div class="nav-item" @click="goToTextToVideo">
          <PlayCircleOutlined />
          <span>文生视频</span>
          <span class="badge-pro">Pro</span>
        </div>
        <div class="nav-item" @click="goToImageToVideo">
          <PictureOutlined />
          <span>图生视频</span>
          <span class="badge-pro">Pro</span>
        </div>
        <div class="nav-item storyboard-item" @click="goToStoryboardVideoCreate">
          <VideoCameraOutlined />
          <span>分镜视频</span>
          <span class="badge-max">Max</span>
        </div>
      </nav>
    </aside>

    <!-- 主内容区域 -->
    <main class="main-content">
      <!-- 顶部用户信息卡片 -->
      <div class="user-info-card">
        <div class="user-avatar">
          <img src="/images/backgrounds/avatar-default.svg" :alt="$t('dashboard.userAvatar')" class="avatar-image" />
        </div>
        <div class="user-details">
          <div class="username">mingzi_FBx7foZYDS7inLQb</div>
          <div class="profile-prompt">还没有设置个人简介,点击填写</div>
          <div class="user-id">ID 2994509784706419</div>
        </div>
        <div class="edit-profile-btn">
          <a-button type="primary">编辑资料</a-button>
        </div>
      </div>

      <!-- 已发布作品区域 -->
      <div class="published-works">
        <div class="works-tabs">
          <div class="tab active">已发布</div>
        </div>
        
        <div class="works-grid">
          <div class="work-item" v-for="(work, index) in publishedWorks" :key="work.id" @click="openDetail(work)">
            <div class="work-thumbnail">
              <img v-lazy:loading="work.cover" :alt="work.title" />
              <!-- 鼠标悬停时显示的做同款按钮 -->
              <div class="hover-create-btn" @click.stop="goToCreate(work)">
                <a-button type="primary" size="small" round>
                  <PlayCircleOutlined />
                  {{ $t('works.createSimilar') }}
                </a-button>
              </div>
            </div>
            <div class="work-info">
              <div class="work-title">{{ work.title }}</div>
              <div class="work-meta">{{ work.date || $t('common.unknownDate') }} · {{ work.id }} · {{ work.size }}</div>
            </div>
            <div class="work-actions" v-if="index === 0">
              <a-button type="primary" class="create-similar-btn" @click.stop="goToCreate(work)">{{ $t('works.createSimilar') }}</a-button>
            </div>
            <div class="work-director" v-else>
              <span>DIRECTED BY VANNOCENT</span>
            </div>
          </div>
        </div>
      </div>
    </main>

    <!-- 作品详情模态框 -->
    <a-modal
      v-model:open="detailDialogVisible"
      :title="selectedItem?.title"
      width="60%"
      class="detail-dialog"
      :modal="true"
      :close-on-click-modal="true"
      :close-on-press-escape="true"
      @close="handleClose"
    >
      <div class="detail-content">
        <div class="detail-left">
          <div class="video-player">
            <img :src="selectedItem?.cover" :alt="selectedItem?.title" class="video-thumbnail" />
            <div class="play-overlay">
              <div class="play-button">▶</div>
            </div>
          </div>
        </div>
        
        <div class="detail-right">
          <div class="metadata-section">
            <div class="metadata-item">
              <span class="label">作品 ID</span>
              <span class="value">{{ selectedItem?.id }}</span>
            </div>
            <div class="metadata-item">
              <span class="label">文件大小</span>
              <span class="value">{{ selectedItem?.size }}</span>
            </div>
            <div class="metadata-item">
              <span class="label">创建时间</span>
              <span class="value">{{ selectedItem?.createTime }}</span>
            </div>
            <div class="metadata-item">
              <span class="label">分类</span>
              <span class="value">{{ selectedItem?.category }}</span>
            </div>
          </div>
          
          <div class="description-section">
            <h3 class="section-title">描述</h3>
            <p class="description-text">{{ getDescription(selectedItem) }}</p>
          </div>
          
          <!-- 操作按钮 -->
          <div class="action-section">
            <button class="create-similar-btn" @click="createSimilar">
              做同款
            </button>
          </div>
        </div>
      </div>
    </a-modal>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { message } from 'ant-design-vue'
import { UserOutlined, FileOutlined, PlayCircleOutlined, PictureOutlined, VideoCameraOutlined, CompassOutlined } from '@ant-design/icons-vue'

const router = useRouter()
const { t } = useI18n()

// 模态框状态
const detailDialogVisible = ref(false)
const selectedItem = ref(null)

// 已发布作品数据
const publishedWorks = ref([
  {
    id: '2995000000001',
    title: '分镜视频作品 #1',
    cover: '/images/backgrounds/welcome.jpg',
    text: 'What Does it Mean To You',
    size: '9 MB',
    category: '分镜视频',
    createTime: '2025/01/15 14:30',
    date: '2025/1/15'
  },
  {
    id: '2995000000002',
    title: '分镜视频作品 #2',
    cover: '/images/backgrounds/welcome.jpg',
    text: 'What Does it Mean To You',
    size: '9 MB',
    category: '分镜视频',
    createTime: '2025/01/14 16:45',
    date: '2025/1/14'
  },
  {
    id: '2995000000003',
    title: '分镜视频作品 #3',
    cover: '/images/backgrounds/welcome.jpg',
    text: 'What Does it Mean To You',
    size: '9 MB',
    category: '分镜视频',
    createTime: '2025/01/13 09:20',
    date: '2025/1/13'
  }
])

// 导航函数
const goToProfile = () => {
  router.push('/profile')
}

const goToSubscription = () => {
  router.push('/subscription')
}

const goToMyWorks = () => {
  router.push('/works')
}

const goToTextToVideo = () => {
  router.push('/text-to-video/create')
}

const goToImageToVideo = () => {
  router.push('/image-to-video/create')
}

const goToStoryboardVideoCreate = () => {
  router.push('/storyboard-video/create')
}

const goToCreate = (work) => {
  // 跳转到分镜视频创作页面
  router.push('/storyboard-video/create')
}

// 模态框相关函数
const openDetail = (work) => {
  selectedItem.value = work
  detailDialogVisible.value = true
}

const handleClose = () => {
  detailDialogVisible.value = false
  selectedItem.value = null
}

const getDescription = (item) => {
  if (!item) return ''
  return `这是一个${item.category}作品，展现了"What Does it Mean To You"的主题。作品通过AI技术生成，具有独特的视觉风格和创意表达。`
}

const createSimilar = () => {
  // 关闭模态框并跳转到创作页面
  handleClose()
  router.push('/storyboard-video/create')
}

onMounted(() => {
  // 页面初始化
})
</script>

<style scoped>
/* 图片懒加载样式 */
.lazy-LoadingOutlined {
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-elevated) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: lazy-shimmer 1.5s infinite;
}

.lazy-loaded {
  animation: lazy-fade-in 0.3s ease-in;
}

.lazy-error {
  background: var(--bg-surface);
}

@keyframes lazy-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes lazy-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.storyboard-video-page {
  display: flex;
  height: 100vh;
  background: var(--bg-base);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
}

/* 左侧导航栏 */
.sidebar {
  width: 280px !important;
  background: var(--bg-base) !important;
  padding: 24px 0 !important;
  border-right: 1px solid var(--border-subtle) !important;
  flex-shrink: 0 !important;
  z-index: 100 !important;
  display: block !important;
  position: relative !important;
}

.logo {
  padding: 0 24px 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo img {
  height: 40px;
  width: auto;
}

.nav-menu {
  padding: 0 24px;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  margin-bottom: 4px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-all);
  position: relative;
}

.nav-item:hover {
  background: var(--bg-hover);
}

.nav-item.active {
  background: var(--primary-900);
}

.nav-item .anticon {
  margin-right: 14px;
  font-size: var(--text-xl);
}

.nav-item span {
  font-size: var(--text-sm);
  flex: 1;
}

.nav-divider {
  height: 1px;
  background: var(--border-default);
  margin: 16px 0;
}

.sora-tag {
  margin-left: 8px;
}

/* 分镜视频特殊样式 */
.storyboard-item {
  position: relative;
}

.storyboard-item .sora-tag {
  background: linear-gradient(135deg, #667eea, #764ba2) !important;
  border: none !important;
  color: var(--text-primary) !important;
  font-weight: var(--font-bold) !important;
  font-size: var(--text-xs) !important;
  padding: 2px 8px !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3) !important;
  animation: pulse-glow 2s ease-in-out infinite alternate;
}

@keyframes pulse-glow {
  0% {
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
  }
  100% {
    box-shadow: 0 2px 12px rgba(102, 126, 234, 0.6);
  }
}

/* 主内容区域 */
.main-content {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* 用户信息卡片 */
.user-info-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: var(--space-5);
}

.user-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border-default);
  overflow: hidden;
}

.avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.username {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.profile-prompt {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

.user-id {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.edit-profile-btn {
  margin-left: auto;
}

/* 已发布作品区域 */
.published-works {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.works-tabs {
  display: flex;
  gap: var(--space-6);
}

.tab {
  padding: 8px 0;
  color: var(--text-tertiary);
  cursor: pointer;
  position: relative;
}

.tab.active {
  color: var(--text-primary);
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary-500);
}

.works-AppstoreOutlined {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

.work-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: var(--transition-all);
  cursor: pointer;
}

.work-item:hover {
  border-color: var(--primary-500);
  transform: translateY(-2px);
}

.work-thumbnail {
  position: relative;
  aspect-ratio: 16/9;
  overflow: hidden;
}

.work-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 鼠标悬停时显示的做同款按钮 */
.hover-create-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  opacity: 0;
  transform: translateY(10px);
  transition: var(--transition-all);
  z-index: 10;
}

.work-thumbnail:hover .hover-create-btn {
  opacity: 1;
  transform: translateY(0);
}

.hover-create-btn .ant-btn {
  background: rgba(64, 158, 255, 0.9);
  border: none;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);
}

.hover-create-btn .ant-btn:hover {
  background: rgba(64, 158, 255, 1);
  transform: scale(1.05);
}

/* work-overlay / overlay-text 样式已移除（不再使用） */

.work-info {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.work-title {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.work-meta {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.work-actions {
  padding: 0 12px 12px;
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-default);
}

.work-item:hover .work-actions {
  opacity: 1;
}

.create-similar-btn {
  width: 100%;
}

.work-director {
  padding: 0 12px 12px;
  text-align: center;
}

.work-director span {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .sidebar {
    width: 260px;
  }
  
  .works-AppstoreOutlined {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
}

@media (max-width: 768px) {
  .storyboard-video-page {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
    height: auto;
  }
  
  .nav-menu {
    flex-direction: row;
    overflow-x: auto;
    padding: 0 16px;
  }
  
  .nav-item {
    white-space: nowrap;
  }
  
  .works-AppstoreOutlined {
    grid-template-columns: 1fr;
  }
}

/* 模态框样式 */
:deep(.detail-dialog .ant-modal) {
  background: var(--bg-base) !important;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default) !important;
  box-shadow: var(--shadow-xl);
}

:deep(.detail-dialog .ant-modal-wrap) {
  background-color: rgba(0, 0, 0, 0.8) !important;
}

:deep(.detail-dialog .ant-modal-header) {
  background: var(--bg-base) !important;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-default);
}

:deep(.detail-dialog .ant-modal-title) {
  color: var(--text-primary) !important;
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
}

:deep(.detail-dialog .ant-modal-close) {
  color: var(--text-primary) !important;
}

:deep(.detail-dialog .ant-modal-body) {
  background: var(--bg-base) !important;
  padding: 0 !important;
}

:deep(.detail-dialog .ant-modal-mask) {
  background-color: rgba(0, 0, 0, 0.8) !important;
}

/* 全局覆盖Element Plus默认样式 */
:deep(.ant-modal) {
  background: var(--bg-base) !important;
  border: 1px solid var(--border-default) !important;
}

:deep(.ant-modal-wrap) {
  background-color: rgba(0, 0, 0, 0.8) !important;
}

:deep(.ant-modal-header) {
  background: var(--bg-base) !important;
}

:deep(.ant-modal-body) {
  background: var(--bg-base) !important;
}

:deep(.ant-modal-mask) {
  background-color: rgba(0, 0, 0, 0.8) !important;
}

.detail-content {
  display: flex;
  height: 50vh;
  background: var(--bg-base);
}

.detail-left {
  flex: 1;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-player {
  position: relative;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 16/9;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
}

.video-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.play-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-default);
}

.video-player:hover .play-overlay {
  opacity: 1;
}

.play-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-2xl);
  color: var(--text-inverse);
  font-weight: var(--font-bold);
}

.detail-right {
  flex: 1;
  padding: 20px;
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.metadata-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.metadata-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.metadata-item:last-child {
  border-bottom: none;
}

.label {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  font-weight: var(--font-medium);
}

.value {
  font-size: var(--text-sm);
  color: var(--text-primary);
  font-weight: var(--font-semibold);
}

.description-section {
  flex: 1;
}

.section-title {
  font-size: var(--text-base);
  color: var(--text-primary);
  font-weight: var(--font-semibold);
  margin-bottom: 12px;
}

.description-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 0;
}

.action-section {
  margin-top: auto;
}

.create-similar-btn {
  width: 100%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: var(--text-primary);
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  cursor: pointer;
  transition: var(--transition-all);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.create-similar-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

/* Sora2.0 SVG 风格标签 */
.badge-pro, .badge-max {
  font-size: 9px;
  padding: 0 3px;
  border-radius: 2px;
  font-weight: var(--font-medium);
  margin-left: 6px;
  background: rgba(62, 163, 255, 0.2);
  color: #5AE0FF;
  flex: 0 0 auto !important;
  width: auto !important;
}

.badge-max {
  background: rgba(255, 100, 150, 0.2);
  color: #FF7EB3;
}
</style>



