<?php

namespace App\Admin\Controllers;

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

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

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->like('name')->width(2);

            });

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


    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Showroom(), function (Form $form) {
            $form->display('id');
            $form->text('name')->required();
            $form->image('cover_img','封面图（宽高比1.4:1）')->saveFullUrl()
                ->uniqueName()->autoUpload()
                ->autoSave(false)
                ->removable(false)
                ->width(4);
            $form->number('sort');
            $form->radio('is_opened')
                ->options(config('global.bool_status'))
                ->default(1);
            $form->editor('detail','案例(图片宽高比7.5:x)')->height(420);

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