<?php

namespace Modules\Post\Http\Livewire;

use Livewire\Component;
use Illuminate\Support\Facades\Storage;

use Modules\Post\Models\Post;

class PostsList extends Component
{
    public $count;
    public $category;
    public function mount()
    {

    }

    public function open($id)
    {
        $this->dispatch('showPostCardInModal', id: $id);
    }
    public function render()
    {
        $posts = Post::orderBy('id', 'desc')->visibleForUser();
        if ($this->category && $this->category != 'all')
            $posts = $posts->where('category', $this->category);

        if ($this->count)
            $posts = $posts->take($this->count)->get();
        else
            $posts = $posts->take(10)->get();

        return view('post::list.cards', [
            'posts' => $posts
        ]);
    }
}