<?php

namespace App\Livewire\Dashboard\Client;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Http;
use Livewire\Attributes\Computed;
use \App\Models\{Course as Data};
use Livewire\Attributes\Layout;
use Livewire\Component;

class Course extends Component
{
    public $search,$baseUrl;

    #[Layout('layouts.dashboard.app')]
    public function render() : View
    {
        return view('livewire.dashboard.client.course');
    }

    public function mount() {
        $this->baseUrl = url('api');         
    }

    #[Computed]
    public function courses () {
        //$response = Http::get("{$this->baseUrl}/dashboard/cursos");
        //if ($response->successful()) {
           // $json = $response->json('data') ?? [];
       // }

        return Data::query()->when($this->search, fn ($q) => $q->where('course_name', "like", "%{$this->search}%"))->get();
    }
}
