/*
Theme Name: Lifevent
Theme URI: https://themeforest.net/user/ovatheme/portfolio
Version: 1.2.0
Description: Lifevent is a modernized take on an ever-popular WordPress. It has custom color options with beautiful default color schemes, a harmonious fluid grid using a mobile-first approach, and impeccable polish in every detail. Lifevent will make your WordPress look beautiful everywhere. Created by <a href="https://themeforest.net/user/ovatheme">Ovatheme</a>
Author: <a href="https://themeforest.net/user/ovatheme">Ovatheme</a>
Author URI: <a href="https://themeforest.net/user/ovatheme/portfolio">Ovatheme</a>
License: GNU General Public License
License URI: license.txt
Tags: two-columns, three-columns, left-sidebar, right-sidebar, custom-menu, editor-style, featured-images, flexible-header, full-width-template, post-formats, rtl-language-support, sticky-post, translation-ready
Text Domain: lifevent
*/

add_action('wp_footer', function () {
    ?>
    <script>
    <script>
document.addEventListener("DOMContentLoaded", function() {
  const membershipStatus = document.querySelectorAll('input[name="membership-status"]');
  const membershipBox = document.querySelector(".membership-box");
  const priceDisplay = document.getElementById("price-display");
  
  const memberBase = 14000;
  const nonMemberBase = 18000;
  const gstRate = 0.18;

  function getDiscountPercent() {
    let today = new Date();
    if (today <= new Date("2025-09-30")) return 0.20;
    if (today <= new Date("2025-10-31")) return 0.15;
    if (today <= new Date("2025-11-30")) return 0.10;
    return 0;
  }

  function updatePrice() {
    let selected = document.querySelector('input[name="membership-status"]:checked');
    if (!selected) return;

    let basePrice = selected.value === "Yes" ? memberBase : nonMemberBase;
    membershipBox.style.display = (selected.value === "Yes") ? "block" : "none";

    let discount = getDiscountPercent();
    let discountedPrice = basePrice - (basePrice * discount);
    let finalPrice = discountedPrice + (discountedPrice * gstRate);

    priceDisplay.innerHTML = `<strong>Final Payable Amount: ₹${finalPrice.toFixed(2)}</strong>`;
    
    // 🔑 Send updated price to Razorpay
    // Assuming you already trigger Razorpay on submit:
    let razorpayBtn = document.querySelector('input[type="submit"]');
    if (razorpayBtn) {
      razorpayBtn.onclick = function(e) {
        e.preventDefault();
        var options = {
          "key": "YOUR_RAZORPAY_KEY", 
          "amount": Math.round(finalPrice * 100), // in paise
          "currency": "INR",
          "name": "Delegate Registration",
          "description": "Event Registration Fee",
          "handler": function (response){
             alert("Payment successful! ID: " + response.razorpay_payment_id);
          },
          "prefill": {
            "email": document.querySelector('[name="email"]').value,
            "contact": document.querySelector('[name="mobile"]').value
          }
        };
        var rzp1 = new Razorpay(options);
        rzp1.open();
      }
    }
  }

  membershipStatus.forEach(radio => {
    radio.addEventListener("change", updatePrice);
  });
});
</script>

    </script>
    <?php
});
