<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Trait Sifency_Render_Trait
 *
 * Provides a reusable method to render the final HTML for a meta item widget.
 */
trait Sifency_Render_Meta_Trait {
	/**
	 * Renders the complete HTML wrapper for a meta item.
	 *
	 * This method handles the label, separator, and the final display value,
	 * including animation attributes and conditional HTML escaping.
	 *
	 * @param string $display_text      The final text or HTML to display.
	 * @param string $animation_attrs   The string of animation data attributes.
	 * @param bool   $is_html           Set to true if $display_text contains HTML (like a link) that should not be escaped.
	 */
	protected function render_sifency_meta_item( $display_text, $animation_attrs = '', $is_html = false ) {
		$settings = $this->get_settings_for_display();

		?>
		<div class="sifency-meta-item" <?php echo $animation_attrs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
			<div class="sifency-meta-item-inner">
				<?php if ( 'yes' === $settings['show_label'] && ! empty( $settings['label_text'] ) ) : ?>
					<span class="sifency-label-style">
						<?php echo esc_html( $settings['label_text'] ); ?>
					</span>
				<?php endif; ?>

				<?php if ( 'yes' === $settings['show_separator'] && ! empty( $settings['separator_text'] ) ) : ?>
					<span class="sifency-separator-style">
						<?php echo esc_html( $settings['separator_text'] ); ?>
					</span>
				<?php endif; ?>

				<span class="sifency-meta-style">
					<?php
					if ( $is_html ) {
						echo wp_kses_post( $display_text );
					} else {
						echo esc_html( $display_text );
					}
					?>
				</span>
			</div>
		</div>
		<?php
	}
}