<?php
/**
 * Buy Now Button Template Partial (One-Click Checkout)
 * 
 * @param int $product_id Product ID
 * @param int $quantity Quantity (default 1)
 * @param int $variation_id Variation ID for variable products
 */

if (!defined('ABSPATH')) exit;

$instinctor_active_addons = \Instinctor\Core\Plugin::getActiveAddons();
$instinctor_has_one_click = in_array('one_click_checkout', $instinctor_active_addons) || in_array('all_access', $instinctor_active_addons);

if ($instinctor_has_one_click):
    $instinctor_settings = \Instinctor\Services\OneClickCheckoutService::getSettings();
    
    if (!empty($instinctor_settings['enabled'])):
        $instinctor_product_id = $product_id ?? get_the_ID();
        $instinctor_quantity = $quantity ?? 1;
        $instinctor_variation_id = $variation_id ?? 0;
        $instinctor_button_text = $instinctor_settings['button_text'] ?? 'Buy Now';
?>

<button type="button" 
        class="instinctor-buy-now-btn" 
        data-product-id="<?php echo esc_attr($instinctor_product_id); ?>"
        data-quantity="<?php echo esc_attr($instinctor_quantity); ?>"
        <?php if ($instinctor_variation_id): ?>data-variation-id="<?php echo esc_attr($instinctor_variation_id); ?>"<?php endif; ?>>
    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
    </svg>
    <?php echo esc_html($instinctor_button_text); ?>
</button>
<?php endif; ?>
<?php endif; ?>
