<?php

namespace Modules\Linker\Traits;

use Encore\Admin\Form;
use Exception;
use Modules\Linker\Models\Linker;

trait WithLinker
{

    public function withUrl(Form $form, string $label = '链接地址'): Form
    {
        try {
            $links = Linker::pluck('title', 'id');
        } catch (Exception $e) {
            $links = [0 => '无链接'];
        }

        $form->divider('链接设置');
        $form->select('linker_id', $label)
             ->options($links);
        $form->select('linker_mode', '参数模式')
             ->options(Linker::MODES)
             ->default(Linker::MODE_OVERRIDE);
        $form->keyValue('linker_params', '替换参数');

        return $form;
    }

}