<?php

namespace App\Admin\Controllers\UserManagement\BmUser;

use App\Admin\Actions\backstage\User\MapDepot;
use App\Admin\Actions\backstage\User\Suggests;
use App\Models\Patient;
use Encore\Admin\Controllers\AdminController;
use App\Admin\Actions\backstage\User\service;
use Illuminate\Http\Request;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class UserPatientsController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '患者列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Patient());
        $grid->disableCreateButton();
        $uesr_id = \request('user_id');
        $grid->filter(function ($filter){
            $filter->disableIdFilter();
            $filter->equal('user_id','用户id');
            $filter->equal('id','患者id');
            $filter->like('name','患者姓名');
        });
        $grid->disableActions();
        $grid->model()->orderBy('id','desc');
        $grid->column('id', __('患者id'));
        $grid->column('user_id', __('用户id'));
        $grid->column('name', __('患者姓名'));
        $grid->column('sex', __('性别'))->using([0=>'未知',1=>'男',2=>'女',]);
        $grid->column('avatar', __('头像'))->lightbox(['width' =>'', 'height' => 30]);
        $grid->column('age', __('年龄'));
        $grid->column('email', __('邮箱'));
        $grid->column('phone', __('联系电话'));
        $grid->column('address', __('家庭住址'))->limit(20,'...');
        $grid->column('guardian_name', __('监护人姓名'));
        $grid->column('card_type', __('证件类型'))->using([1=>'身份证',2=>'护照']);
        $grid->column('card_number', __('证件号'));
        $grid->column('social_card_number', __('社保卡号'));
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('更新时间'));

        return $grid;
    }

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

        $show->field('id', __('档案id'));
        $show->field('user_id', __('用户id'));
        $show->field('name', __('姓名'));
        $show->field('sex', __('性别'))->using([0=>'未知',1=>'男',2=>'女',]);
        $show->field('avatar', __('头像'))->image();
        $show->field('card_img_url', __('身份证正面照片'))->image();
        $show->field('card_back_img_url', __('身份证背面照片'))->image();
        $show->field('birthday', __('生日'));
        $show->field('age', __('年龄'));
        $show->field('email', __('邮箱'));
        $show->field('phone', __('联系电话'));
        $show->field('address', __('家庭住址'));
        $show->field('guardian_name', __('监护人姓名'));
        $show->field('relationship_type', __('与就诊人关系类型'))
            ->using([1=>'父亲',2=>'母亲',3=>'祖父',4=>'祖母',5=>'外祖父',6=>'外祖母',7=>'叔侄',8=>'其他']);
        $show->field('info', __('就诊信息'));
        $show->field('card_type', __('证件类型'))->using([1=>'身份证',2=>'护照']);
        $show->field('card_number', __('证件号'));
        $show->field('social_card_number', __('社保卡号'));
        $show->field('born_hospital', __('出生医院'));
        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('更新时间'));

        return $show;
    }

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