<?php

namespace App\Distributor\Controllers;

use App\Distributor\Repositories\DistProductParameter;
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 DistProductParameterController extends AdminController
{
    /**
     * page index
     */
    public function index(Content $content)
    {
        return $content
            ->view('distributor.layouts.content')
            ->header(admin_trans( 'admin.product_parameter'))
            ->description(admin_trans('admin.all'))
            ->breadcrumb(['text'=>'list','url'=>''])
            ->body($this->grid());
    }

    /**
     * Edit interface.
     *
     * @param  mixed  $id
     * @param  Content  $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->view('distributor.layouts.content')
            ->translation($this->translation())
            ->title($this->title())
            ->description($this->description()['edit'] ?? trans('admin.edit'))
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param  Content  $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->view('distributor.layouts.content')
            ->translation($this->translation())
            ->title($this->title())
            ->description($this->description()['create'] ?? trans('admin.create'))
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new DistProductParameter(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('order');
            $grid->column('enabled');
            $grid->column('content');
            $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 DistProductParameter(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('order');
            $show->field('enabled');
            $show->field('content');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new DistProductParameter(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->text('order');
            $form->text('enabled');
            $form->text('content');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
