<?php
defined( 'ABSPATH' ) || exit;

class Jalpi_Element_Badge extends Jalpi_Element {
    public static function type(): string { return 'badge'; }

    public function render( array $node, Jalpi_Renderer $renderer ): string {
        $id      = sanitize_html_class( $node['id'] ?? '' );
        $content = $node['content'] ?? [];
        $styles  = $node['styles']  ?? [];
        $text    = esc_html( $content['text']    ?? __( 'Badge', 'jalpi-page-builder' ) );
        $variant = sanitize_key( $content['variant'] ?? 'primary' );
        $a       = $renderer->get_css_attrs( $node );

        $renderer->add_css( '.jalpi-el.jalpi-' . $id . '{' . $renderer->styles_to_css( $styles ) . '}' );

        return '<span class="jalpi-el jalpi-badge jalpi-badge--' . esc_attr( $variant ) . ' jalpi-' . esc_attr( $id ) . $a['extra_cls'] . '"' . $a['id_attr'] . '>' . $text . '</span>';
    }
}
