<?php
/**
 * Template View: Coupon Card
 *
 * Displays a coupon with copy-to-clipboard functionality.
 * Requires Pro license.
 *
 * @package    BoostBot
 * @subpackage Templates/Views
 * @since      1.6.0
 *
 * @var string $code        Coupon code.
 * @var string $discount    Discount description (e.g., "20%" or "₪50").
 * @var string $description Optional description.
 * @var string $expiry      Optional expiry date.
 */

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

$unique_id = 'bb-coupon-' . wp_unique_id();
?>

<div class="bb-coupon-card" id="<?php echo esc_attr( $unique_id ); ?>">
    <div class="bb-coupon-discount">
        <span class="bb-coupon-discount-value"><?php echo esc_html( $discount ); ?></span>
        <span class="bb-coupon-discount-label"><?php esc_html_e( 'הנחה', 'boostbot' ); ?></span>
    </div>
    
    <div class="bb-coupon-details">
        <?php if ( ! empty( $description ) ) : ?>
            <div class="bb-coupon-description"><?php echo esc_html( $description ); ?></div>
        <?php endif; ?>
        
        <div class="bb-coupon-code-wrapper">
            <div class="bb-coupon-code" id="<?php echo esc_attr( $unique_id ); ?>-code">
                <?php echo esc_html( $code ); ?>
            </div>
            <button type="button" class="bb-coupon-copy" onclick="boostbotCopyCoupon('<?php echo esc_js( $unique_id ); ?>', '<?php echo esc_js( $code ); ?>')">
                <span class="bb-copy-text"><?php esc_html_e( 'העתק', 'boostbot' ); ?></span>
                <span class="bb-copied-text"><?php esc_html_e( 'הועתק!', 'boostbot' ); ?></span>
            </button>
        </div>
        
        <?php if ( ! empty( $expiry ) ) : ?>
            <div class="bb-coupon-expiry">
                <span class="bb-expiry-icon">⏰</span>
                <span><?php /* translators: %s: expiry date */
                echo esc_html( sprintf( __( 'תוקף עד: %s', 'boostbot' ), $expiry ) ); ?></span>
            </div>
        <?php endif; ?>
    </div>
</div>

