<?php

namespace App\Livewire;

use App\Models\Episode;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;

class NavLiveSearch extends Component
{
    public $navSearch;

    protected $queryString = [
        'navSearch' => ['except' => '', 'as' => 's'],
    ];

    public function render()
    {
        $episodes = [];
        if ($this->navSearch != '') {
            $episodes = Episode::search($this->navSearch)
                ->when(Auth::guest(), fn ($query) => $query->whereNotIn('tags', ['Loli', 'Shota']))
                ->query(fn ($query) => $query->with(['gallery', 'studio']))
                ->take(7)
                ->get();
        }

        return view('livewire.nav-live-search', [
            'episodes' => $episodes,
            'query' => $this->navSearch,
            'hide' => empty($this->navSearch),
        ]);
    }
}
