<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\AdminBundle\Components\Offer;

use Ferienpass\CoreBundle\Entity\Attendance;
use Ferienpass\CoreBundle\Entity\Offer\OfferInterface;
use Knp\Menu\ItemInterface;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate;

#[AsTwigComponent('Admin:Offer:SummaryHeader')]
class SummaryHeader
{
    public OfferInterface $offer;
    public ?ItemInterface $menu = null;
    public bool $showThirdLine = true;
    public bool $showStatusSelect = false;
    public bool $showWorkflowButton = false;

    #[ExposeInTemplate]
    public function demand(): ?int
    {
        if (!$this->offer->getMaxParticipants()) {
            return null;
        }

        return (int) round($this->offer->getAttendances()->filter(static fn (Attendance $a) => !$a->isWithdrawn())->count() / $this->offer->getMaxParticipants() * 100);
    }
}
