<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\BaseProductParameter;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Form\NestedForm;

class BaseProductParameterController extends AdminController
{
    public function index(Content $content)
    {
        return $content
            ->header('Product Parameter')
            ->description('')
            ->body($this->grid());
    }


    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new BaseProductParameter(), function (Grid $grid) {
            $grid->column('id','ID')->sortable();
            $grid->column('name');
            $grid->column('order')->orderable();
            $grid->column('enabled')->switch();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
            $grid->disableViewButton();
            $grid->showQuickEditButton();
            $grid->enableDialogCreate();
            $grid->disableEditButton();
            $grid->quickSearch('name');
        });
    }





    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {

        return Form::make(new BaseProductParameter(), function (Form $form) {
            $form->display('id');
            $form->text('name')->required();
            $form->table('content','Parameters', function (NestedForm $table) {
                $table->text('key')->required();
                $table->text('value')->required();
            })->default([
                ['key' => 'color', 'value' => 'white'],
            ]);
            $form->switch('enabled')->default(1);
        });
    }
}
