<?php

namespace Modules\Mall\Http\Controllers\Admin;

use App\Admin\Traits\WithUploads;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Modules\Linker\Traits\WithLinker;
use Modules\Mall\Models\Banner;
use Modules\Mall\Models\Video;

class VideoController extends AdminController
{

    use WithUploads,
        WithShop,
        WithLinker;

    public $title = "视频管理";

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

        $grid->filter(function (Grid\Filter $filter) {
            $filter->column(1 / 3, function (Grid\Filter $filter) {
                $filter->like('name', '视频名称');
            });
            $filter->column(1 / 3, function (Grid\Filter $filter) {
                $filter->equal('status', '状态')->radio([
                    0 => '禁用',
                    1 => '正常',
                ]);
            });
        });


        $grid->column('id', '#ID#');
        $grid->column('name', '视频名称');
        $grid->column('cover', '封面地址')->image('', 60, 60);
        $grid->column('path', '视频地址')
            ->display(function () {
                return $this->path_url;
            });
        $grid->column('status', '状态')->switch();
        $grid->column('created_at', '创建时间');

        return $grid;
    }

    protected function form(): Form
    {
        $form = new Form((new Video())->disableModelCaching());

        $form->text('name', '视频标题')->required();
        $this->cover($form);
        $this->video($form);
        $form->switch('status', '显示')->default(1);

        return $form;
    }

}
