<?php

use App\Http\Controllers\ContactController;
use App\Http\Controllers\PageController;
use Illuminate\Support\Facades\Route;

Route::get('/', [PageController::class, 'home'])->name('home');
Route::get('/about', [PageController::class, 'about'])->name('about');
Route::get('/services', [PageController::class, 'services'])->name('services');
Route::get('/portfolio', [PageController::class, 'portfolio'])->name('portfolio');
Route::get('/insights', [PageController::class, 'insights'])->name('insights');
Route::get('/insights/{slug}', [PageController::class, 'insightDetail'])->name('insight.detail');
Route::get('/privacy-policy', [PageController::class, 'privacyPolicy'])->name('privacy-policy');
Route::get('/contact', [ContactController::class, 'show'])->name('contact');
Route::post('/contact', [ContactController::class, 'submit'])->name('contact.submit');

Route::get('/sitemap.xml', function () {
    $urls = [
        ['loc' => url('/'),              'priority' => '1.0',  'changefreq' => 'weekly'],
        ['loc' => url('/about'),         'priority' => '0.8',  'changefreq' => 'monthly'],
        ['loc' => url('/services'),      'priority' => '0.9',  'changefreq' => 'monthly'],
        ['loc' => url('/portfolio'),     'priority' => '0.8',  'changefreq' => 'monthly'],
        ['loc' => url('/insights'),      'priority' => '0.7',  'changefreq' => 'weekly'],
        ['loc' => url('/contact'),       'priority' => '0.8',  'changefreq' => 'monthly'],
        ['loc' => url('/privacy-policy'),'priority' => '0.3',  'changefreq' => 'yearly'],
    ];

    $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
    $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
    foreach ($urls as $u) {
        $xml .= "  <url>\n";
        $xml .= "    <loc>{$u['loc']}</loc>\n";
        $xml .= "    <changefreq>{$u['changefreq']}</changefreq>\n";
        $xml .= "    <priority>{$u['priority']}</priority>\n";
        $xml .= "  </url>\n";
    }
    $xml .= '</urlset>';

    return response($xml, 200, ['Content-Type' => 'application/xml']);
})->name('sitemap');

Route::get('/robots.txt', function () {
    $content = "User-agent: *\nDisallow:\n\nSitemap: " . url('/sitemap.xml') . "\n";
    return response($content, 200, ['Content-Type' => 'text/plain']);
})->name('robots');
