<?php

namespace Modules\Prevention;

use Modules\Dashboard\Block;
use App\Member\Member;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;

class EfzPendingBlock extends Block
{

    /**
     * @var Collection<Member>
     */
    public Collection $members;

    public function mount(): void
    {
        $this->members = Member::where(function ($query) {
            return $query->where('efz', '<=', now()->subYears(5)->endOfYear())
                ->orWhereNull('efz');
        })
            ->whereCurrentGroup()
            ->orderByRaw('lastname, firstname')
            ->whereHas('memberships', fn ($builder) => $builder->isLeader()->active())
            ->get();
    }

    public function title(): string
    {
        return 'Ausstehende Führungszeugnisse';
    }

    public function render(): string
    {
        return <<<'HTML'
            <div>
                @foreach($members as $member)
                <div class="flex mt-2 items-center leading-none text-gray-100">
                    <span class="grow">{{$member->fullname}}</span>
                </div>
                @endforeach
            </div>
        HTML;
    }
}
