<template>
  <div class="publish-page">
    <div class="publish-container">
      <!-- 类别切换 -->
      <div class="tab-header">
        <div 
          class="tab-item" 
          :class="{ active: activeTab === 'publish' }"
          @click="switchTab('publish')"
        >
          发布作品
        </div>
        <div 
          class="tab-item" 
          :class="{ active: activeTab === 'manage' }"
          @click="switchTab('manage')"
        >
          作品管理
        </div>
      </div>
      
      <!-- 组件内容区域 -->
      <div class="tab-content">
        <PublishWork v-if="activeTab === 'publish'" />
        <ManageWork v-if="activeTab === 'manage'" />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import PublishWork from './components/PublishWork.vue'
import ManageWork from './components/ManageWork.vue'

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

// 当前激活的标签
const activeTab = ref('publish')

// 根据 URL 参数设置初始标签
const initTabFromQuery = () => {
  const tab = route.query.tab
  if (tab === 'manage') {
    activeTab.value = 'manage'
  } else {
    activeTab.value = 'publish'
  }
}

// 切换标签
const switchTab = (tab) => {
  activeTab.value = tab
  // 更新 URL 参数
  router.replace({
    path: route.path,
    query: { ...route.query, tab }
  })
}

// 监听路由变化
watch(() => route.query.tab, (newTab) => {
  if (newTab === 'manage') {
    activeTab.value = 'manage'
  } else if (newTab === 'publish') {
    activeTab.value = 'publish'
  }
})

onMounted(() => {
  initTabFromQuery()
})
</script>

<style scoped>
.publish-page {
  width: 100%;
  min-height: 800px;
  padding: 0;
  margin: 0;
  overflow: hidden;
  box-sizing: border-box;
}

.publish-container {
  width: 100%;
  box-sizing: border-box;
}

.tab-header {
  display: flex;
  gap: 20px;
  margin-bottom: 30px;
}

.tab-item {
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.3s ease;
  color: #666;
}

.tab-item:hover {
  background-color: #f5f5f5;
}

.tab-item.active {
  background-color: #e6f7ff;
  color: #1890ff;
}

.tab-content {
  min-height: 400px;
}
</style> 