@extends('layouts.frontend.app')

@push('meta')
    <meta name='description' content="Download Product File" />
    <meta name='keywords' content="E-commerce, Best e-commerce website" />
@endpush

@section('title', 'Order List')

@section('content')

    <style>
    body {
        background-color: #f8f9fa;
    }

    .order-success-container {
        max-width: 600px;
        margin: 100px auto;
        padding: 20px;
        background-color: #fff;
        border-radius: 8px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        text-align: center;
    }

    .order-success-icon {
        font-size: 48px;
        color: #28a745;
        margin-bottom: 20px;
    }

    .order-success-title {
        font-size: 24px;
        font-weight: bold;
        margin-bottom: 20px;
    }

    .order-details {
        text-align: left;
        margin-bottom: 20px;
    }

    .order-details p {
        margin-bottom: 5px;
    }

    .btn-continue-shopping {
        background-color: #28a745;
        color: #fff;
        padding: 10px 20px;
        border-radius: 5px;
        text-decoration: none;
        display: inline-block;
        margin-top: 20px;
    }

    .btn-continue-shopping:hover {
        background-color: #218838;
    }

        .btn-print {
            background-color: #007bff;
            color: #fff;
            padding: 10px 20px;
            border-radius: 5px;
            text-decoration: none;
            display: inline-block;
            margin-top: 20px;
        }

        .btn-print:hover {
            background-color: #0056b3;
        }
        @media print {
            body * {
                visibility: hidden;
            }
            #order_success_page, #order_success_page * {
                visibility: visible;
            }
            #order_success_page {
                position: absolute;
                left: 0;
                top: 0;
                width: 100%;
            }
        }
    </style>

    <div id="order_success_page" class="order-success-container">
        <div class="order-success-icon">
            <i class="fas fa-check-circle"></i>
        </div>
        <div class="order-success-title">
            {{ setting('order_success_messege') ?? 'Thank You! Your Order Has Been Placed Successfully.' }}
        </div>
        <div class="order-details">
            <p><strong>Order ID:</strong> {{ $data['invoice'] ?? $order['invoice'] }}</p>
            <p><strong>Date & Time:</strong>
                {{ (new DateTime($data['date']))->setTimezone(new DateTimeZone('Asia/Dhaka'))->format('F j, Y, g:i a') }}
            </p>
            <p><strong>Total:</strong> {{ $data['total'] }} {{ setting('CURRENCY_ICON') }}</p>
            <p><strong>Payment Method:</strong> {{ $data['payment_method'] }}</p>
            <hr>
            <p><strong>Phone:</strong> {{ $data['phone'] }}</p>
            <p><strong>E-mail:</strong> {{ $data['email'] }}</p>
            <p><strong>Address</strong> {{ $data['address'] }}</p>

            @if (!empty($paymentCondition) && $paymentCondition == false)
                <div class="alert alert-danger mt-2">Payment failed</div>
            @endif

            @if (!empty($responseExecute))
                <div class="alert alert-success mt-2">Paid !</div>
                <ul class="list-group">
                    <li class="list-group-item">Payment ID : {{ $responseExecute->paymentID }}</li>
                    <li class="list-group-item">Amount : {{ $responseExecute->amount }}
                        {{ $responseExecute->currency }}</li>
                    <li class="list-group-item">Timestamp : {{ $responseExecute->paymentExecuteTime }}</li>
                    <li class="list-group-item">Invoice : {{ $responseExecute->merchantInvoiceNumber }}</li>
                    <li class="list-group-item">Reference : {{ $responseExecute->payerReference }}</li>
                    <li class="list-group-item">Payer A/C : {{ $responseExecute->customerMsisdn }}</li>
                </ul>
            @endif
            <br><div class="py-2 px-2 bg-warning">Note: the order number or take a screenshot for next query</div>

        </div>
        <a href="/" class="btn-continue-shopping">
            Continue Shopping
        </a>
        <a href="javascript:window.print()" class="btn-print">
            Print
        </a>
    </div>
    
@endsection



@php
    // Define the session keys you want to forget
    $sessionKeys = ['coupon', 'bkash_id_token', 'responseExecute', 'bkash_id_token'];

    // Forget each session key if it exists
    foreach ($sessionKeys as $key) {
        if (Session::has($key)) {
            Session::forget($key);
        }
    }
@endphp

@if (setting('GTM_DATA_LAYER_STATUS') == 1 || setting('GTM_DATA_LAYER_STATUS') == null)
    <script type="text/javascript">
        window.dataLayer = window.dataLayer || [];
        window.dataLayer.push({
            event: "purchase",
            customer_info: {
                first_name: "{{ $data['name'] ?? '' }}",
                email_address: "{{ $data['email'] ?? '' }}",
                city: "{{ $data['address'] ?? '' }}",
                phone_number: "{{ $data['phone'] ?? '' }}"
            },
            ecommerce: {
                currency: "BDT",
                transaction_id: "{{ $data['order_id'] }}",
                tax: 0,
                shipping: {{ $data['shipping_charge'] ?? 0 }},
                coupon: "{{ $data['coupon_code'] ?? '' }}",
                value: {{ $data['total'] ?? 0 }},
                items: [
                    @foreach ($data['orderDetails'] as $item)
                        {
                            item_id: "{{ $item->product_id }}",
                            item_name: "{{ $item->title }}",
                            affiliation: "{{ config('app.name') }}",
                            coupon: "{{ $data['coupon_code'] ?? '' }}",
                            discount: {{ $data['discount'] ?? '' }},
                            index: 0,
                            item_brand: "",
                            item_category: "",
                            item_variant: "{{ $item->color ?? '' }}",
                            price: {{ $item->price }},
                            quantity: {{ $item->qty }}
                        },
                    @endforeach
                ]
            }
        });
    </script>
@endif
