<?php

namespace App\Admin\Controllers;

use App\Models\WeeklyReport;
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;
use App\Admin\Extensions\ReportExporter;

class ReportController 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) {
		$item=WeeklyReport::find($id);
		return $content->header ( '查看日报' )->
		// body 方法可以接受 Laravel 的视图作为参数
		body ( view ( 'admin.report.show' ,['item'=>$item]) );
	}

	/**
	 * 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 WeeklyReport () );
		$grid->model ()->orderBy ( 'id', 'desc' );
		$grid->id ( 'ID' )->sortable ();
		$grid->created_date ( '训练日期' );
		$grid->teacher_name ( '教练姓名' );
		$grid->disableCreateButton ();

		$grid->actions ( function ($actions) {
			// $actions->disableView ();
			// $actions->disableDelete();
			$actions->disableEdit ();
		} );

		$grid->filter ( function ($filter) {

			// $filter->disableIdFilter ();
		} );
		$grid->exporter(new ReportExporter());
		return $grid;
	}

	/**
	 * Make a show builder.
	 *
	 * @param mixed $id
	 * @return Show
	 */
	// protected function detail($id)
	// {
	// $show = new Show(WeeklyReport::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 WeeklyReport () );
		$form->text ( 'title', '标题' )->rules ( 'required' );
		$form->select ( 'category_id', '类型' )->options ( WeeklyReport::$typeArr );
		$form->image ( 'head_img', '日报主图' );
		$form->UEditor ( 'content', '正文' );
		return $form;
	}
	public function detail($content, $id) {
		return view ( 'admin.report.show' );
	}
}
