<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\ExternalPrescription;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use App\Models\PharmacyModel;
use App\Admin\Extensions\ToolBar\Actions\ExternalPrescriptionImportAction;
class ExternalPrescriptionController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new ExternalPrescription(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('external_prescription_id');
            $grid->column('issue_at')->sortable();
            $grid->column('status');
            $grid->column('company_name');
            $grid->column('pharmacy_name');
            // $grid->column('pharmacy_id');
            $grid->column('agent');
            $grid->column('patient_name');
            $grid->column('patient_mobile');
            $grid->column('patient_gender');
            $grid->column('patient_age');
            $grid->column('patient_id_card');
            $grid->column('doctor_name');
            $grid->column('diagnosis');
            $grid->column('drug_info');
            $grid->column('pharmacist_name');
            $grid->column('review_at');
            $grid->column('pharmacist_attr');
            $grid->column('dispatcher');
            $grid->column('checker');
            $grid->column('dispenser');
            // $grid->column('created_at');
            // $grid->column('updated_at')->sortable();
            // 工具栏普通按钮
            $grid->tools(function ($tools) {
                $tools->append(new ExternalPrescriptionImportAction()); // 导入药品信息
            });
            
            $grid->filter(function (Grid\Filter $filter) {
                //$filter->equal('id');
                $filter->panel(); // 更改为 panel 布局
                $filter->expand(); // 默认展开搜索框
                $filter->equal('external_prescription_id','580处方单编号')->width(3);
                $filter->equal('pharmacy_id')->select(PharmacyModel::all()->pluck('name', 'id'))->width(3);
            });

            // 行按钮控制
            $grid->disableCreateButton(); // 禁用创建按钮
            $grid->disableDeleteButton(); // 禁用删除按钮
            $grid->disableEditButton(); // 禁用编辑按钮

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ExternalPrescription(), function (Show $show) {
            $show->field('id');
            $show->field('external_prescription_id');
            $show->field('issue_at');
            $show->field('status');
            $show->field('company_name');
            $show->field('pharmacy_name');
            $show->field('pharmacy_id');
            $show->field('agent');
            $show->field('patient_name');
            $show->field('patient_mobile');
            $show->field('patient_gender');
            $show->field('patient_age');
            $show->field('patient_id_card');
            $show->field('doctor_name');
            $show->field('diagnosis');
            $show->field('drug_info');
            $show->field('pharmacist_name');
            $show->field('review_at');
            $show->field('pharmacist_attr');
            $show->field('dispatcher');
            $show->field('checker');
            $show->field('dispenser');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ExternalPrescription(), function (Form $form) {
            $form->display('id');
            $form->text('external_prescription_id');
            $form->text('issue_at');
            $form->text('status');
            $form->text('company_name');
            $form->text('pharmacy_name');
            $form->text('pharmacy_id');
            $form->text('agent');
            $form->text('patient_name');
            $form->text('patient_mobile');
            $form->text('patient_gender');
            $form->text('patient_age');
            $form->text('patient_id_card');
            $form->text('doctor_name');
            $form->text('diagnosis');
            $form->text('drug_info');
            $form->text('pharmacist_name');
            $form->text('review_at');
            $form->text('pharmacist_attr');
            $form->text('dispatcher');
            $form->text('checker');
            $form->text('dispenser');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
