<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        if (app()->environment() !== 'local') {
            \Illuminate\Support\Facades\URL::forceScheme('https');
        }

        try {
            if (\Illuminate\Support\Facades\Schema::hasTable('settings')) {
                $activeTheme = \App\Models\Setting::where('key', 'active_theme')->value('value') ?? 'default';
                
                // Jika folder tema eksis, maka prioritas render diubah ke sana.
                $themePath = resource_path('views/themes/' . $activeTheme);
                if (file_exists($themePath)) {
                    \Illuminate\Support\Facades\View::prependLocation($themePath);
                }
            }
        } catch (\Exception $e) {
            // Ignore if DB not ready (e.g., during initial migrate)
        }
    }
}
