<?php

namespace App\Providers;

use App\Models\Admin\Language;
use Illuminate\Support\Facades\App;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Blade;
use App\View\Composers\SettingComposer;
use Illuminate\Support\ServiceProvider;
use App\View\Composers\LanguageComposer;
use App\View\Composers\CountriesComposer;
use App\View\Composers\NavigationComposer;

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

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        View::composer('*', NavigationComposer::class);
        View::composer('*', SettingComposer::class);
        View::composer('*', LanguageComposer::class);
        View::composer('*', CountriesComposer::class);

        //$languages = Language::where('status', 1)->get();

        $supportedLocales = [];

        // foreach ($languages as $language) {
        //     $supportedLocales[$language->short] = [
        //         'name' => $language->title,
        //         'script' => 'Latn',
        //         'native' => $language->title,
        //         'regional' => $language->code
        //     ];
        // }

        $supportedLocales["tr"] = [
            'name' => "Türkçe",
            'script' => 'Latn',
            'native' => "Türkçe",
            'regional' => "tr-TR"
        ];

        config(['laravellocalization.supportedLocales' => $supportedLocales]);

        Paginator::useBootstrapFive();

        $agent = app('agent');

        Blade::if('mobile', function () use ($agent) {
            return $agent->isMobile();
        });

        Blade::if('desktop', function () use ($agent) {
            return $agent->isDesktop();
        });

        Blade::if('tablet', function () use ($agent) {
            return $agent->isTablet();
        });
    }
}
