<?php

namespace Modules\Cms\Http\Controllers\Admin;

use App\Admin\Traits\WithUploads;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Modules\Cms\Models\Storage;

class StorageController extends AdminController
{

    use WithUploads;

    protected $title = '素材管理';

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

        $grid->column('id', '#ID#');
        $grid->column('name', '素材标题');
        $grid->column('地址')->display(function () {
            return $this->cover_text;
        });

        return $grid;
    }

    public function form(): Form
    {
        $form = new Form(new Storage());

        $form->text('name', '素材标题')
             ->rules([
                 'required',
                 'max:255',
             ], [
                 'max' => '标题最大长度不能超过 :max 个字符',
             ])
             ->required();
        $this->cover($form);
        $form->url('url', '素材地址');

        return $form;
    }

}