<?php

namespace App\Admin\Controllers;

use App\Models\Dishes;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class DishesController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'Dishes';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Dishes());

        $grid->column('id', __('Id'));
        $grid->column('name', __('Name'));
        $grid->column('price', __('Price'));
        $grid->column('weigh', __('Weigh'));
        $grid->column('category_id', __('Category id'));
        $grid->column('composition', __('Composition'));
        $grid->column('created_at', __('Created at'))->hide();
        $grid->column('updated_at', __('Updated at'))->hide();

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Dishes::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('price', __('Price'));
        $show->field('weigh', __('Weigh'));
        $show->field('category_id', __('Category id'));
        $show->field('composition', __('Composition'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Dishes());

        $form->textarea('name', __('Name'));
        $form->number('price', __('Price'));
        $form->number('weigh', __('Weigh'));
        $form->image('image');
        $form->text('categories.name');
        $form->textarea('composition', __('Composition'));

        return $form;
    }
}
