@extends($activeTemplate . 'layouts.frontend')
@section('content')
    <div class="container padding-top padding-bottom">
        <div class="row justify-content-center">
            <div class="col-md-6">
                <h4 class="text-center mb-4">@lang('Pay Securely with Paystack')</h4>
                <form action="{{ route('ipn.' . $deposit->gateway->alias) }}" method="POST" class="text-center">
                    @csrf
                    <div class="payment-system-list">
                        <div class="payment-details-card mb-4">
                            <div class="payment-details-card-body">
                                <div class="payment-details-card-header pb-2">
                                    <h3 class="text-start">@lang('Booking Details')</h3>
                                </div>
                                <div class="deposit-info">
                                    <div class="deposit-info__title">
                                        <p class="text has-icon">@lang('Date of Journey')</p>
                                    </div>
                                    <div class="deposit-info__input payment-value-text">
                                        <p class="text">
                                            {{ showDateTime($bookedTicket->date_of_journey, 'F d, Y') }}
                                        </p>
                                    </div>
                                </div>
                                <div class="deposit-info total-amount pt-1">
                                    <div class="deposit-info__title">
                                        <p class="text has-icon">@lang('Pickup Point')</p>
                                    </div>
                                    <div class="deposit-info__input payment-value-text">
                                        <p class="text">
                                            {{ __($bookedTicket->pickup->name) }}
                                        </p>
                                    </div>
                                </div>
                                <div class="deposit-info total-amount pt-1">
                                    <div class="deposit-info__title">
                                        <p class="text has-icon">@lang('Dropping Point')</p>
                                    </div>
                                    <div class="deposit-info__input payment-value-text">
                                        <p class="text">
                                            {{ __($bookedTicket->drop->name) }}
                                        </p>
                                    </div>
                                </div>
                                <div class="deposit-info total-amount pt-1">
                                    <div class="deposit-info__title">
                                        <p class="text has-icon">@lang('Departure Time')</p>
                                    </div>
                                    <div class="deposit-info__input payment-value-text">
                                        <p class="text">
                                            {{ showDateTime($bookedTicket->trip->start_time, 'h:i A') }}
                                        </p>
                                    </div>
                                </div>
                                <div class="deposit-info total-amount pt-1">
                                    <div class="deposit-info__title">
                                        <p class="text has-icon">@lang('Seats')</p>
                                    </div>
                                    <div class="deposit-info__input payment-value-text">
                                        <p class="text">
                                            {{ implode(', ', $bookedTicket->seats) }}
                                        </p>
                                    </div>
                                </div>

                                <div class="payment-details-card-header mt-5 pb-2">
                                    <h3 class="text-start">@lang('Fare Details')</h3>
                                </div>

                                <div class="deposit-info total-amount pt-1">
                                    <div class="deposit-info__title">
                                        <p class="text has-icon">@lang('Total Ticket Fare')</p>
                                    </div>
                                    <div class="deposit-info__input payment-value-text">
                                        <input type="hidden" class="form-control form--control amount" name="amount"
                                            placeholder="@lang('00.00')"
                                            value="{{ getAmount($bookedTicket->sub_total) }}" readonly autocomplete="off">
                                        <p class="text"><span
                                                class="ticket-fee">{{ getAmount($bookedTicket->sub_total) }}</span>
                                            {{ __(gs('cur_text')) }}
                                        </p>
                                    </div>
                                </div>
                                <div class="deposit-info total-amount pt-1">
                                    <div class="deposit-info__title">
                                        <p class="text has-icon">@lang('Processing Charge')
                                            <span data-bs-toggle="tooltip" title="@lang('Processing charge for payment gateways')"
                                                class="proccessing-fee-info"><i class="las la-info-circle"></i>
                                            </span>
                                        </p>
                                    </div>
                                    <div class="deposit-info__input payment-value-text">
                                        <p class="text"><span class="processing-fee">@lang(showAmount($deposit->charge, currencyFormat: false))</span>
                                            {{ __(gs('cur_text')) }}
                                        </p>
                                    </div>
                                </div>

                                @if ($deposit->method_currency != gs('cur_text') && $deposit?->gateway?->crypto != 1)
                                    <div class="deposit-info total-amount pt-1">
                                        <div class="deposit-info__title">
                                            <p class="text">@lang('Total')</p>
                                        </div>
                                        <div class="deposit-info__input payment-value-text">
                                            <p class="text"><span
                                                    class="final-amount">{{ showAmount($deposit->amount + $deposit->charge, currencyFormat: false) }}</span>
                                                {{ __(gs('cur_text')) }}</p>
                                        </div>
                                    </div>

                                    <div class="deposit-info gateway-conversion total-amount pt-1">
                                        <div class="deposit-info__title">
                                            <p class="text">@lang('Conversion')
                                            </p>
                                        </div>
                                        <div class="deposit-info__input payment-value-text">
                                            <p class="text">
                                                @lang('1') {{ __(gs('cur_text')) }} = <span
                                                    class="rate">{{ showAmount($deposit->rate, currencyFormat: false) }}</span>
                                                <span class="method_currency">{{ $deposit->method_currency }}</span>
                                            </p>
                                        </div>
                                    </div>
                                    <div class="deposit-info conversion-currency total-amount pt-1">
                                        <div class="deposit-info__title">
                                            <p class="text">
                                                @lang('Payable') </span>
                                            </p>
                                        </div>
                                        <div class="deposit-info__input payment-value-text">
                                            <p class="text">
                                                <span
                                                    class="in-currency total-value-text">{{ showAmount($deposit->final_amount, currencyFormat: false) }}</span>
                                                <span class="gateway-currency">{{ $deposit->method_currency }}</span>
                                            </p>
                                        </div>
                                    </div>
                                @else
                                    <div class="deposit-info total-amount pt-1">
                                        <div class="deposit-info__title">
                                            <p class="text">@lang('Total')</p>
                                        </div>
                                        <div class="deposit-info__input payment-value-text">
                                            <p class="text"><span
                                                    class="final-amount">{{ showAmount($deposit->final_amount, currencyFormat: false) }}</span>
                                                {{ __(gs('cur_text')) }}</p>
                                        </div>
                                    </div>
                                @endif
                                <button type="button" class="btn btn--base w-100 mt-2"
                                    id="btn-confirm">@lang('Pay Now')</button>
                            </div>
                        </div>
                    </div>
                    <script src="//js.paystack.co/v1/inline.js" data-key="{{ $data->key }}" data-email="{{ $data->email }}"
                        data-amount="{{ round($data->amount) }}" data-currency="{{ $data->currency }}" data-ref="{{ $data->ref }}"
                        data-custom-button="btn-confirm"></script>
                </form>
            </div>
        </div>
    </div>
@endsection

@push('script')
    <script>
        'use strict';
        document.addEventListener("DOMContentLoaded", function() {
            let paystackBtn = document.getElementById("btn-confirm");
            if (paystackBtn) {
                paystackBtn.click();
            }
        });
    </script>
@endpush
