<?php

namespace App\Admin\Controllers;

use App\Models\Exam;
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 ExamController 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 Exam () );
		$grid->id ( 'ID' )->sortable ();

		$grid->title ( '标题' );
		$grid->pdf_url ( '报告地址' );
		$grid->created_at ( '创建时间' );
		$grid->actions ( function ($actions) {
			$actions->disableView ();
		} );

		$grid->filter ( function ($filter) {

			// $filter->disableIdFilter ();
		} );

		return $grid;
	}

	/**
	 * Make a form builder.
	 *
	 * @return Form
	 */
	protected function form() {
		$form = new Form ( new Exam() );		
		$form->text ( 'title', '标题' )->rules ( 'required' );
		$form->file('pdf_url','报告PDF');
		
		return $form;
	}
}
