<?php

namespace App\Livewire\DataForm;

use App\Models\Form;
use App\Models\FormBuilder;
use Livewire\WithPagination;
use Livewire\Component;
use Illuminate\Support\Facades\Crypt;

class DataEntry extends Component
{
    use WithPagination;

    public $table_id='';
    
    // public $findTable = '';

    // for view content details
    public $showId = '';

    public $redirect_id ='';

    public function mount($id) {
        $this->redirect_id = "data-enter|".$id;
        $this->table_id = Crypt::decryptString($id);
    }

    public function getTable($id)
    {
        $this->table_id = $id;
    }

    public function updatedSearch(){
        $this->resetPage();
    }

    public function showFormData($id){
        $this->showId = $id;
    }

    public function render()
    {
        // $query = FormBuilder::query();

        // Apply search term if present
        // if (!empty($this->findTable)) {
        //     $query->where('name', 'like', '%' . $this->findTable . '%');
        // }

        // $data = Form::find($this->showId);
        // $formInfo = FormBuilder::find($data->form_id ?? '');
        // $forms = !empty($formInfo->content) ? json_decode($formInfo->content) : '';

        // $tables = $query->paginate(15);
        return view('livewire.data-form.data-entry');

        // [
        //     'tables'=> $tables,
        //     'formInfo'=> $forms,
        // ]
    }
}
