// WhatsApp Order Functionality
document.addEventListener('DOMContentLoaded', function () {
    const whatsappButtons = document.querySelectorAll('.whatsapp-order');

    whatsappButtons.forEach(button => {
        button.addEventListener('click', function () {
            const productName = this.getAttribute('data-product-name');
            const productPrice = this.getAttribute('data-product-price');
            const productId = this.getAttribute('data-product-id');
            const sellerPhone = this.getAttribute('data-seller-phone') || '254788419041'; // Admin fallback number
            const shopName = this.getAttribute('data-shop-name') || 'IzzieShop';

            // Clean phone number (remove spaces, dashes, etc.)
            const cleanPhone = sellerPhone.replace(/[\s\-\(\)]/g, '');

            // Create message
            const message = `Hello ${shopName}! I'm interested in ordering from IzzieShop:\n\n` +
                `Product: ${productName}\n` +
                `Price: KSh ${productPrice}\n` +
                `Product ID: ${productId}\n\n` +
                `Please provide more details about delivery and payment.`;

            // Encode message for URL
            const encodedMessage = encodeURIComponent(message);

            // Create WhatsApp URL
            const whatsappUrl = `https://wa.me/${cleanPhone}?text=${encodedMessage}`;

            // Open WhatsApp
            window.open(whatsappUrl, '_blank');
        });
    });
});

// Smooth scroll
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();
        const target = document.querySelector(this.getAttribute('href'));
        if (target) {
            target.scrollIntoView({
                behavior: 'smooth'
            });
        }
    });
});
