<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use Inertia\Inertia;

class ShopDashboardController extends Controller
{
    public function index()
    {
        $shopUser = Auth::guard('shop')->user();

        $todayOrders = $shopUser->unlockOrders()
            ->whereDate('date', today())
            ->count();

        $pendingOrders = $shopUser->unlockOrders()
            ->where('status', 'pending')
            ->count();

        $completedOrders = $shopUser->unlockOrders()
            ->where('status', 'done')
            ->count();

        $totalIncome = $shopUser->unlockOrders()
            ->where('status', 'done')
            ->sum('service_price');

        $balance = $shopUser->getBalance();

        return Inertia::render('Shop/Dashboard', [
            'stats' => [
                'today_orders' => $todayOrders,
                'pending_orders' => $pendingOrders,
                'completed_orders' => $completedOrders,
                'total_income' => $totalIncome,
                'balance' => $balance,
            ],
        ]);
    }
}
