<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\UserMember;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserMemberController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserMember(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('title');
            $grid->column('type')->display(function (){
                if($this->type == 1){
                    return '连续包月';
                }else{
                    return '一次性支付';
                }
            })->label();
            $grid->column('describe');
            $grid->column('money');
            $grid->column('month');
            $grid->column('updated_at')->sortable();
            $grid->disableFilter();
            $grid->disableViewButton();
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableQuickEdit();
                $actions->disableView();
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserMember(), function (Show $show) {
            $show->field('id');
            $show->field('title');
            $show->field('describe');
            $show->field('money');
            $show->field('content');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserMember(), function (Form $form) {
            $form->display('id')->width(4);
            $form->radio('type')->options([
                    1 => '连续包月',
                    2 => '一次性支付',
                ])->default(1);
            $form->text('title')->width(4)->required();
            $form->text('describe')->width(4);
            $form->decimal('money')->width(4)->required();
            $form->number('month')->min(1)->width(4)->default(1)->required();
//            $form->editor('content');
            $form->disableViewButton();
            $form->disableDeleteButton();
        });
    }
}
