<?php

namespace App\Livewire\FormBuilder;

use App\Models\FormBuilder;
use Livewire\Component;

class Index extends Component
{
    public function delete($id)
    {
        
        $form = FormBuilder::findOrFail($id);
        $form->delete();

        session()->flash('success', 'Form deleted successfully!');
        // $this->dispatch('$refresh');
        return $this->redirectRoute('form-builder', navigate: true);
    }

    public function render()
    {
        $forms = FormBuilder::all();
        return view('livewire.form-builder.index', compact('forms'));
    }
}
