<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Response;

class SitemapController extends Controller
{
    public function index()
    {
        // Get active posts (only what search engines need)
        $posts = DB::table('posts')
            ->where('status', 'active')
            ->orderBy('id', 'DESC')
            ->select('id', 'title_bn', 'updated_at')
            ->get();

        // Return XML properly with caching (VERY IMPORTANT for Google)
        $xml = view('backend.sitemap', compact('posts'))->render();

        return Response::make($xml, 200)
            ->header('Content-Type', 'text/xml; charset=UTF-8')
            ->header('Cache-Control', 'public, max-age=86400')
            ->header('Pragma', 'public');
    }
}