<?php

namespace App\Admin\Controllers;

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

class ProductController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Product(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('cover_img');
            $grid->column('cases');
            $grid->column('origin_price');
            $grid->column('sale_price');
            $grid->column('sort');
            $grid->column('is_opened');
            $grid->column('tech_param');
            $grid->column('cad_model');
            $grid->column('cad_design');
            $grid->column('su_model');
            $grid->column('other');
            $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 Product(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('cover_img');
            $show->field('cases');
            $show->field('origin_price');
            $show->field('sale_price');
            $show->field('sort');
            $show->field('is_opened');
            $show->field('tech_param');
            $show->field('cad_model');
            $show->field('cad_design');
            $show->field('su_model');
            $show->field('other');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Product(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->text('cover_img');
            $form->text('cases');
            $form->text('origin_price');
            $form->text('sale_price');
            $form->text('sort');
            $form->text('is_opened');
            $form->text('tech_param');
            $form->text('cad_model');
            $form->text('cad_design');
            $form->text('su_model');
            $form->text('other');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
