<?php
/**
 * Stablezact WP Order Confirmation
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/stablezact/order-confirmation.php.
 *
 * @package Stablezact
 * @version 1.0.0
 */

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

defined( 'ABSPATH' ) || exit;

// Get order data
$stablezact_order_id = $order->get_id();
$stablezact_payment_id = $order->get_meta( '_stablezact_payment_id' );
$stablezact_customer_name = $order->get_billing_first_name();
$stablezact_total = $order->get_formatted_order_total();
$stablezact_currency = $order->get_currency();
$stablezact_date = $order->get_date_created()->date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) );
$stablezact_payment_method = $order->get_payment_method_title();

// Get additional Stablezact payment details
$stablezact_transaction_hash = $order->get_meta('_stablezact_transaction_hash');
$stablezact_payment_pending = $order->get_meta('_stablezact_payment_pending');

// Enqueue this template's styles/script (previously inlined below).
wp_enqueue_style( 'stablezact-order-confirmation', STABLEZACT_PLUGIN_URL . 'assets/css/order-confirmation.css', array(), STABLEZACT_VERSION );
wp_enqueue_script( 'stablezact-order-confirmation', STABLEZACT_PLUGIN_URL . 'assets/js/order-confirmation.js', array( 'jquery' ), STABLEZACT_VERSION, true );
?>

