import { supabaseAdmin } from '@/lib/supabaseAdmin'
import { TutorialsClient, TutorialItem } from './TutorialsClient'

export const dynamic = 'force-dynamic'

export default async function AdminTutorialsPage() {
  const { data: tutorials, error } = await supabaseAdmin
    .from('tutorials')
    .select('*')
    .order('sort_order', { ascending: true })

  const items: TutorialItem[] = (tutorials || []).map((t: any) => ({
    id: t.id,
    title: t.title,
    description: t.description || '',
    category: t.category || 'basics',
    category_label: t.category_label || '🚀 Hızlı Başlangıç',
    duration: t.duration || '03:00',
    youtube_id: t.youtube_id,
    target_view: t.target_view,
    target_view_label: t.target_view_label,
    highlights: Array.isArray(t.highlights) ? t.highlights : [],
    sort_order: t.sort_order || 0,
    is_active: t.is_active !== false,
    created_at: t.created_at,
  }))

  return <TutorialsClient initialTutorials={items} />
}
