<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\CategoryController;
use App\Http\Controllers\AuthorController;
use App\Http\Controllers\SitemapController;
use App\Http\Controllers\SubscriberController;
use App\Http\Controllers\StaticPageController;

// Robots.txt
Route::get('/robots.txt', function () {
    return response(file_get_contents(base_path('robots.txt')), 200)
        ->header('Content-Type', 'text/plain');
});

// Core pages
Route::get('/',               [HomeController::class, 'index'])->name('index');
Route::get('/search',         [HomeController::class, 'search'])->name('search');

// Static pages (use controller so ViewComposer allCategories works in header)
Route::get('/about',          [StaticPageController::class, 'about'])->name('about');
Route::get('/privacy-policy', [StaticPageController::class, 'privacyPolicy'])->name('privacyPolicy');

// Category & Author
Route::get('/category/{slug}', [CategoryController::class, 'show'])->name('category.show');
Route::get('/author/{slug}',   [AuthorController::class,   'show'])->name('author.show');

// Subscribe (POST)
Route::post('/subscribe', [SubscriberController::class, 'store'])->name('subscribe');

// Sitemaps
Route::get('/sitemap.xml',            [SitemapController::class, 'index']);
Route::get('/sitemap-news.xml',       [SitemapController::class, 'news']);
Route::get('/sitemap-articles.xml',   [SitemapController::class, 'articles']);
Route::get('/sitemap-pages.xml',      [SitemapController::class, 'pages']);
Route::get('/sitemap-categories.xml', [SitemapController::class, 'categories']);
Route::get('/sitemap-authors.xml',    [SitemapController::class, 'authors']);

// Article detail — MUST be last
Route::get('/{category}/{slug}', [HomeController::class, 'show'])->name('news.show');
