document.addEventListener('DOMContentLoaded', function() {
    // 1. Filter Bar Logic
    const filterBtns = document.querySelectorAll('.wcp-filter-btn');
    const cards = document.querySelectorAll('.wcp-card');
    filterBtns.forEach(btn => {
        btn.addEventListener('click', function() {
            filterBtns.forEach(b => b.classList.remove('active'));
            this.classList.add('active');
            const filter = this.getAttribute('data-filter');
            cards.forEach(card => {
                card.style.display = (filter === 'all' || card.getAttribute('data-type') === filter) ? 'flex' : 'none';
            });
        });
    });

    // 2. Terms Modal
    const modal = document.getElementById('wcp-terms-modal');
    const termsBtns = document.querySelectorAll('.wcp-terms-btn');
    const closeBtn = document.querySelector('.wcp-modal-close');
    const modalText = document.getElementById('wcp-modal-terms-text');
    termsBtns.forEach(btn => {
        btn.addEventListener('click', function() {
            modalText.innerText = this.getAttribute('data-terms');
            modal.style.display = 'block';
        });
    });
    if (closeBtn) closeBtn.addEventListener('click', () => { modal.style.display = 'none'; });
    window.addEventListener('click', (e) => { if (e.target === modal) modal.style.display = 'none'; });

    // ==========================================
    // 3. STATISTICS TRACKING & COPY LOGIC
    // ==========================================
    if (typeof wcp_ajax !== 'undefined') {
        // Track Views using Intersection Observer
        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    const couponId = entry.target.dataset.couponId;
                    if (couponId && !entry.target.dataset.viewTracked) {
                        entry.target.dataset.viewTracked = 'true';
                        jQuery.post(wcp_ajax.ajax_url, {
                            action: 'wcp_track_view',
                            coupon_id: couponId,
                            nonce: wcp_ajax.nonce
                        });
                    }
                }
            });
        }, { threshold: 0.3 });

        document.querySelectorAll('.wcp-card, .wcp-list-item').forEach(card => {
            observer.observe(card);
        });

        // Track Clicks & Handle Copy on "Get Deal" or "Copy" buttons
        document.querySelectorAll('.wcp-get-deal-btn, .wcp-copy-btn-inline').forEach(btn => {
            btn.addEventListener('click', function() {
                const card = this.closest('.wcp-card, .wcp-list-item');
                const couponId = card ? card.dataset.couponId : null;
                
                // Track the click
                if (couponId) {
                    jQuery.post(wcp_ajax.ajax_url, {
                        action: 'wcp_track_click',
                        coupon_id: couponId,
                        nonce: wcp_ajax.nonce
                    });
                }
                
                // Handle copy logic if it's the copy button
                if (this.classList.contains('wcp-copy-btn-inline')) {
                    const code = this.getAttribute('data-code');
                    if (navigator.clipboard && navigator.clipboard.writeText) {
                        navigator.clipboard.writeText(code).then(() => showCopiedState(this)).catch(() => fallbackCopy(code, this));
                    } else {
                        fallbackCopy(code, this);
                    }
                }
            });
        });
    }
});

// Fallback copy for older browsers or non-HTTPS sites
function fallbackCopy(text, btn) {
    const textarea = document.createElement('textarea'); 
    textarea.value = text; 
    textarea.style.position = 'fixed'; 
    textarea.style.opacity = 0;
    document.body.appendChild(textarea); 
    textarea.select();
    try { 
        document.execCommand('copy'); 
        showCopiedState(btn); 
    } catch (err) { 
        console.error('Fallback copy failed', err); 
    }
    document.body.removeChild(textarea);
}

function showCopiedState(btn) {
    const originalHTML = btn.innerHTML;
    btn.innerHTML = '<span class="wcp-copy-icon">✅</span> Copied!'; 
    btn.classList.add('copied');
    setTimeout(() => { 
        btn.innerHTML = originalHTML; 
        btn.classList.remove('copied'); 
    }, 2000);
}<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/wp-content/plugins/squirrly-seo/view/assets/css/sitemap.xsl"?>
<!-- generated-on="2026-06-07T12:48:39+00:00" -->
<!-- generator="Squirrly SEO Sitemap" -->
<!-- generator-url="https://wordpress.org/plugins/squirrly-seo/" -->

<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" >
	<url>
		<loc>https://www.androidpimp.com</loc>
		<lastmod>2026-03-15T17:00:37+00:00</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.6</priority>
	</url>
	<url>
		<loc>https://www.androidpimp.com/about-us/</loc>
		<lastmod>2026-01-14T11:25:07+00:00</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.6</priority>
	</url>
	<url>
		<loc>https://www.androidpimp.com/supporters/</loc>
		<lastmod>2026-01-21T14:39:19+00:00</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.6</priority>
	</url>
	<url>
		<loc>https://www.androidpimp.com/contact/</loc>
		<lastmod>2026-06-04T15:28:31+00:00</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.6</priority>
		<image:image>
			<image:loc>http://www.androidpimp.com/wp-content/uploads/2020/08/About_Androidpimp.png</image:loc>
		</image:image>
	</url>
	<url>
		<loc>https://www.androidpimp.com/disclaimer/</loc>
		<lastmod>2022-08-14T13:31:25+00:00</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.6</priority>
	</url>
	<url>
		<loc>https://www.androidpimp.com/terms-use/</loc>
		<lastmod>2022-08-14T13:31:08+00:00</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.6</priority>
	</url>
	<url>
		<loc>https://www.androidpimp.com/about/</loc>
		<lastmod>2025-05-01T13:20:58+00:00</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.6</priority>
		<image:image>
			<image:loc>https://www.androidpimp.com/wp-content/uploads/2012/02/About_Androidpimp.png</image:loc>
			<image:title>About_Androidpimp</image:title>
		</image:image>
		<image:image>
			<image:loc>http://www.androidpimp.com/wp-content/uploads/2020/08/About_Androidpimp.png</image:loc>
		</image:image>
	</url>
</urlset>