<?php

namespace App\Admin\Controllers\Activity;

use App\Models\ActivityCouponLog;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Illuminate\Routing\Controller as AdminController;

class LogController extends AdminController
{

    use HasResourceActions;

    protected $title = '回调记录';

    /**
     * Get content title.
     *
     * @return string
     */
    protected function title(): string
    {
        return $this->title;
    }

    /**
     * Index interface.
     *
     * @param  Content  $content
     * @return Content
     */
    public function index(Content $content): Content
    {
        return $content
            ->title($this->title())
            ->description($this->description['index'] ?? trans('admin.list'))
            ->body($this->grid());
    }

    protected function grid(): Grid
    {
        $grid = new Grid(new ActivityCouponLog);

        $grid->model()->latest();
        $grid->disableActions();
        $grid->disableCreateButton();

        $grid->filter(function ($filter) {
            $filter->column(1 / 2, function ($filter) {
                $filter->equal('code', '卡券编号');
                $filter->equal('type', '分类')->select(ActivityCouponLog::TYPES);
            });

            $filter->column(1 / 2, function ($filter) {
                $filter->equal('status', '状态')->select(ActivityCouponLog::STATUS);
                $filter->between('created_at', '开始时间')->datetime();
            });
        });

        $grid->column('id', '#ID#');
        $grid->column('code', '卡券编号');
        $grid->column('type', '分类')
            ->using(ActivityCouponLog::TYPES)
            ->label([
                1 => 'default',
                2 => 'warning',
                3 => 'info',
            ]);

        $grid->column('status', '状态')
            ->using(ActivityCouponLog::STATUS)
            ->label([
                1 => 'default',
                2 => 'warning',
                3 => 'info',
            ]);

        $grid->column('remark', '处理结果');
        $grid->column('created_at', '操作时间');
        return $grid;
    }
}
