<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use App\Models\Category;
use Illuminate\Support\Facades\URL;

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        //
    }

    public function boot(): void
    {
        // Force HTTPS in production
        if (config('app.env') === 'production') {
            URL::forceScheme('https');
        }

        // Share all categories globally with every view (for nav/mega-menu)
        View::composer('*', function ($view) {
            $allCategories = cache()->remember('all_nav_categories', 3600, function () {
                return Category::orderBy('display_order')->orderBy('category_name')->get();
            });
            $view->with('allCategories', $allCategories);
        });
    }
}
