<?php
/**
 * Template View: Link Button
 *
 * Generic link button.
 *
 * @package    BoostBot
 * @subpackage Templates/Views
 * @since      1.6.0
 *
 * @var string $url    Link URL.
 * @var string $text   Button text.
 * @var string $icon   Optional icon (emoji).
 * @var string $target Link target: '_self' or '_blank'.
 */

// phpcs:ignoreFile WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template-scope variables set by the includer, not true globals.

// Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// Validate required data
if ( empty( $url ) || empty( $text ) ) {
    return;
}

$target = $target ?? '_self';
?>

<a href="<?php echo esc_url( $url ); ?>" 
   class="bb-link-button"
   target="<?php echo esc_attr( $target ); ?>"
   <?php echo $target === '_blank' ? 'rel="noopener noreferrer"' : ''; ?>>
    <?php if ( ! empty( $icon ) ) : ?>
        <span class="bb-link-icon"><?php echo esc_html( $icon ); ?></span>
    <?php endif; ?>
    <span class="bb-link-text"><?php echo esc_html( $text ); ?></span>
    <?php if ( $target === '_blank' ) : ?>
        <span class="bb-link-external">↗</span>
    <?php endif; ?>
</a>