<div class="stablezact-order-confirmation">
    <div class="stablezact-confirmation-header">
        <img src="<?php echo esc_url(STABLEZACT_PLUGIN_URL . 'assets/images/stablezact-logo.png'); ?>" alt="Stablezact" class="coinley-logo">
        
        <?php if ($stablezact_payment_pending) : ?>
            <div class="stablezact-payment-pending-notice">
                <h2><?php esc_html_e('Payment Pending', 'stablezact-crypto-payments'); ?></h2>
                <p><?php esc_html_e('Your order has been received, but the payment is still pending. Please complete your payment to process your order.', 'stablezact-crypto-payments'); ?></p>
                <p><button class="stablezact-order-pay-button button"><?php esc_html_e('Complete Payment', 'stablezact-crypto-payments'); ?></button></p>
            </div>
        <?php else : ?>
            <div class="stablezact-payment-complete-notice">
                <h2><?php esc_html_e('Payment Complete', 'stablezact-crypto-payments'); ?></h2>
                <p><?php esc_html_e('Thank you for your payment. Your transaction has been completed successfully.', 'stablezact-crypto-payments'); ?></p>
            </div>
        <?php endif; ?>
    </div>
    
    <div class="stablezact-order-details">
        <h3><?php esc_html_e('Order Details', 'stablezact-crypto-payments'); ?></h3>
        
        <div class="stablezact-order-info-grid">
            <div class="stablezact-order-info-item">
                <span class="stablezact-label"><?php esc_html_e('Order Number', 'stablezact-crypto-payments'); ?>:</span>
                <span class="stablezact-value"><?php echo esc_html($order->get_order_number()); ?></span>
            </div>
            
            <div class="stablezact-order-info-item">
                <span class="stablezact-label"><?php esc_html_e('Date', 'stablezact-crypto-payments'); ?>:</span>
                <span class="stablezact-value"><?php echo esc_html(wc_format_datetime($order->get_date_created())); ?></span>
            </div>
            
            <div class="stablezact-order-info-item">
                <span class="stablezact-label"><?php esc_html_e('Total', 'stablezact-crypto-payments'); ?>:</span>
                <span class="stablezact-value"><?php echo wp_kses_post($order->get_formatted_order_total()); ?></span>
            </div>
            
            <div class="stablezact-order-info-item">
                <span class="stablezact-label"><?php esc_html_e('Payment Method', 'stablezact-crypto-payments'); ?>:</span>
                <span class="stablezact-value"><?php esc_html_e('Cryptocurrency (Stablezact)', 'stablezact-crypto-payments'); ?></span>
            </div>
            
            <?php if ($stablezact_currency) : ?>
                <div class="stablezact-order-info-item">
                    <span class="stablezact-label"><?php esc_html_e('Cryptocurrency', 'stablezact-crypto-payments'); ?>:</span>
                    <span class="stablezact-value"><?php echo esc_html($stablezact_currency); ?></span>
                </div>
            <?php endif; ?>
            
            <?php if ($stablezact_payment_id && !$stablezact_payment_pending) : ?>
                <div class="stablezact-order-info-item">
                    <span class="stablezact-label"><?php esc_html_e('Payment ID', 'stablezact-crypto-payments'); ?>:</span>
                    <span class="stablezact-value"><?php echo esc_html($stablezact_payment_id); ?></span>
                </div>
            <?php endif; ?>
            
            <?php if ($stablezact_transaction_hash && !$stablezact_payment_pending) : ?>
                <div class="stablezact-order-info-item stablezact-transaction-hash">
                    <span class="stablezact-label"><?php esc_html_e('Transaction Hash', 'stablezact-crypto-payments'); ?>:</span>
                    <div class="stablezact-hash-wrapper">
                        <span class="stablezact-value"><?php echo esc_html($stablezact_transaction_hash); ?></span>
                        <button type="button" class="stablezact-btn-copy" data-clipboard-text="<?php echo esc_attr($stablezact_transaction_hash); ?>">
                            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                                <path d="M13.3333 6H7.33333C6.59695 6 6 6.59695 6 7.33333V13.3333C6 14.0697 6.59695 14.6667 7.33333 14.6667H13.3333C14.0697 14.6667 14.6667 14.0697 14.6667 13.3333V7.33333C14.6667 6.59695 14.0697 6 13.3333 6Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
                                <path d="M3.33366 10.0001H2.66699C2.31337 10.0001 1.97423 9.8597 1.72418 9.60965C1.47413 9.35961 1.33366 9.02047 1.33366 8.66683V2.66683C1.33366 2.3132 1.47413 1.97407 1.72418 1.72402C1.97423 1.47397 2.31337 1.3335 2.66699 1.3335H8.66699C9.02062 1.3335 9.35975 1.47397 9.6098 1.72402C9.85985 1.97407 10.0003 2.3132 10.0003 2.66683V3.3335" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
                            </svg>
                        </button>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </div>
    
    <?php if (!$stablezact_payment_pending) : ?>
        <div class="stablezact-next-steps">
            <h3><?php esc_html_e('Next Steps', 'stablezact-crypto-payments'); ?></h3>
            <ul class="stablezact-steps-list">
                <li>
                    <div class="stablezact-step-icon">
                        <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
                            <path d="M16.6667 5L7.5 14.1667L3.33337 10" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                        </svg>
                    </div>
                    <div class="stablezact-step-content">
                        <h4><?php esc_html_e('Order Processing', 'stablezact-crypto-payments'); ?></h4>
                        <p><?php esc_html_e('Your order is now being processed.', 'stablezact-crypto-payments'); ?></p>
                    </div>
                </li>
                <li>
                    <div class="stablezact-step-icon">
                        <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
                            <path d="M10 1.66663V18.3333M10 1.66663L5 6.66663M10 1.66663L15 6.66663" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                        </svg>
                    </div>
                    <div class="stablezact-step-content">
                        <h4><?php esc_html_e('Shipping & Fulfillment', 'stablezact-crypto-payments'); ?></h4>
                        <p><?php esc_html_e('You will receive an email when your order ships.', 'stablezact-crypto-payments'); ?></p>
                    </div>
                </li>
                <li>
                    <div class="stablezact-step-icon">
                        <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
                            <path d="M9.99999 18.3333C14.6024 18.3333 18.3333 14.6024 18.3333 10C18.3333 5.39763 14.6024 1.66667 9.99999 1.66667C5.39762 1.66667 1.66666 5.39763 1.66666 10C1.66666 14.6024 5.39762 18.3333 9.99999 18.3333Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                            <path d="M10 5V10L13.3333 11.6667" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                        </svg>
                    </div>
                    <div class="stablezact-step-content">
                        <h4><?php esc_html_e('Delivery', 'stablezact-crypto-payments'); ?></h4>
                        <p><?php esc_html_e('Your items will be delivered according to the shipping method selected.', 'stablezact-crypto-payments'); ?></p>
                    </div>
                </li>
            </ul>
        </div>
    <?php endif; ?>
    
    <div class="stablezact-confirmation-footer">
        <a href="<?php echo esc_url(wc_get_page_permalink('shop')); ?>" class="stablezact-btn-secondary"><?php esc_html_e('Continue Shopping', 'stablezact-crypto-payments'); ?></a>
        <a href="<?php echo esc_url(wc_get_account_endpoint_url('orders')); ?>" class="stablezact-btn-primary"><?php esc_html_e('View Your Orders', 'stablezact-crypto-payments'); ?></a>
    </div>
</div>
