<template>
  <section class="page-section block animate-slide-down">
    <div class="max-w-4xl mx-auto pt-32 px-6 pb-20">
      <!-- Loading state -->
      <div v-if="loading" class="flex justify-center items-center h-64">
        <div class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-art-accent"></div>
      </div>

      <div v-else-if="column">
        <!-- Header -->
        <div class="mb-16 text-center">
          <div class="inline-block mb-4 px-3 py-1 rounded-full border border-art-accent/30 text-art-accent text-xs font-mono">专栏</div>
          <h2 class="font-serif text-4xl italic text-white mb-6">{{ column.name }}</h2>
          <p class="text-art-muted max-w-lg mx-auto leading-relaxed">{{ column.description }}</p>
        </div>

        <!-- Posts List (Placeholder for now as we don't have column_posts API integrated fully yet) -->
        <!-- Since we don't have GetPostsByColumn API yet, we might need to fetch all posts and filter, 
             or update backend to support fetching posts by column. 
             The SQL has `column_posts` table. I need to check if backend `GetColumn` returns posts or if I need a separate endpoint.
        -->
        
        <div class="space-y-8">
           <div class="text-center py-10 border border-dashed border-white/10 rounded-lg">
             <p class="text-art-muted">专栏文章列表功能开发中...</p>
             <!-- 
               TODO: Fetch posts associated with this column.
               Backend needs to expose this.
               For now, I'll just show the column info.
             -->
           </div>
        </div>
      </div>

      <div v-else class="text-center py-20 text-art-muted">
        未找到专栏
      </div>
    </div>
  </section>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { fetchColumn, Column } from '../services/api'

const route = useRoute()
const column = ref<Column | null>(null)
const loading = ref(true)

onMounted(async () => {
  try {
    const id = parseInt(route.params.id as string)
    column.value = await fetchColumn(id)
  } catch (error) {
    console.error('Failed to fetch column:', error)
  } finally {
    loading.value = false
  }
})
</script>
