<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\AdminConfig;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use App\Service\AdminConfigService;
use Illuminate\Support\Facades\Log;

class AdminConfigController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new AdminConfig(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('config');
            $grid->column('status')->switch();
            $grid->column('type')->display('基础');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new AdminConfig(), function (Show $show) {
            $show->field('id');
            $show->field('config');
            $show->field('status');
            $show->field('type');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new AdminConfig(), function (Form $form) {
            $form->display('id');

            $form->select('type')->options(AdminConfigService::$typeLabel)->default(AdminConfigService::TYPE_DEFAULT);
            $form->text('config.oss.cdnDomain', __('外网地址'));
            $form->text('config.oss.access_id', __('APP_KEY'));
            $form->text('config.oss.access_key_secret', __('APP_SECRET'));
            $form->text('config.oss.bucket', __('BUCKET'));
            $form->text('config.oss.endpoint', __('ENDPOINT'));
            $form->switch('status');
            $form->submitted(function (Form $form) {
            });
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
