<?php

namespace App\Admin\Controllers\UserManagement\DocterManagement;
use App\Models\DocterOrganization;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class SignUpController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '签约管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new DocterOrganization());
        $grid->disableCreateButton();
        $docter_id = \request('docter_id');
        $grid->filter(function ($filter){
            $filter->disableIdFilter();
            $filter->equal('docter_id','医生');
        });
        $grid->actions(function ($actions) {
            // 去掉删除
            $actions->disableDelete();
            // 去掉查看
            $actions->disableView();

            // 如果审核成功才能修改认证到期时间
            if($actions->row->state != 1){
                //去掉编辑
                $actions->disableEdit();
            }
        });
        $grid->model()->orderBy('id','desc');
        $grid->column('id', __('Id'));
        $grid->column('docter_id', __('医生id'));
        $grid->column('docter.name', __('医生姓名'));
        $grid->column('organization_id', __('机构id'));
        $grid->column('organization.name', __('机构名字'));
        $grid->column('state', __('审核状态'))->using([0=>'社区端待审核',1=>'审核成功',2=>'审核驳回',3=>'待审核']);
        $grid->column('authentication_time', __('签约时间'))->display(function ($time){
            if ($time == 0){
                return '';
            }else
            {
                return $time;
            }
        });
        $grid->column('authentication_end_time', __('签约到期时间'))->display(function ($time){
            if ($time == 0){
                return '';
            }else
            {
                return $time;
            }
        });
        $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(DocterOrganization::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('docter_id', __('Docter id'));
        $show->field('organization_id', __('Organization id'));
        $show->field('offices_id', __('Offices id'));
        $show->field('qualifications_id', __('Qualifications id'));
        $show->field('state', __('State'));
        $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 DocterOrganization());
        $form->datetime('authentication_end_time', __('签约到期时间'));
        return $form;
    }
}
