<?php

namespace App\Providers;

use App\Models\Solution;
use App\Settings\SiteSettings;
use App\Settings\SiteSocialSettings;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\View as ViewFacade;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\View;

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

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Model::unguard();

        $this->addSettingsToViews();
        $this->addSolutionsToViews();

        // logDB();
    }

    /**
     * Add settings to views
     */
    public function addSettingsToViews(): void
    {
        ViewFacade::composer(['web.layouts.app'], function (View $view) {
            $view->with('settings', app(SiteSettings::class));
            $view->with('socialMedia', app(SiteSocialSettings::class));
        });
    }

    /**
     * Add solutions to views
     */
    public function addSolutionsToViews(): void
    {
        ViewFacade::composer(['web.layouts.navigation.header'], function (View $view) {
            $view->with('solutions', Solution::query()->latest()->get());
        });
    }
}
