<?php

use Livewire\Component;
use App\Models\Faq;

return new class extends Component
{
    public $question = '';
    public $answer = '';
    public $sort_order = 0;
    public $status = 'published';

    public function render()
    {
        return $this->view()->layout('layouts::auth');
    }

    public function save()
    {
        $this->validate([
            'question' => 'required|min:5',
            'answer' => 'required|min:10',
            'sort_order' => 'required|integer',
            'status' => 'required|in:draft,published',
        ]);

        Faq::create([
            'question' => $this->question,
            'answer' => $this->answer,
            'sort_order' => $this->sort_order,
            'status' => $this->status,
        ]);

        session()->flash('message', 'FAQ created successfully.');
        return $this->redirect(route('admin.faqs'), navigate: true);
    }

    protected function view($data = [])
    {
        return app('view')->file('D:\02-my freelance\00-DR_Padhi\DR_PADHI\storage\framework/views/livewire/views/7e8eea3b.blade.php', $data);
    }
};
