<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\EventoForm;
use App\Models\Evento;
use App\DataTables\EventoFormDataTable;
use App\DataTables\EventoFormDataTableEditor;
use Illuminate\Support\Facades\Auth;

class EventoFormController extends Controller
{
    public static $permission_group = "Form-Eventi";
    public static $permissions = [
        'view-evento_form' => 'Vedi',
        'create-evento_form' => 'Crea',
        'edit-evento_form' => 'Modifica',
        'delete-evento_form' => 'Elimina',
    ];

    public static function middleware(): array
    {
        return [
            new Middleware('permission:view-evento_form', only: ['index']), 
            new Middleware('permission:create-evento_form|edit-evento_form|delete-evento_form', only: ['store', 'update', 'destroy']),
        ];
    }



    public function index(Request $request, EventoFormDataTable $dataTable)
    {
        $dataTable->evento_id = $request->get('evento_id');
        return $dataTable->render('evento_form.index');
    }

    public function store(EventoFormDataTableEditor $editor)
    {
        $request = request();
        $input = $request->all();
        if($request->has('action')){
            switch($input['action']){
                case 'create':
                    if(!Auth::user()->can('create-evento_form')) return;
                    break;
                case 'edit':
                    if(!Auth::user()->can('edit-evento_form')) return;
                    break;
                case 'delete':
                    if(!Auth::user()->can('delete-evento_form')) return;
                    break;
            }
        }
        return $editor->process($request);
    }


}
