import { NextRequest, NextResponse } from 'next/server' import { requireAdmin } from '@/lib/admin-auth' import { createServiceClient } from '@/lib/supabase' export async function GET() { const check = await requireAdmin() if (check instanceof NextResponse) return check const db = createServiceClient() const [{ data: content }, { data: badges }] = await Promise.all([ db.from('hero_content').select('*').limit(1).single(), db.from('hero_badges').select('*').order('reihenfolge'), ]) return NextResponse.json({ content: content ?? null, badges: badges ?? [] }) } export async function PATCH(req: NextRequest) { const check = await requireAdmin() if (check instanceof NextResponse) return check const body = await req.json() const db = createServiceClient() const { data: existing } = await db.from('hero_content').select('id').limit(1).single() const fields = { site_name: body.site_name ?? 'Musterfirma', site_tagline: body.site_tagline ?? '', eyebrow_text: body.eyebrow_text ?? 'Ihr Slogan hier', headline1: body.headline1 ?? 'Wir lieben Qualität.', headline2: body.headline2 ?? 'Ihre Kunden auch.', subtext1: body.subtext1 ?? '', subtext2: body.subtext2 ?? '', cta1_text: body.cta1_text ?? 'Jetzt anfragen', cta1_href: body.cta1_href ?? '#kontakt', cta2_text: body.cta2_text ?? 'Unsere Leistungen', cta2_href: body.cta2_href ?? '#leistungen', updated_at: new Date().toISOString(), } const { error } = existing ? await db.from('hero_content').update(fields).eq('id', existing.id) : await db.from('hero_content').insert(fields) if (error) return NextResponse.json({ error: error.message }, { status: 500 }) return NextResponse.json({ success: true }) }