<?php

namespace App\Admin\Controllers;

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

class StudentController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Student(), function (Grid $grid) {
            //$grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('sex')->using(config('map.sex'));
            $grid->column('month_old');
            $grid->column('join_garden_time');
            $grid->column('parent_name');
            $grid->column('class_id')->using(config('map.class'));
            $grid->disableCreateButton();
            $grid->disableViewButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->like('name')->width(4);
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Student(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('sex');
            $show->field('month_old');
            $show->field('join_garden_time');
            $show->field('parent_name');
            $show->field('class_id');
            $show->field('name_en');
            $show->field('blood_type');
            $show->field('hypersensitive_source');
            $show->field('past_medical_history');
            $show->field('birthday');
            $show->field('exclusive_consultant_name');
            $show->field('exclusive_consultant_phone');
            $show->field('home_address');
            $show->field('hobby');
            $show->field('family_lang');
            $show->field('sleep_habits_and_others');
            $show->field('first_communication_of_parents');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Student(), function (Form $form) {
            //$form->display('id');
            $form->row(function (Form\Row $row) {
                $row->width(6)->text('name')->required()->placeholder('请输入中文名');
                $row->width(6)->text('name_en')->placeholder('请输入英文名');
            });
            $form->row(function (Form\Row $row) {
               $row->width(6)->select('sex')->options(config('map.sex'));
               $row->width(6)->select('blood_type')->options(config('map.blood_type'));
            });
            $form->row(function (Form\Row $row) {
               $row->width(12)->text('hypersensitive_source');
            });
            $form->row(function (Form\Row $row) {
               $row->textarea('past_medical_history')->required();
            });
            $form->row(function (Form\Row $row) {
               $row->width(6)->text('birthday')->required();
               $row->width(6)->text('join_garden_time');
            });
            $form->row(function (Form\Row $row) {
               $row->width(6)->text('exclusive_consultant_name')->placeholder('请输入专属顾问名');
               $row->width(6)->text('exclusive_consultant_phone')->placeholder('请输入专属顾问联系方式');
            });
            $form->row(function (Form\Row $row) {
               $row->width(6)->text('parent_name')->placeholder('请输入家长名');
           });
            $form->row(function (Form\Row $row) {
               $row->text('home_address');
            });
            $form->row(function (Form\Row $row) {
               $row->width(6)->text('hobby')->placeholder('请输入喜好');
               $row->width(6)->text('family_lang')->placeholder('请输入家庭语言');
           });
            $form->row(function (Form\Row $row) {
               $row->text('sleep_habits_and_others');
            });
            $form->row(function (Form\Row $row) {
               $row->textarea('first_communication_of_parents');
            });
            // $form->text('month_old');
            // $form->text('class_id');
        });
    }
}
