<?php
// Add custom Theme Functions here
include get_stylesheet_directory() . '/functions/include.php';
// Enqueue parent theme's style
function enqueue_parent_theme_style() {
   wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
}add_action('wp_enqueue_scripts', 'enqueue_parent_theme_style');

// Enqueue child theme's style
function enqueue_child_theme_style() {
   wp_enqueue_style('child-style', get_stylesheet_uri(), array('parent-style'));
}add_action('wp_enqueue_scripts', 'enqueue_child_theme_style');

// Allow CSV / TSV / TXT uploads in WordPress
add_filter('upload_mimes', function($mimes) {
    $mimes['csv'] = 'text/csv';
    $mimes['txt'] = 'text/plain';
    $mimes['tsv'] = 'text/tab-separated-values';
    return $mimes;
});

add_action('wp_enqueue_scripts', function () {
    wp_enqueue_script('password-strength-meter');
});

add_action('wp_footer', function () {
?>
<script>
jQuery(document).ready(function ($) {

     var form = $('form');
     var pass1 = $('#pass1');

     if (!pass1.length || typeof wp.passwordStrength === 'undefined') {
         return;
     }

     form.on('submit', function (e) {

         var strength = wp.passwordStrength.meter(pass1.val(), [], null);

         if (strength < 3) {
             e.preventDefault();
             var warningHtml = `
			<div class="custom-reset-warning"
				 style="background:#f8d7da;
						border:1px solid #f5c2c7;
						color:#842029;
						padding:12px 15px;
						border-radius:4px;
						margin-top:12px; 
						margin-bottom:12px;
						font-size:14px;">
				<strong>⚠ Warning:</strong> Password is weak. Please enter a strong password.
			</div>
			`;


             // TARGET ORANGE WARNING
             var orangeWarning = $('.warning').first();

             if (orangeWarning.length) {
                 orangeWarning.before(warningHtml);
             } else {
                 // fallback
                 pass1.closest('form').prepend(warningHtml);
             }

             pass1.focus();
             return false;
         }
     });

 });
 </script>
 <?php
 });

add_action('wp_footer', function () {
?>
<script>
(function () {

    // Helper to update ONLY the currency symbol
    function updatePrice(selector, symbol) {
        document.querySelectorAll(selector).forEach(el => {
            const em = el.querySelector('em');
            if (em) {
                em.textContent = symbol;
            }
        });
    }

    // ✅ IF product 307719 → allow $
    if (document.body.classList.contains('postid-307719')) {

        fetch('https://ipapi.co/json/')
            .then(res => res.json())
            .then(data => {
                const symbol = (data.country !== 'IN') ? '$' : '₹';
                updatePrice('.summary .price .woocommerce-Price-amount', symbol);
            })
            .catch(() => {
                updatePrice('.summary .price .woocommerce-Price-amount', '₹');
            });

    } 
    // ❌ ELSE → force ₹ for ALL other products
    else {
        updatePrice('.woocommerce-Price-amount', '₹');
    }

})();
</script>
<?php
});
