<?php
/**
 * Template View: CTA Button
 *
 * A call-to-action button.
 *
 * @package    BoostBot
 * @subpackage Templates/Views
 * @since      1.6.0
 *
 * @var string $text    Button text.
 * @var string $url     Button URL.
 * @var string $style   Button style: 'primary', 'secondary', 'outline', 'gradient'.
 * @var string $icon    Optional icon (emoji or text).
 * @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( $text ) || empty( $url ) ) {
    return;
}

$style  = $style ?? 'primary';
$target = $target ?? '_self';
$btn_class = 'bb-cta-' . sanitize_html_class( $style );
?>

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