<?php

namespace App\Admin\Controllers;

use App\Models\Suggestion;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class SuggestionController extends Controller {
	use HasResourceActions;

	/**
	 * Index interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function index(Content $content) {
		return $content->header ( '客户反馈' )->description ( '列表' )->body ( $this->grid () );
	}
	public function create(Content $content) {
		return $content->header ( 'Create' )->description ( 'description' )->body ( $this->form () );
	}

	/**
	 * Edit interface.
	 *
	 * @param mixed $id
	 * @param Content $content
	 * @return Content
	 */
	public function edit($id, Content $content) {
		return $content->header ( '客户反馈' )->description ( '编辑' )->body ( $this->form ()->edit ( $id ) );
	}

	/**
	 * Make a grid builder.
	 *
	 * @return Grid
	 */
	protected function grid() {
		$grid = new Grid ( new Suggestion () );

		$grid->model ()->orderBy ( 'created_at', 'desc' );
		$grid->id ( 'ID' )->sortable ();
		$grid->content ( '内容' );
		$grid->created_at ( '创建时间' );
		$grid->actions ( function ($actions) {
			$actions->disableView ();
		} );

		return $grid;
	}

	/**
	 * Make a show builder.
	 *
	 * @param mixed $id
	 * @return Show
	 */
	protected function detail($id) {
		$show = new Show ( Suggestion::findOrFail ( $id ) );

		return $show;
	}

	/**
	 * Make a form builder.
	 *
	 * @return Form
	 */
	protected function form() {
		$form = new Form ( new Suggestion () );
		$form->text ( 'title', '标题' )->required ();
		$form->ckeditor ( 'content' );
		$form->tools ( function (Form\Tools $tools) {
			// 去掉`删除`按钮
			$tools->disableDelete ();
			$tools->disableView ();
		} );

		// 去掉`重置`按钮
		$form->disableReset ();

		// 去掉`查看`checkbox
		$form->disableViewCheck ();

		// 去掉`继续编辑`checkbox
		$form->disableEditingCheck ();

		$form->disableCreatingCheck ();
		return $form;
	}
}
