<?php include 'includes/header.php';?>


<?php

$drills_cont =[
   '10-yard-dash' => [
    'price_drills'=> 12.95,
   ],
   '20-yard-dash' => [
    'price_drills'=> 13.95,
   ],
   '40-yard-dash' => [
    'price_drills'=> 15.95,
   ],
   'zig-zag' => [
    'price_drills' => 14.95
   ],
   '505-agility' => [
    'price_drills'=> 16.95,
   ],
   '60-yard-dash' => [
    'price_drills' => 17.95,
   ],
   'base-running' => [
    'price_drills' => 18.95,
   ],
   'biometric-measurements' => [
    'price_drills' => 19.95,
   ],
   'broad-jump' => [
    'price_drills' => 20.95,
   ],
   'bronco-1.2k' => [
    'price_drills' => 21.95,
   ],
   'dash' => [
    'price_drills' => 22.95,
   ],
   'figure-eight' => [
    'price_drills' => 23.95,
   ],
   'flying' => [
    'price_drills' => 24.95,
   ],
   'L-drills' => [
    'price_drills' => 25.95,
   ],
   'flying-30' => [
    'price_drills' => 26.95,
   ],
   'lane-agility' => [
    'price_drills' => 27.95,
   ],
   'lap' => [
    'price_drills' => 28.95,
   ],
   'long-snapping' => [
    'price_drills' => 29.95,
   ],
   'pop-time' => [
    'price_drills' => 30.95,
   ],
   'pro-agility-on-the-ice' => [
    'price_drills' => 31.95,
   ],
   'pro-agility' => [
    'price_drills' => 32.95,
   ],
   'QB-reactive-agility' => [
    'price_drills' => 33.95,
   ],
   'rast' => [
    'price_drills' => 34.95,
   ],
   'reactive-agility-test' => [
    'price_drills' => 35.95,
   ],
   'reactive-shuttle' => [
    'price_drills' => 36.95,
   ],
   'red-blue-sprint' => [
    'price_drills' => 37.95,
   ],
   'route-timing' => [
    'price_drills' => 38.95,
   ],
   'reactive-strength-index' => [
    'price_drills' => 39.95,
   ],
   'run-a-three' => [
    'price_drills' => 40.95,
   ],
   'sprint-17.68-meters' => [
    'price_drills' => 41.95,
   ],
   't-test' => [
    'price_drills' => 42.95,
   ],
   'vertical-jump-/-max-vertical' => [
    'price_drills' => 43.95,
   ],
   'welsh-anaerobic-test' => [
    'price_drills' => 44.95,
   ],
   '3/4-court-dash' => [
    'price_drills' => 45.95,
   ],
];

$pricing_cont =[
    'core-combine-drills' => [
        'pricing_price' => 30,
    ],
    'additional-drills' => [
        'pricing_price' => 35,
    ],
    'standard-package-kids' => [
        'pricing_price' => 150,
    ],
    'standard-package-adults' => [
        'pricing_price' => 200,
    ],
    'premium-package-kids' => [
        'pricing_price' => 250,
    ],
    'premium-package-adults' => [
        'pricing_price' => 300,
    ],

];

$driils = $_GET['drills'] ?? null;
$prici = $_GET['pricing'] ?? null;

?>


<!-- Banner Main About Section Start Here -->
<section class="banner-main-sec-about">
    <div class="container-fluid">
        <div class="row align-items-center">
            <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-12 col-sm-12 col-12" data-aos="fade-right"
                data-aos-duration="1500">
                <div class="banner-main-about">
                    <h1>CHECKOUT</h1>
                    <div class="website-main-buttons">
                        <button class="popup-btn">Get Started</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!-- Banner Main About Section End Here -->


