<?php

namespace App\Admin\Controllers;

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

class LeaveController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Leave(), function (Grid $grid) {
           
            $grid->column('student_id')->using(config('map.students'));
            $grid->column('leave_type')->using(config('map.leave_type'));
            $grid->column('reason');
            $grid->column('start_time');
            $grid->column('end_time');
            $grid->disableEditButton();
            $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 Leave(), function (Show $show) {
            $show->field('student_id')->using(config('map.students'));
            $show->field('reason');
            $show->field('leave_type')->using(config('map.leave_type'));
            $show->field('start_time');
            $show->field('end_time');
            $show->field('created_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Leave(), function (Form $form) {
            $form->display('id');
            $form->text('student_id');
            $form->text('reason');
            $form->text('start_time');
            $form->text('end_time');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
