<?php

namespace App\Admin\Controllers;

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

class PromotionController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Config(), function (Grid $grid) {
            $grid->model()->whereIn('id', [14]);
            $grid->column('id')->sortable();
            $grid->column('desc', '标题');
            $grid->column('value', '推广背景图')->image();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->disableDeleteButton();
            $grid->disableCreateButton();
            $grid->disableViewButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Config(), function (Show $show) {
            $show->field('id');
            $show->field('key');
            $show->field('value');
            $show->field('desc');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Config(), function (Form $form) {
            $form->display('id');
            $form->image('value', '推广背景图')->disk('oss')->autoUpload()->saving(function ($res) {
                return $res;
            })->required();
            $form->display('desc', '标题');
            $form->disableViewButton();
            $form->disableDeleteButton();
        });
    }
}
