<?php

namespace App\Livewire;

use App\Models\Episode;
use Livewire\Component;

class ViewCount extends Component
{
    public $episodeId = 0;

    public $viewCount = 0;

    public function mount(Episode $episode)
    {
        $this->episodeId = $episode->id;
        $this->viewCount = $episode->view_count;
    }

    public function update()
    {
        $this->viewCount = Episode::where('id', $this->episodeId)->firstOrFail()->view_count;
    }

    public function render()
    {
        return view('livewire.view-count');
    }
}
