<?php

namespace App\Admin\Controllers\UserManagement\DocterManagement;

use App\Models\Docter;
use App\Models\DocterTimes;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ChatController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '图文服务配置列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new DocterTimes());
        $grid->disableCreateButton();
        $grid->disableActions();
        $grid->disableBatchActions();
        $docter_id = request('docter_id');
        $grid->model()->where('docter_id',$docter_id)->where('type',2);
        $grid->column('id', __('Id'));
        $grid->column('docter_id', __('医生id'));
        $grid->column('docter.avatar', __('医生头像'))->lightbox(['width' =>'', 'height' => 30]);
        $grid->column('docter.name', __('医生姓名'));
        $grid->column('type', __('类型'))->using([1=>'电话咨询',2=>'图文咨询',3=>'门诊咨询',4=>'疫苗预约接种',5=>'儿保预约',6=>'服务包',7=>'充值']);
        $grid->column('base_price', __('基础价格'));
        $grid->column('am', __('上午服务时间'))->display(function (){
            $service_time = DocterTimes::where('docter_id',$this->docter_id)->where('id',$this->id)->value('service_time');
            $arr = json_decode($service_time);
            $obj_arr = object_array($arr);
            if (empty($obj_arr[1]))
            {
                return '无';
            }else
            {
                $str = $obj_arr[1]['amStartTime'].'-'.$obj_arr[1]['amEndTime'];
                return $str;
            }
        });
        $grid->column('pm', __('下午服务时间'))->display(function (){
            $service_time = DocterTimes::where('docter_id',$this->docter_id)->where('id',$this->id)->value('service_time');
            $arr = json_decode($service_time);
            $obj_arr = object_array($arr);
            if (empty($obj_arr[2]))
            {
                return '无';
            }else
            {
                $str = $obj_arr[2]['pmStartTime'].'-'.$obj_arr[2]['pmEndTime'];
                return $str;
            }
        });
        $grid->column('night', __('晚上服务时间'))->display(function (){
            $service_time = DocterTimes::where('docter_id',$this->docter_id)->where('id',$this->id)->value('service_time');
            $arr = json_decode($service_time);
            $obj_arr = object_array($arr);
            if (empty($obj_arr[3]))
            {
                return '无';
            }else
            {
                $str = $obj_arr[3]['nightStartTime'].'-'.$obj_arr[3]['nightEndTime'];
                return $str;
            }
        });
        $grid->column('person', __('服务人数'));
        $grid->column('updated_at', __('更新时间'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(DocterTimes::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('docter_id', __('Docter id'));
        $show->field('base_price', __('Base price'));
        $show->field('step_price', __('Step price'));
        $show->field('service_time', __('Service time'));
        $show->field('person', __('Person'));
        $show->field('type', __('Type'));
        $show->field('relation_id', __('Relation id'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new DocterTimes());

        $form->number('docter_id', __('Docter id'));
        $form->decimal('base_price', __('Base price'));
        $form->decimal('step_price', __('Step price'));
        $form->text('service_time', __('Service time'));
        $form->number('person', __('Person'));
        $form->number('type', __('Type'));
        $form->number('relation_id', __('Relation id'));

        return $form;
    }
}
