<?php

/*
 * This file is part of the Serenity package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Controller\Admin;

use CpCreation\VitiCore\Cart\Repository\CartRepository;
use CpCreation\VitiCore\Cart\Repository\WithdrawalRequestRepository;
use CpCreation\VitiCore\Marketing\Repository\ProductReviewRepository;
use CpCreation\VitiCore\Shop\Repository\ShopConfigRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class HomepageController extends AbstractController
{
    public function __construct(
        private readonly ShopConfigRepository $shopConfigRepository,
        private readonly CartRepository $cartRepository,
        private readonly WithdrawalRequestRepository $withdrawalRequestRepository,
        private readonly ProductReviewRepository $productReviewRepository,
    ) {}

    #[Route('', name: 'admin_homepage')]
    public function index(): Response
    {
        return $this->render('@CpCreationVitiCore/admin/homepage.html.twig', [
            'shopConfig' => $this->shopConfigRepository->findOne(),
            'todoCounts' => [
                'withdrawals' => $this->withdrawalRequestRepository->countPendingForAdmin(),
                'reviews' => $this->productReviewRepository->countPendingForAdmin(),
                'offlinePayments' => $this->cartRepository->countOfflineOrdersAwaitingPayment(),
                'deliveries' => $this->cartRepository->countPaidOrdersAwaitingDelivery(),
            ],
        ]);
    }
}
