<?php

namespace App\Admin\Controllers\OrdersManagement;

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

class ServicePackDetailsController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '服务包详情';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $order_id = \request('order_id');
        $grid = new Grid(new OrderPack());

        $grid->disableActions();
        $grid->filter(function ($filter){
            $filter->disableIdFilter();
            $filter->equal('order_id','订单id');
        });
        $grid->model()->orderBy('id','desc');
        $grid->column('id', __('id'));
        $grid->column('order_id', __('订单id'));
        $grid->column('service_pack_id', __('服务包id'));
        $grid->column('pack_name', __('服务包名称'));
        $grid->column('pack_price', __('服务包价格'))->display(function ($price){
            return $price/100;
        });
        $grid->column('phone_minutes', __('剩余电话分钟数'));
        $grid->column('chat_num', __('剩余图文咨询次数'));
        $grid->column('appoint_num', __('剩余门诊预约次数'));
        $grid->column('vaccine_limit_amount', __('剩余疫苗金额'));
        $grid->column('nurses_limit_amount', __('剩余儿保金额'));
        $grid->column('effective_days', __('有效天数'));
        $grid->column('start_time', __('开始时间'))->display(function ($time){
            return date('Y-m-d H:i:s',$time);
        });
        $grid->column('end_time', __('结束时间'))->display(function ($time){
            return date('Y-m-d H:i:s',$time);
        });
        return $grid;
    }

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

        $show->field('id', __('Id'));
        $show->field('order_id', __('Order id'));
        $show->field('service_pack_id', __('Service pack id'));
        $show->field('pack_name', __('Pack name'));
        $show->field('pack_intro', __('Pack intro'));
        $show->field('pack_price', __('Pack price'));
        $show->field('insurance_policy', __('Insurance policy'));
        $show->field('insurance_img_url', __('Insurance img url'));
        $show->field('team_id', __('Team id'));
        $show->field('phone_minutes', __('Phone minutes'));
        $show->field('chat_num', __('Chat num'));
        $show->field('appoint_num', __('Appoint num'));
        $show->field('vaccine_limit_amount', __('Vaccine limit amount'));
        $show->field('nurses_limit_amount', __('Nurses limit amount'));
        $show->field('effective_days', __('Effective days'));
        $show->field('start_time', __('Start time'));
        $show->field('end_time', __('End time'));
        $show->field('is_security', __('Is security'));
        $show->field('guardian_name', __('Guardian name'));
        $show->field('relationship_type', __('Relationship type'));
        $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 OrderPack());

        $form->number('order_id', __('Order id'));
        $form->number('service_pack_id', __('Service pack id'));
        $form->text('pack_name', __('Pack name'));
        $form->text('pack_intro', __('Pack intro'));
        $form->number('pack_price', __('Pack price'));
        $form->text('insurance_policy', __('Insurance policy'));
        $form->text('insurance_img_url', __('Insurance img url'));
        $form->number('team_id', __('Team id'));
        $form->number('phone_minutes', __('Phone minutes'));
        $form->number('chat_num', __('Chat num'));
        $form->number('appoint_num', __('Appoint num'));
        $form->number('vaccine_limit_amount', __('Vaccine limit amount'));
        $form->number('nurses_limit_amount', __('Nurses limit amount'));
        $form->number('effective_days', __('Effective days'));
        $form->number('start_time', __('Start time'));
        $form->number('end_time', __('End time'));
        $form->switch('is_security', __('Is security'));
        $form->text('guardian_name', __('Guardian name'));
        $form->switch('relationship_type', __('Relationship type'));

        return $form;
    }
}