<section class="checkout-main-wrap">
    <div class="container">
        <div class="row">
            <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 col-xxl-12">
                <div class="checkout-header">
                    <h2>Checkout Information</h2>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-12 col-sm-12 col-md-12 col-lg-7 col-xl-7 col-xxl-7">
                <div class="checkout-details">
                    <div class="checkout-card">
                        <div class="card-header">
                            <h4>Contact Details</h4>
                        </div>
                        <form id="checkoutForm" action="#">
                            <div class="row">
                                <div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 col-xxl-6">
                                    <div class="form-group">
                                        <label for="firstName">First Name</label>
                                        <input type="text" id="firstName" class="form-control" required="">
                                    </div>
                                </div>
                                <div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 col-xxl-6">
                                    <div class="form-group">
                                        <label for="lastName">Last Name</label>
                                        <input type="text" id="lastName" class="form-control" required="">
                                    </div>
                                </div>
                                <div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 col-xxl-6">
                                    <div class="form-group">
                                        <label for="email">Email</label>
                                        <input type="email" id="email" class="form-control"
                                            placeholder="you@example.com" required="">

                                    </div>
                                </div>
                                <div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 col-xxl-6">
                                    <div class="form-group">
                                        <label for="phone">Phone Number <span>(Optional)</span></label>
                                        <input type="tel" id="phone" name="phone" class="form-control"
                                            placeholder="e.g., +1 (555) 123-4567">

                                    </div>
                                </div>
                                <div id="shippingAddressFields" class="row">
                                    <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 col-xxl-12">
                                        <div class="form-group">
                                            <label for="address">Address</label>
                                            <input type="text" id="address" class="form-control"
                                                placeholder="1234 Main St">
                                        </div>
                                    </div>
                                    <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 col-xxl-12">
                                        <div class="form-group">
                                            <label for="address2">Address 2</label>
                                            <input type="text" id="address2" class="form-control"
                                                placeholder="Apartment or suite" required="">
                                        </div>
                                    </div>
                                    <div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 col-xxl-6">
                                        <div class="form-group">
                                            <label for="country">Country</label>
                                            <select id="country" class="form-select">
                                                <option value="">Choose...</option>
                                                <option value="Afghanistan">Afghanistan</option>
                                                <option value="Albania">Albania</option>
                                                <option value="Algeria">Algeria</option>
                                                <option value="Andorra">Andorra</option>
                                                <option value="Angola">Angola</option>
                                                <option value="Antigua and Barbuda">Antigua and Barbuda</option>
                                                <option value="Argentina">Argentina</option>
                                                <option value="Armenia">Armenia</option>
                                                <option value="Australia">Australia</option>
                                                <option value="Austria">Austria</option>
                                                <option value="Azerbaijan">Azerbaijan</option>
                                                <option value="Bahamas">Bahamas</option>
                                                <option value="Bahrain">Bahrain</option>
                                                <option value="Bangladesh">Bangladesh</option>
                                                <option value="Barbados">Barbados</option>
                                                <option value="Belarus">Belarus</option>
                                                <option value="Belgium">Belgium</option>
                                                <option value="Belize">Belize</option>
                                                <option value="Benin">Benin</option>
                                                <option value="Bhutan">Bhutan</option>
                                                <option value="Bolivia">Bolivia</option>
                                                <option value="Bosnia and Herzegovina">Bosnia and Herzegovina</option>
                                                <option value="Botswana">Botswana</option>
                                                <option value="Brazil">Brazil</option>
                                                <option value="Brunei">Brunei</option>
                                                <option value="Bulgaria">Bulgaria</option>
                                                <option value="Burkina Faso">Burkina Faso</option>
                                                <option value="Burundi">Burundi</option>
                                                <option value="Cabo Verde">Cabo Verde</option>
                                                <option value="Cambodia">Cambodia</option>
                                                <option value="Cameroon">Cameroon</option>
                                                <option value="Canada">Canada</option>
                                                <option value="Central African Republic">Central African Republic
                                                </option>
                                                <option value="Chad">Chad</option>
                                                <option value="Chile">Chile</option>
                                                <option value="China">China</option>
                                                <option value="Colombia">Colombia</option>
                                                <option value="Comoros">Comoros</option>
                                                <option value="Congo (Brazzaville)">Congo (Brazzaville)</option>
                                                <option value="Congo (Kinshasa)">Congo (Kinshasa)</option>
                                                <option value="Costa Rica">Costa Rica</option>
                                                <option value="Croatia">Croatia</option>
                                                <option value="Cuba">Cuba</option>
                                                <option value="Cyprus">Cyprus</option>
                                                <option value="Czech Republic">Czech Republic</option>
                                                <option value="Denmark">Denmark</option>
                                                <option value="Djibouti">Djibouti</option>
                                                <option value="Dominica">Dominica</option>
                                                <option value="Dominican Republic">Dominican Republic</option>
                                                <option value="East Timor (Timor-Leste)">East Timor (Timor-Leste)
                                                </option>
                                                <option value="Ecuador">Ecuador</option>
                                                <option value="Egypt">Egypt</option>
                                                <option value="El Salvador">El Salvador</option>
                                                <option value="Equatorial Guinea">Equatorial Guinea</option>
                                                <option value="Eritrea">Eritrea</option>
                                                <option value="Estonia">Estonia</option>
                                                <option value="Eswatini">Eswatini</option>
                                                <option value="Ethiopia">Ethiopia</option>
                                                <option value="Fiji">Fiji</option>
                                                <option value="Finland">Finland</option>
                                                <option value="France">France</option>
                                                <option value="Gabon">Gabon</option>
                                                <option value="Gambia">Gambia</option>
                                                <option value="Georgia">Georgia</option>
                                                <option value="Germany">Germany</option>
                                                <option value="Ghana">Ghana</option>
                                                <option value="Greece">Greece</option>
                                                <option value="Grenada">Grenada</option>
                                                <option value="Guatemala">Guatemala</option>
                                                <option value="Guinea">Guinea</option>
                                                <option value="Guinea-Bissau">Guinea-Bissau</option>
                                                <option value="Guyana">Guyana</option>
                                                <option value="Haiti">Haiti</option>
                                                <option value="Honduras">Honduras</option>
                                                <option value="Hungary">Hungary</option>
                                                <option value="Iceland">Iceland</option>
                                                <option value="India">India</option>
                                                <option value="Indonesia">Indonesia</option>
                                                <option value="Iran">Iran</option>
                                                <option value="Iraq">Iraq</option>
                                                <option value="Ireland">Ireland</option>
                                                <option value="Israel">Israel</option>
                                                <option value="Italy">Italy</option>
                                                <option value="Ivory Coast">Ivory Coast</option>
                                                <option value="Jamaica">Jamaica</option>
                                                <option value="Japan">Japan</option>
                                                <option value="Jordan">Jordan</option>
                                                <option value="Kazakhstan">Kazakhstan</option>
                                                <option value="Kenya">Kenya</option>
                                                <option value="Kiribati">Kiribati</option>
                                                <option value="Kosovo">Kosovo</option>
                                                <option value="Kuwait">Kuwait</option>
                                                <option value="Kyrgyzstan">Kyrgyzstan</option>
                                                <option value="Laos">Laos</option>
                                                <option value="Latvia">Latvia</option>
                                                <option value="Lebanon">Lebanon</option>
                                                <option value="Lesotho">Lesotho</option>
                                                <option value="Liberia">Liberia</option>
                                                <option value="Libya">Libya</option>
                                                <option value="Liechtenstein">Liechtenstein</option>
                                                <option value="Lithuania">Lithuania</option>
                                                <option value="Luxembourg">Luxembourg</option>
                                                <option value="Madagascar">Madagascar</option>
                                                <option value="Malawi">Malawi</option>
                                                <option value="Malaysia">Malaysia</option>
                                                <option value="Maldives">Maldives</option>
                                                <option value="Mali">Mali</option>
                                                <option value="Malta">Malta</option>
                                                <option value="Marshall Islands">Marshall Islands</option>
                                                <option value="Mauritania">Mauritania</option>
                                                <option value="Mauritius">Mauritius</option>
                                                <option value="Mexico">Mexico</option>
                                                <option value="Micronesia">Micronesia</option>
                                                <option value="Moldova">Moldova</option>
                                                <option value="Monaco">Monaco</option>
                                                <option value="Mongolia">Mongolia</option>
                                                <option value="Montenegro">Montenegro</option>
                                                <option value="Morocco">Morocco</option>
                                                <option value="Mozambique">Mozambique</option>
                                                <option value="Myanmar (Burma)">Myanmar (Burma)</option>
                                                <option value="Namibia">Namibia</option>
                                                <option value="Nauru">Nauru</option>
                                                <option value="Nepal">Nepal</option>
                                                <option value="Netherlands">Netherlands</option>
                                                <option value="New Zealand">New Zealand</option>
                                                <option value="Nicaragua">Nicaragua</option>
                                                <option value="Niger">Niger</option>
                                                <option value="Nigeria">Nigeria</option>
                                                <option value="North Korea">North Korea</option>
                                                <option value="North Macedonia">North Macedonia</option>
                                                <option value="Norway">Norway</option>
                                                <option value="Oman">Oman</option>
                                                <option value="Pakistan">Pakistan</option>
                                                <option value="Palau">Palau</option>
                                                <option value="Palestine">Palestine</option>
                                                <option value="Panama">Panama</option>
                                                <option value="Papua New Guinea">Papua New Guinea</option>
                                                <option value="Paraguay">Paraguay</option>
                                                <option value="Peru">Peru</option>
                                                <option value="Philippines">Philippines</option>
                                                <option value="Poland">Poland</option>
                                                <option value="Portugal">Portugal</option>
                                                <option value="Qatar">Qatar</option>
                                                <option value="Romania">Romania</option>
                                                <option value="Russia">Russia</option>
                                                <option value="Rwanda">Rwanda</option>
                                                <option value="Saint Kitts and Nevis">Saint Kitts and Nevis</option>
                                                <option value="Saint Lucia">Saint Lucia</option>
                                                <option value="Saint Vincent and the Grenadines">Saint Vincent and the
                                                    Grenadines</option>
                                                <option value="Samoa">Samoa</option>
                                                <option value="San Marino">San Marino</option>
                                                <option value="Sao Tome and Principe">Sao Tome and Principe</option>
                                                <option value="Saudi Arabia">Saudi Arabia</option>
                                                <option value="Senegal">Senegal</option>
                                                <option value="Serbia">Serbia</option>
                                                <option value="Seychelles">Seychelles</option>
                                                <option value="Sierra Leone">Sierra Leone</option>
                                                <option value="Singapore">Singapore</option>
                                                <option value="Slovakia">Slovakia</option>
                                                <option value="Slovenia">Slovenia</option>
                                                <option value="Solomon Islands">Solomon Islands</option>
                                                <option value="Somalia">Somalia</option>
                                                <option value="South Africa">South Africa</option>
                                                <option value="South Korea">South Korea</option>
                                                <option value="South Sudan">South Sudan</option>
                                                <option value="Spain">Spain</option>
                                                <option value="Sri Lanka">Sri Lanka</option>
                                                <option value="Sudan">Sudan</option>
                                                <option value="Suriname">Suriname</option>
                                                <option value="Sweden">Sweden</option>
                                                <option value="Switzerland">Switzerland</option>
                                                <option value="Syria">Syria</option>
                                                <option value="Taiwan">Taiwan</option>
                                                <option value="Tajikistan">Tajikistan</option>
                                                <option value="Tanzania">Tanzania</option>
                                                <option value="Thailand">Thailand</option>
                                                <option value="Togo">Togo</option>
                                                <option value="Tonga">Tonga</option>
                                                <option value="Trinidad and Tobago">Trinidad and Tobago</option>
                                                <option value="Tunisia">Tunisia</option>
                                                <option value="Turkey">Turkey</option>
                                                <option value="Turkmenistan">Turkmenistan</option>
                                                <option value="Tuvalu">Tuvalu</option>
                                                <option value="Uganda">Uganda</option>
                                                <option value="Ukraine">Ukraine</option>
                                                <option value="United Arab Emirates">United Arab Emirates</option>
                                                <option value="United Kingdom">United Kingdom</option>
                                                <option value="United States">United States</option>
                                                <option value="Uruguay">Uruguay</option>
                                                <option value="Uzbekistan">Uzbekistan</option>
                                                <option value="Vanuatu">Vanuatu</option>
                                                <option value="Vatican City">Vatican City</option>
                                                <option value="Venezuela">Venezuela</option>
                                                <option value="Vietnam">Vietnam</option>
                                                <option value="Yemen">Yemen</option>
                                                <option value="Zambia">Zambia</option>
                                                <option value="Zimbabwe">Zimbabwe</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 col-xxl-6">
                                        <div class="form-group">
                                            <label for="state">State</label>
                                            <select id="state" class="form-select">
                                                <option value="">Choose...</option>
                                                <option value="Alabama">Alabama</option>
                                                <option value="Alaska">Alaska</option>
                                                <option value="Arizona">Arizona</option>
                                                <option value="Arkansas">Arkansas</option>
                                                <option value="California">California</option>
                                                <option value="Colorado">Colorado</option>
                                                <option value="Connecticut">Connecticut</option>
                                                <option value="Delaware">Delaware</option>
                                                <option value="Florida">Florida</option>
                                                <option value="Georgia">Georgia</option>
                                                <option value="Hawaii">Hawaii</option>
                                                <option value="Idaho">Idaho</option>
                                                <option value="Illinois">Illinois</option>
                                                <option value="Indiana">Indiana</option>
                                                <option value="Iowa">Iowa</option>
                                                <option value="Kansas">Kansas</option>
                                                <option value="Kentucky">Kentucky</option>
                                                <option value="Louisiana">Louisiana</option>
                                                <option value="Maine">Maine</option>
                                                <option value="Maryland">Maryland</option>
                                                <option value="Massachusetts">Massachusetts</option>
                                                <option value="Michigan">Michigan</option>
                                                <option value="Minnesota">Minnesota</option>
                                                <option value="Mississippi">Mississippi</option>
                                                <option value="Missouri">Missouri</option>
                                                <option value="Montana">Montana</option>
                                                <option value="Nebraska">Nebraska</option>
                                                <option value="Nevada">Nevada</option>
                                                <option value="New Hampshire">New Hampshire</option>
                                                <option value="New Jersey">New Jersey</option>
                                                <option value="New Mexico">New Mexico</option>
                                                <option value="New York">New York</option>
                                                <option value="North Carolina">North Carolina</option>
                                                <option value="North Dakota">North Dakota</option>
                                                <option value="Ohio">Ohio</option>
                                                <option value="Oklahoma">Oklahoma</option>
                                                <option value="Oregon">Oregon</option>
                                                <option value="Pennsylvania">Pennsylvania</option>
                                                <option value="Rhode Island">Rhode Island</option>
                                                <option value="South Carolina">South Carolina</option>
                                                <option value="South Dakota">South Dakota</option>
                                                <option value="Tennessee">Tennessee</option>
                                                <option value="Texas">Texas</option>
                                                <option value="Utah">Utah</option>
                                                <option value="Vermont">Vermont</option>
                                                <option value="Virginia">Virginia</option>
                                                <option value="Washington">Washington</option>
                                                <option value="West Virginia">West Virginia</option>
                                                <option value="Wisconsin">Wisconsin</option>
                                                <option value="Wyoming">Wyoming</option>
                                            </select>

                                        </div>
                                    </div>
                                    <div class="col-12 col-sm-12 col-md-12 col-lg-6 col-xl-6 col-xxl-6">
                                        <div class="form-group">
                                            <label for="zip">Zip</label>
                                            <input type="text" id="zip" class="form-control">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <button type="submit" form="checkoutForm" class="btn-default" id="submitOrder">Place Order</button>
                </div>
            </div>
            <div class="col-12 col-sm-12 col-md-12 col-lg-5 col-xl-5 col-xxl-5">
                <div class="order-summary">
                    <div class="checkout-card">
                        <div class="card-header">
                            <h4>Order Summary</h4>
                        </div>
                        <div class="card-body">
                            <ul class="order-items">
                                <?php if(!empty($prici) && isset($pricing_cont[$prici])): ?>

                                <li>
                                    <span>"<?= $prici ?>" ( Pricing )</span>
                                    <span>$<?= $pricing_cont[$prici]['pricing_price'] ?></span>
                                </li>

                                <li class="order-total">
                                    <span>Total (USD)</span>
                                    <span id="orderTotal" data-price="<?= $pricing_cont[$prici]['pricing_price'] ?>">
                                        $<?= $pricing_cont[$prici]['pricing_price'] ?>
                                    </span>
                                </li>

                                <?php elseif(!empty($driils) && isset($drills_cont[$driils])): ?>

                                <li>
                                    <span><?= $driils ?> ( Drills )</span>
                                    <span>$<?= $drills_cont[$driils]['price_drills'] ?></span>
                                </li>

                                <li class="order-total">
                                    <span>Total (USD)</span>
                                    <span id="orderTotal" data-price="<?= $drills_cont[$driils]['price_drills'] ?>">
                                        $<?= $drills_cont[$driils]['price_drills'] ?>
                                    </span>
                                </li>

                                <?php else: ?>
                                <li>No valid product selected</li>
                                <?php endif; ?>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="checkout-card mt-4">
                    <div class="card-header">
                        <h4>Payment Details</h4>
                    </div>
                    <form id="paymentForm" action="void:;">
                        <div class="row">
                            <div id="card-element-checkout"></div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Message Box and Overlay -->
