<?php
/**
 * Copyright © Simplyin. All rights reserved.
 * 
 * Template for 3DS handler on success page
 * Shows payment processing status similar to WooCommerce/PrestaShop
 */

// Get the store base URL for API calls
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
$baseUrl = $storeManager->getStore()->getBaseUrl();

// Get static URL for images
$assetRepository = $objectManager->get(\Magento\Framework\View\Asset\Repository::class);
$simplyinLogoUrl = $assetRepository->getUrl('Simplyin_Payment::images/simplyin-logo.svg');
$p24LogoUrl = $assetRepository->getUrl('Simplyin_Payment::images/p24.svg');
?>

<!-- Payment Status Container (will be shown/hidden by JS) -->
<div id="simplyin-payment-status" class="simplyin-payment-status" style="display: none;">
    <div class="simplyin-payment-status-box status-processing">
        <!-- Header with logos -->
        <div class="simplyin-status-header">
            <p class="simplyin-status-title"><?= $block->escapeHtml(__('Payment processing by')) ?></p>
            <div class="simplyin-status-logos">
                <!-- <img src="" alt="SimplyIN" class="simplyin-logo">
                <span class="logo-separator">&amp;</span> -->
                <img id="simplyin-provider-logo" src="<?= /* @noEscape */ $p24LogoUrl ?>" alt="Payment Provider" class="p24-logo">
            </div>
        </div>
        
        <!-- Payment method display -->
        <div class="simplyin-status-method">
            <input type="radio" checked="checked">
            <div class="simplyin-status-method-info">
                <img class="simplyin-status-method-logo" id="simplyin-method-logo" src="" alt="Payment Method" style="display: none;">
                <span class="simplyin-status-method-name" id="simplyin-method-name"><?= $block->escapeHtml(__('Card')) ?></span>
            </div>
            <span class="simplyin-status-method-check">✓</span>
        </div>
        
        <!-- Status content -->
        <div class="simplyin-status-content">
            <div class="simplyin-status-icon-wrapper">
                <!-- Clock icon for processing -->
                <svg viewBox="0 0 24 24" id="simplyin-status-icon">
                    <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm.5-13H11v6l5.25 3.15.75-1.23-4.5-2.67z"/>
                </svg>
            </div>
            <div class="simplyin-status-messages">
                <p class="simplyin-status-main" id="simplyin-status-main"><?= $block->escapeHtml(__('Please wait for confirmation')) ?></p>
                <p class="simplyin-status-sub" id="simplyin-status-sub"><?= $block->escapeJs(__('Processing payment...')) ?></p>
            </div>
        </div>
        
        <!-- Spinner -->
        <div class="simplyin-status-spinner" id="simplyin-status-spinner">
            <div class="simplyin-spinner"></div>
        </div>
    </div>
</div>

<script type="text/x-magento-init">
{
    "*": {
        "Simplyin_Payment/js/success/3ds-handler": {
            "baseUrl": "<?= $block->escapeJs($baseUrl) ?>",
            "translations": {
                "processing": "<?= $block->escapeJs(__('Processing payment...')) ?>",
                "waitConfirmation": "<?= $block->escapeJs(__('Please wait for confirmation')) ?>",
                "verifying": "<?= $block->escapeJs(__('Verifying payment status...')) ?>",
                "success": "<?= $block->escapeJs(__('Payment completed successfully!')) ?>",
                "successSub": "<?= $block->escapeJs(__('Your order has been confirmed.')) ?>",
                "failed": "<?= $block->escapeJs(__('Payment failed')) ?>",
                "failedSub": "<?= $block->escapeJs(__('Your order has been created but requires payment.')) ?>",
                "pending": "<?= $block->escapeJs(__('Payment is being processed')) ?>",
                "pendingSub": "<?= $block->escapeJs(__('You will receive a confirmation email once the payment is verified.')) ?>",
                "card": "<?= $block->escapeJs(__('Card')) ?>",
                "blik": "<?= $block->escapeJs(__('BLIK')) ?>"
            }
        }
    }
}
</script>
