<?php
/**
 * Template View: Email Button
 *
 * Click-to-email button.
 *
 * @package    BoostBot
 * @subpackage Templates/Views
 * @since      1.6.0
 *
 * @var string $email   Email address.
 * @var string $text    Button text (optional).
 * @var string $subject Pre-filled subject (optional).
 * @var string $body    Pre-filled body (optional).
 */

// 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( $email ) ) {
    return;
}

$text = $text ?? __( 'שלח אימייל', 'boostbot' );

// Build mailto URL
$mailto_url = 'mailto:' . $email;
$params = array();
if ( ! empty( $subject ) ) {
    $params[] = 'subject=' . rawurlencode( $subject );
}
if ( ! empty( $body ) ) {
    $params[] = 'body=' . rawurlencode( $body );
}
if ( ! empty( $params ) ) {
    $mailto_url .= '?' . implode( '&', $params );
}
?>

<a href="<?php echo esc_url( $mailto_url ); ?>" class="bb-email-button">
    <span class="bb-email-icon">✉️</span>
    <span class="bb-email-text"><?php echo esc_html( $text ); ?></span>
</a>
