import { NextResponse } from 'next/server'

export async function GET() {
    try {
        const strapiBaseUrl = process.env.NEXT_PUBLIC_STRAPI_BASE_URL || process.env.NEW_STRAPI_URL || "http://160.187.167.213"
        const baseUrl = strapiBaseUrl.replace(/\/+$/, "")
        
        // Fetch offerings and heading in parallel
        const [offeringsRes, headingRes] = await Promise.all([
            fetch(`${baseUrl}/api/offerings`, {
                headers: { Accept: "application/json" },
                next: { revalidate: 300 }
            }),
            fetch(`${baseUrl}/api/offering-text`, {
                headers: { Accept: "application/json" },
                next: { revalidate: 300 }
            })
        ])

        const offerings = offeringsRes.ok ? await offeringsRes.json() : null
        const heading = headingRes.ok ? await headingRes.json() : null

        return NextResponse.json({ offerings, heading }, {
            headers: {
                'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
            },
        })
    } catch (error) {
        console.error('Error fetching offerings:', error)
        return NextResponse.json({ error: 'Failed to fetch offerings' }, { status: 500 })
    }
}

