<?php

namespace Modules\Member;

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

class TestersBlock extends Block
{

    private $months = 8;

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

    public function mount(): void
    {
        $this->members = Member::whereHas('memberships', fn ($q) => $q->isTrying())
            ->with('memberships', fn ($q) => $q->isTrying())
            ->get();
    }

    public function title(): string
    {
        return 'Endende Schhnupperzeiten';
    }

    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>
                    <span class="mr-2 text-sm tex-gray-600">{{ $member->memberships->first()->from->addWeeks($this->months)->format('d.m.Y') }}</span>
                    <span class="text-xs tex-gray-600">{{ $member->memberships->first()->from->addWeeks($this->months)->diffForHumans() }}</span>
                </div>
                @endforeach
            </div>
        HTML;
    }
}
