<?php

declare(strict_types=1);

namespace PpPhp\Plugins;

use PpPhp\Core\EditPlugin;
use PpPhp\Core\PluginSupport;

/**
 * Read-only display of a value inside a form. Shows the value as plain text and
 * still SUBMITS it (via a named input + hidden mirror) so the field round-trips
 * unchanged instead of being dropped on save.
 */
class ReadOnlyControl implements EditPlugin
{
    use PluginSupport;

    public static function id(): string { return 'ReadOnlyControl'; }
    public static function label(): string { return 'Read Only'; }
    public static function version(): string { return '1.1.0'; }
    public static function description(): string { return 'Shows a value the user cannot edit, and preserves it on submit.'; }

    public static function render(string $fieldName, mixed $value, array $settings): string
    {
        $name = self::e($fieldName);
        $val  = self::e($value);
        return '<input type="text" value="' . $val . '" readonly tabindex="-1" class="form-control-plaintext" aria-readonly="true">'
            . '<input type="hidden" name="' . $name . '" value="' . $val . '">';
    }

    public static function settingsSchema(): array { return []; }
    public static function assets(): array { return ['js' => [], 'css' => []]; }
}
