<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\DoctorCorrectionRepository;
use App\Models\DoctorCorrectionModel;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;

// 医师纠错
class DoctorCorrectionController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new DoctorCorrectionRepository(), function (Grid $grid) {
            $grid->model()->orderBy('id', 'DESC');

            $grid->column('id');
            $grid->column('is_handle')->switch();
            // $grid->column('doctor_id');
            $grid->column('doctor_name');
            $grid->column('content');
            // $grid->column('created_at');
            // $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel(); // 更改为 panel 布局
                $filter->expand(); // 默认展开搜索框

                $filter->like('doctor_name')->width(3);
                $filter->in('is_handle')->checkbox(DoctorCorrectionModel::IS_HANDLE_MAP)->width(3);
            });

            // 行按钮控制
            $grid->disableActions(); // 禁用按钮

            // 工具栏按钮控制
            $grid->disableCreateButton(); // 禁用创建按钮
            $grid->disableBatchActions(); // 禁用批量操作
        });
    }

    /**
     * Make a show builder.
     *
     * @param  mixed  $id
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new DoctorCorrectionRepository(), function (Show $show) {
            $show->field('id');
            $show->field('doctor_id');
            $show->field('doctor_name');
            $show->field('is_handle');
            $show->field('content');
            $show->field('created_at');
            $show->field('updated_at');

            $show->panel()->tools(function ($tools) {
                $tools->disableDelete(); // 禁止删除按钮
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new DoctorCorrectionRepository(), function (Form $form) {
            $form->display('id')->width(4);
            // $form->text('doctor_id')->readonly()->width(4);
            $form->text('doctor_name')->readonly()->width(4);
            $form->textarea('content')->readonly()->width(4);
            $form->switch('is_handle')->width(4);

            $form->display('created_at')->width(4);
            $form->display('updated_at')->width(4);

            // 右上角按钮控制
            $form->disableDeleteButton(); // 去掉删除按钮
        });
    }
}
