<?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->column('id')->sortable();
            $grid->column('title');
            $grid->column('img_url')->image('',50);
            $grid->column('url');
            $grid->column('site')->using(['1'=>'动态首页']);

            $grid->column('status')->switch();
            $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 Banner(), function (Show $show) {
            $show->field('id');
            $show->field('title');
            $show->field('img_url')->image();
            $show->field('url');
            $show->field('site')->using(['1'=>'动态首页']);

            $show->field('status')->using(['隐藏','显示']);
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Banner(), function (Form $form) {
            $form->display('id');
            $form->text('title');
            $form->image('img_url')->uniqueName()->removable(false)->autoUpload();
            $form->text('url')->help('以http://或者https://开头');
            $form->radio('site')->options(['1'=>'动态首页'])->default(1);
            $form->switch('status')->options([0=>"隐藏",1=>"显示"])->default(1);
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
