<?php

namespace App\Admin\Controllers\Setting;

use App\Models\PayConfig;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
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('douyin_app_id')->editable();
            $grid->column('douyin_app_secret')->display('*****');
            $grid->column('douyin_salt')->display('*****');
            $grid->column('douyin_token')->display('*****');

            $grid->column('kuaishou_app_id')->editable();
            $grid->column('kuaishou_app_secret')->display('*****');
            $grid->column('mini_app_id')->editable();
            $grid->column('mini_app_key')->display('*****');
            $grid->column('wechat_mch_id')->editable();
            $grid->column('wechat_mch_key')->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 form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(PayConfig::with(['setting']), function (Form $form) {
            $form->display('id');
            $form->text('douyin_app_id')->required();
            $form->text('douyin_app_secret')->required();
            $form->text('douyin_salt')->required();
            $form->text('douyin_token')->required();

            $form->text('kuaishou_app_id');
            $form->text('kuaishou_app_secret');
            $form->text('mini_app_id');
            $form->text('mini_app_key');
            $form->text('wechat_mch_id');
            $form->text('wechat_mch_key');

            $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();
        });
    }
}
