<?php

namespace App\Livewire;

use Illuminate\Support\Collection;
use Livewire\Component;
use App\Models\Tag;
use App\Models\Category;
use Livewire\Attributes\Computed;

class CategoryFilter extends Component
{
    public ?Tag $filter = null;

    #[Computed]
    public function categories() : Collection {
        return $this->filter?->categories ?? Category::all();
    }

    public function setFilter(int $filter) : void {
        $this->filter = Tag::find($filter);
    }

    public function render()
    {
        return view('livewire.category-filter', [
            'tags' => Tag::all(),
        ]);
    }
}