<div class="message-box-overlay" id="messageBoxOverlay"></div>
<div class="message-box" id="messageBox">
    <h5>Order Placed Successfully!</h5>
    <p>Thank you for your purchase. Your order has been received and is being processed.</p>
    <button type="button" class="btn-default" id="closeMessageBox">Close</button>
</div>


<script src="https://js.stripe.com/v3/"></script>
<script>
const stripe = Stripe(
    'pk_test_51TC4TjL1qy8feMVjSOWB4s0l06YxNHh77ZAgbDjM2dHq94ASwiKFAHYUU1WREMbkcxpSPvqweVM881oegbOmKx7H00J5uxd3Wf');

const style = {
  base: {
    color: "#ffffff",
    fontSize: "16px",
    fontFamily: "Arial, sans-serif",
    "::placeholder": {
      color: "#999999"
    }
  },
  invalid: {
    color: "#ff4d4f"
  }
};    

const elements = stripe.elements();
const cardElement = elements.create('card' , { style: style });

// ✅ Correct div
cardElement.mount('#card-element-checkout');

document.getElementById('submitOrder').addEventListener('click', async (e) => {
    e.preventDefault();

    const totalPrice = document.getElementById('orderTotal').getAttribute('data-price');

    try {
        // 🔥 Create PaymentIntent ON CLICK
        const res = await fetch('create_payment_intent.php', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                amount: parseFloat(totalPrice)
            })
        });

        const data = await res.json();

        if (!data.clientSecret) {
            alert("Payment error");
            return;
        }

        const {
            error,
            paymentIntent
        } = await stripe.confirmCardPayment(data.clientSecret, {
            payment_method: {
                card: cardElement
            }
        });

        if (error) {
            alert(error.message);
        } else if (paymentIntent.status === 'succeeded') {
            alert("Payment Successful!");
            window.location.href = "thank-you.php";
        }

    } catch (err) {
        console.error(err);
        alert("Something went wrong");
    }
});
</script>

<?php include 'includes/footer.php';?>