<?php

namespace App\Admin\Controllers\Program;

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

class NavBarController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new NavBar(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name')->editable();
            $grid->column('icon')->image('', 50);
            $grid->column('sort')->editable()->sortable();
            $grid->column('status')->switch('', true);

            $grid->disableCreateButton();
            $grid->disableBatchDelete();
            $grid->disableDeleteButton();
            $grid->disableViewButton();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new NavBar(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->image('icon')->saveFullUrl()
                ->uniqueName()->autoUpload()
                ->autoSave(false)
                ->removable(false)
                ->width(4)->required();
            $form->number('sort');
            $form->switch('status');

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