<?php

declare(strict_types=1);

namespace App\Modules\Sales\Presentation\Controllers;

use App\Core\Auth;
use App\Core\Response;
use App\Modules\Sales\Application\Services\SalesDashboardService;

final class SalesDashboardController
{
    public function __construct(private ?SalesDashboardService $service = null)
    {
        $this->service ??= new SalesDashboardService(db());
    }

    public function index(): void
    {
        Auth::requireLogin();
        \require_permission('sales.invoices.view');

        $data = $this->service->summary();

        Response::view('pages/sales/board', $data + [
            'page_title' => 'المبيعات',
            'breadcrumbs' => [['label' => 'المبيعات']],
        ]);
    }
}
