<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use App\Models\Category;
use App\Models\Order;
use App\Models\DeliveryMan;

class ViewServiceProvider extends ServiceProvider
{
    public function register()
    {
        //
    }

    public function boot()
    {
        View::composer('partials.header', function ($view) {
            $view->with('categories', Category::with('subcategories')->get());
        });

        View::composer('partials.admin_sidebar', function ($view) {
            $orderStatusCounts = Order::selectRaw('order_status, count(*) as count')
                ->groupBy('order_status')
                ->pluck('count', 'order_status')
                ->toArray();

            $newJoiningRequestCount = DeliveryMan::where('status', 'pending')->count();

            $view->with([
                'orderStatusCounts' => $orderStatusCounts,
                'newJoiningRequestCount' => $newJoiningRequestCount
            ]);
        });
    }
}