<?php

namespace App\Admin\Controllers;

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

class DailyCareReportController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new DailyCareReport(), function (Grid $grid) {
            $grid->column('student_id')->using(config('map.students'));
            $grid->column('log_type')->using(config('map.log_type'));
            $grid->column('situation');
            $grid->column('log_user_id')->using(config('map.log_user_ids'));
            $grid->disableViewButton();
            $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 DailyCareReport(), function (Show $show) {
            $show->field('id');
            $show->field('student_id');
            $show->field('log_type');
            $show->field('situation');
            $show->field('log_user_id');
            $show->field('diet_json');
            $show->field('drink_json');
            $show->field('nurse_json');
            $show->field('defecation_json');
            $show->field('change_clothes_json');
            $show->field('emotion_json');
            $show->field('sleep_json');
            $show->field('clean_json');
            $show->field('health_json');
            $show->field('medication_json');
            $show->field('temperature_json');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new DailyCareReport(), function (Form $form) {
            $form->row(function (Form\Row $row) {
                $row->width(6)->select('student_id')->options(config('map.students'))->required();
            });
            $form->row(function (Form\Row $row) {
                $row->width(12)->table('diet_json', function (NestedForm $table) {
                    $table->text('eat','饮食');
                    $table->datetime('time','时间');
                    $table->text('volume','饮食量');
                    $table->textarea('remark','特别说明');
                });
            });

            $form->row(function (Form\Row $row) {
                $row->width(12)->table('drink_json', function (NestedForm $table) {
                    $table->text('drink','饮品')->required();
                    $table->datetime('time','时间');
                    $table->text('volume','饮用总量');
                    $table->textarea('remark','特别说明');
                });
            });

            $form->row(function (Form\Row $row) {
                $row->width(12)->table('nurse_json', function (NestedForm $table) {
                    $table->text('nurse','喂奶');
                    $table->datetime('time','时间');
                    $table->text('volume','饮用量');
                    $table->textarea('remark','特别说明');
                });
            });

            $form->row(function (Form\Row $row) {
                $row->width(12)->table('defecation_json', function (NestedForm $table) {
                    $table->text('defecation_type','排便类型');
                    $table->datetime('time','时间');
                    $table->text('status','状态');
                    $table->text('color','颜色');
                    $table->text('volume','量');
                    $table->text('red_ass','红屁股');
                    $table->radio('is_acerbity','是否发酸')->options([1=>'是',0=>'否']);
                    $table->image('pic','照片');
                    $table->radio('potty_training','如厕训练')
                    ->when(1,function(NestedForm $table){
                      $table->textarea('remark','如厕训练说明');
                    })
                    ->options([1=>'是',0=>'否']);
                    //$table->textarea('remark','如厕训练说明');
                });
            });
            $form->text('log_type');
            $form->text('situation');
            $form->text('log_user_id');

            $form->row(function (Form\Row $row) {
                $row->width(12)->table('change_clothes_json', function (NestedForm $table) {
                    $table->text('is_normal','是否正常');
                    $table->datetime('time','时间');
                    $table->textarea('red_ass','红屁股');
                });
            });

            $form->row(function (Form\Row $row) {
                $row->width(12)->table('emotion_json', function (NestedForm $table) {
                    $table->text('emotion','情绪');
                    $table->datetime('time','时间');
                });
            });

            $form->row(function (Form\Row $row) {
                $row->width(12)->table('sleep_json', function (NestedForm $table) {
                    $table->text('sleep_status','睡眠状态');
                    $table->datetime('time','时间');
                });
            });
            
            $form->row(function (Form\Row $row) {
                $row->width(12)->table('clean_json', function (NestedForm $table) {
                    $table->text('mouth_clean','口腔清洁');
                    $table->datetime('mouth_clean_time','口腔清洁时间');
                    $table->devider();
                    $table->text('nasal_clean_color','鼻涕清洁颜色');
                    $table->text('nasal_clean_shape','鼻涕清洁形状');
                    $table->text('nasal_clean_volume','鼻涕清洁量');
                    $table->datetime('nasal_clean_time','鼻涕清洁时间');
                    $table->datetime('time','时间');
                    $table->devider();
                    $table->radio('is_wash_head','是否洗头')->options([1=>'是',0=>'否']);
                    $table->select('is_change_diapers','更换尿布')->options([1=>'是',0=>'否']);
                    $table->select('is_change_clothes','更换衣物')->options([1=>'是',0=>'否']);
                    $table->datetime('time','时间');
                    $table->datetime('wash_ass_time','洗屁屁时间');
                });
            });

            $form->row(function (Form\Row $row) {
                $row->width(12)->table('health_json', function (NestedForm $table) {
                    $table->datetime('time','时间');
                    $table->select('symptom','症状')->options([1=>'是',0=>'否']);
                    $table->textarea('remark','其他说明');
                    
                });
            });

            $form->row(function (Form\Row $row) {
                $row->width(12)->table('medication_json', function (NestedForm $table) {
                    $table->datetime('time','时间');
                    $table->textarea('remark','其他说明');
                });
            });

            $form->row(function (Form\Row $row) {
                $row->width(12)->table('temperature_json', function (NestedForm $table) {
                    $table->datetime('time','时间');
                    $table->text('temperature','温度');
                    $table->select('temperature_type','体温种类')->options([1=>'摄氏度',0=>'华氏度']);
                });
            });
            $form->disableViewButton();
        });
    }
}
