<?php

namespace App\Admin\Controllers;

use App\Models\Share;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class ShareDataController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Share(), function (Grid $grid) {
            $grid->model()->with(['inviteData','pidData'])->orderByDesc('id');
            $grid->column('id')->sortable();
            $grid->column('inviteData.name','邀请人昵称');
            $grid->column('inviteData.avatar','邀请人头像')->image('',80,80);
            $grid->column('pidData.name','被邀请人昵称');
            $grid->column('pidData.avatar','被邀请人头像')->image('',80,80);
            $grid->column('diamond','获得次数');
            $grid->column('desc','备注');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->disableDeleteButton();
            $grid->disableViewButton();
            $grid->disableCreateButton();
            $grid->disableEditButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('desc');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Share(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('pid');
            $show->field('diamond');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Share(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('pid');
            $form->text('diamond');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
