<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\BaseProductCategory;
use App\Admin\Repositories\BaseVideoCategory;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Admin;

class BaseVideoCategoryController extends AdminController
{
    /**
     * page index
     */
    public function index(Content $content)
    {
        return $content
            ->header('Video Category')
            ->description('all')
            ->breadcrumb(['text'=>'Video Category','url'=>''])
            ->body($this->grid());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {

        return Grid::make(new BaseVideoCategory(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name')->tree(true,true);
            $grid->column('parent_id');
            $grid->column('order')->orderable();
            $grid->column('enabled')->switch();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            //$grid->quickSearch('name');
            // 允许筛选
            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->expand();
                $filter->equal('name')->width(2);
                $filter->equal('enabled', 'Enabled')->select(config('dictionary.enabled'))->width(2);
            });
            //按钮
            $grid->disableViewButton();
            $grid->showQuickEditButton();
            $grid->enableDialogCreate();
            $grid->disableEditButton();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new BaseVideoCategory(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->select('parent_id', trans('Parent'))
                ->options(BaseVideoCategory::selectOptions())
                ->saving(function ($v) {
                    return (int) $v;
                });
            $form->switch('enabled')->default(1);
        });
    }
}
