<?php

namespace GriffinForms\Admin\Html\Elements;

class ExtensionBadge extends \GriffinForms\Admin\Html\Format
{
    protected string $name;
    protected string $badge_url;

    public function __construct(string $name = '', string $badge_url = '')
    {
        $this->name = trim($name);
        $this->badge_url = trim($badge_url);
    }

    public function html(): void
    {
        echo '<span class="gf-extension-badge">';

        if ($this->badge_url !== '') {
            echo '<img class="gf-extension-badge__image" src="' . esc_url($this->badge_url) . '" alt="' . esc_attr($this->name) . '">';
        } else {
            $badge = new \GriffinForms\Admin\Html\Elements\ProBadge($this->name !== '' ? $this->name : __('Extension', 'griffinforms-form-builder'), 'gradient');
            $badge->html();
        }

        echo '</span>';
    }
}
