<?php

namespace App\Admin\Controllers;

use App\models\Post;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

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

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

        $grid->column('id', __('Id'));
        $grid->column('category_id', __('Category id'));
        $grid->column('user_id', __('User id'));
        $grid->title('Заголовок');
//        $grid->column('title', __('Title'));
        $grid->column('anons', __('Anons'));
        $grid->column('body', __('Body'));
        $grid->column('thumbnail', __('Thumbnail'));
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));

        return $grid;
    }

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

        $show->field('id', __('Id'));
        $show->field('category_id', __('Category id'));
        $show->field('user_id', __('User id'));
        $show->field('title', __('Title'));
        $show->field('anons', __('Anons'));
        $show->field('body', __('Body'));
        $show->field('thumbnail', __('Thumbnail'));
        $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 Post());

//        $form->number('category_id', __('Category id'));
//        $form->number('user_id', __('User id'));
        $form->text('title',"Заголовок", __('Title'));
//        $form->text('title', __('Title'));
        $form->text('anons', __('Anons'));
        $form->ckeditor('body','Текст новости');
        $form->image('thumbnail',"Изображение", __('Thumbnail'));

        return $form;
    }
}
