<?php

namespace App\Livewire\Home;

use App\Models\Faq as FaqModel;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Layout;
use Livewire\Component;

#[Layout('components.layouts.home', [
    'title' => 'FAQs',
])]
class Faq extends Component
{
    public ?string $search = null;

    public function render(): View
    {
        $faqs = FaqModel::orderBy('sort_order')
            ->when($this->search, function ($query) {
                $query->where('question', 'like', '%'.$this->search.'%')
                    ->orWhere('answer', 'like', '%'.$this->search.'%');
            })
            ->get()
            ->toArray();

        return view('livewire.home.faqs', [
            'pageTitle' => 'FAQs',
            'pageDesc' => 'Daftar pertanyaan yang sering diajukan beserta jawabannya.',
            'faqs' => $faqs,
        ]);
    }
}
