<?php

namespace App\Admin\Controllers\Setting;

use App\Models\PayConfig;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class PayConfigController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(PayConfig::with(['setting']), function (Grid $grid) {

            $grid->disableColumnSelector();
            $grid->column('mini_app_id')->editable();
            $grid->column('mini_app_key')->display('*****');
            $grid->column('wechat_app_id')->editable();
            $grid->column('wechat_app_key')->display('*****');
            $grid->column('wechat_apiclient_key')->display('*****');
            $grid->column('wechat_apiclient_cert')->display('*****');
            $grid->column('alipay_app_id')->editable();
            $grid->column('alipay_app_key')->display('*****');
            $grid->column('alipay_app_secret')->display('*****');
            $grid->column('douyin_app_id')->editable();
            $grid->column('douyin_app_key')->display('*****');
            $grid->column('douyin_app_secret')->display('*****');
            $grid->column('setting.is_watch_auto_pay',trans('setting.fields.is_watch_auto_pay'))->switch();


            $grid->disableDeleteButton();
            $grid->disableCreateButton();
            $grid->disableViewButton();
            $grid->disableRowSelector();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new PayConfig(), function (Show $show) {
            $show->field('id');
            $show->field('mini_app_id');
            $show->field('mini_app_key');
            $show->field('wechat_app_id');
            $show->field('wechat_app_key');
            $show->field('wechat_apiclient_key');
            $show->field('wechat_apiclient_cert');
            $show->field('alipay_app_id');
            $show->field('alipay_app_key');
            $show->field('alipay_app_secret');
            $show->field('douyin_app_id');
            $show->field('douyin_app_key');
            $show->field('douyin_app_secret');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(PayConfig::with(['setting']), function (Form $form) {
            $form->display('id');
            $form->text('mini_app_id');
            $form->text('mini_app_key');
            $form->text('wechat_app_id');
            $form->text('wechat_app_key');
            $form->textarea('wechat_apiclient_key');
            $form->textarea('wechat_apiclient_cert');
            $form->text('alipay_app_id');
            $form->textarea('alipay_app_key');
            $form->textarea('alipay_app_secret');
            $form->text('douyin_app_id');
            $form->textarea('douyin_app_key');
            $form->textarea('douyin_app_secret');
            $form->switch('setting.is_watch_auto_pay',trans('setting.fields.is_watch_auto_pay'))->default(0);

            $form->disableViewButton();
            $form->disableDeleteButton();
            $form->disableListButton();
            $form->disableEditingCheck();
            $form->disableViewCheck();
        });
    }
}
