<?php

declare(strict_types=1);

namespace PpPhp\Plugins;

use PpPhp\Core\PluginSupport;
use PpPhp\Core\ViewPlugin;

class PhoneNumber implements ViewPlugin
{
    use PluginSupport;

    public static function id(): string { return 'PhoneNumber'; }
    public static function label(): string { return 'Phone Number'; }
    public static function version(): string { return '1.1.0'; }
    public static function description(): string { return 'Renders a phone number as a clickable tel: link.'; }

    public static function render(mixed $value, array $settings): string
    {
        $display = trim((string) ($value ?? ''));
        if ($display === '') return '';
        // tel: target keeps only dial-safe characters; the label shows the original.
        $dial = preg_replace('/[^0-9+]/', '', $display);
        if ($dial === '') return self::e($display);
        return '<a href="tel:' . self::e($dial) . '">' . self::e($display) . '</a>';
    }

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