<?php

namespace App\View\Components;

use Closure;
use App\Models\Post;
use Illuminate\View\Component;
use Illuminate\Contracts\View\View;

class Comment extends Component
{
    public Post $post;

    public function __construct(Post $post)
    {
        $this->post = $post;
    }

    public function render(): View
   {
    $comments = $this->post->comments()
        ->where('active', 1)
        ->orderBy('created_at', 'desc')
        ->get();

       return view('components.comment', ['post' => $this->post, 'comments' => $comments]);
   }
}