<?php

namespace App\Admin\Controllers;

use App\Models\Accident;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class AccidentController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Accident(), function (Grid $grid) {

            $grid->column('student_id')->using(config('map.students'));
            $grid->column('happen_time');
            $grid->column('situation_detail');
            $grid->column('creator_user_id')->using(config('map.teachers'));
           
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Accident(), function (Show $show) {
            $show->field('id');
            $show->field('student_id');
            $show->field('happen_time');
            $show->field('situation_detail');
            $show->field('creator_user_id');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Accident(), function (Form $form) {
            $form->text('student_id');
            $form->text('happen_time');
            $form->text('situation_detail');
            $form->text('creator_user_id');
        });
    }
}
