<?php

namespace Modules\Task\Http\Controllers\Admin;

use App\Admin\Traits\WithUploads;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Illuminate\Support\MessageBag;
use Modules\Linker\Traits\WithLinker;
use Modules\Task\Models\Category;
use Modules\Task\Models\Task;
use Modules\Task\Models\User;
use Modules\User\Models\AccountRule;
use Modules\User\Models\Identity;
use Modules\User\Models\IdentityMiddle;

class UserController extends AdminController
{

    use WithUploads, WithLinker;

    protected $title = '任务管理';

    public function grid(): Grid
    {
        $grid = new Grid(new User());

        $grid->disableCreateButton();
        $grid->disableActions();
        
        $grid->filter(function (Grid\Filter $filter) {
            $filter->column(1 / 3, function (Grid\Filter $filter) {
                $filter->equal('user_id', '下单用户')->select()->ajax(route('admin.user.users.ajax'));
            });
            $filter->column(1 / 3, function (Grid\Filter $filter) {
                $filter->equal('task_id', '任务')->select(Task::query()->pluck('title', 'id'));
            });
        });

        $grid->column('id', '#ID#');
        $grid->column('task.title', '任务');
        $grid->column('user.username', '用户');
        $grid->column('task.task_number', '任务量');
        $grid->column('total', '完成次数');
        $grid->column('task_at', '时间');

        return $grid;
    }
}
