<?php

namespace App\Distributor\Controllers;

use App\Distributor\Repositories\DistProductImage;
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 DistProductImageController extends AdminDistController
{
    /**
     * page index
     */
    public function index(Content $content)
    {
        return $content
            ->header('列表')
            ->description('全部')
            ->breadcrumb(['text'=>'列表','url'=>''])
            ->body($this->grid());
    }

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

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

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