<?php

namespace Modules\Dashboard\Components;

use Livewire\Component;
use Modules\Dashboard\DashboardFactory;

class DashboardComponent extends Component
{

    private array $blocks = [];

    public function mount(DashboardFactory $factory): void
    {
        session()->put('menu', 'dashboard');
        session()->put('title', 'Dashboard');

        $this->blocks = $factory->load();
    }

    public function render(): string
    {
        return <<<'HTML'
            <x-page::layout>
                <div class="gap-6 md:grid-cols-2 xl:grid-cols-4 grid p-6">
                    @foreach($this->blocks as $block)
                        <x-ui::box title="{{$block->title()}}" :second="true">
                            <livewire:dynamic-component is="{{ get_class($block) }}" lazy></livewire:dynamic-component>
                        </x-ui::box>
                    @endforeach
                </div>
            </x-page::layout>
        HTML;
    }
}
