<?php

namespace App\Admin\Controllers;

use App\Models\Classes;
use App\Models\Article;
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;
use Illuminate\Http\Request;

class ClassController extends Controller {
	use HasResourceActions;

	/**
	 * Index interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function index(Content $content) {
		return $content->header ( '班级' )->description ( '列表' )->body ( $this->grid () );
	}

	/**
	 * Show interface.
	 *
	 * @param mixed $id
	 * @param Content $content
	 * @return Content
	 */
	public function show($id, Content $content) {
		return $content->header ( '班级' )->description ( 'description' )->body ( $this->detail ( $id ) );
	}

	/**
	 * 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 ) );
	}

	/**
	 * Create interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function create(Content $content) {
		return $content->header ( '班级' )->description ( '新增' )->body ( $this->form () );
	}

	/**
	 * Make a grid builder.
	 *
	 * @return Grid
	 */
	protected function grid() {
		$grid = new Grid ( new Classes );

		$grid->id ( 'ID' )->sortable ();
		$grid->name ( '班级名' );
		$grid->actions ( function ($actions) {
			$actions->disableView ();
		} );

		$grid->filter ( function ($filter) {

			// $filter->disableIdFilter ();
		} );

		return $grid;
	}

	/**
	 * Make a show builder.
	 *
	 * @param mixed $id
	 * @return Show
	 */
	// protected function detail($id)
	// {
	// $show = new Show(Article::findOrFail($id));
	//
	// $show->id('Id');
	// $show->name('Name');
	// $show->image('Image');
	// $show->start_at('Start at');
	// $show->end_at('End at');
	// $show->created_at('Created at');
	// $show->updated_at('Updated at');
	//
	// return $show;
	// }

	/**
	 * Make a form builder.
	 *
	 * @return Form
	 */
	protected function form() {
		$form = new Form ( new Classes() );		
		$form->text ( 'name', '班级名' )->rules ( 'required' );
		return $form;
	}
}
