<?php

namespace App\Admin\Controllers;

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

class BannerController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Banner(), function (Grid $grid) {
            $grid->model()->orderByDesc('sort');
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('image')->image('',100);
            $grid->column('sort')->editable();
            $grid->column('is_opened')->switch();

            $grid->disableViewButton();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Banner(), function (Form $form) {
            $form->display('id');
            $form->text('name')->required();
            $form->image('image')->saveFullUrl()
                ->uniqueName()->autoUpload()
                ->autoSave(false)
                ->removable(false)
                ->width(4)
                ->required()->required();
            $form->number('sort');
            $form->radio('is_opened')
                ->options(config('global.bool_status'))
            ->default(1);


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

        });
    }
}
