// Initialize animations document.addEventListener('DOMContentLoaded', function() { // Animate elements with data-animate attribute const animatedElements = document.querySelectorAll('[data-animate]'); animatedElements.forEach((element, index) => { const animationType = element.getAttribute('data-animate'); element.classList.add(animationType); element.style.animationDelay = `${index * 0.1}s`; }); // Mobile menu toggle functionality will be handled by navbar component }); // API functions async function fetchFeaturedProducts() { try { // Using mock API for demo const mockProducts = [ { id: 1, name: "گوجه فرنگی", price: 15000, farmer: "محمد رضایی", location: "اصفهان", image: "http://static.photos/agriculture/320x240/1" }, { id: 2, name: "خیار", price: 12000, farmer: "علی محمدی", location: "تهران", image: "http://static.photos/agriculture/320x240/2" }, { id: 3, name: "سیب", price: 25000, farmer: "حسن کریمی", location: "شیراز", image: "http://static.photos/agriculture/320x240/3" } ]; return mockProducts; } catch (error) { console.error('Error fetching featured products:', error); return []; } } // Form validation function validatePhoneNumber(phone) { const regex = /^09[0-9]{9}$/; return regex.test(phone); } // Utility functions function formatPrice(price) { return new Intl.NumberFormat('fa-IR').format(price) + ' تومان'; } // Register form submissions document.addEventListener('DOMContentLoaded', function() { // Farmer registration form const farmerForm = document.getElementById('farmerForm'); if (farmerForm) { farmerForm.addEventListener('submit', function(e) { e.preventDefault(); if (validatePhoneNumber(this.phone.value)) { // In a real app, you would send data to server here alert('ثبتنام کشاورز با موفقیت انجام شد!'); this.reset(); } else { alert('لطفا شماره تماس معتبر وارد کنید (09xxxxxxxxx)'); } }); } // Buyer registration form const buyerForm = document.getElementById('buyerForm'); if (buyerForm) { buyerForm.addEventListener('submit', function(e) { e.preventDefault(); if (validatePhoneNumber(this.phone.value)) { // In a real app, you would send data to server here alert('ثبتنام خریدار با موفقیت انجام شد!'); this.reset(); } else { alert('لطفا شماره تماس معتبر وارد کنید (09xxxxxxxxx)'); } }); } }); // Load featured products on homepage async function loadFeaturedProducts() { const products = await fetchFeaturedProducts(); const container = document.getElementById('featuredProducts'); if (container && products.length > 0) { container.innerHTML = products.map(product => `
کشاورز: ${product.farmer}
موقعیت: ${product.location}
${formatPrice(product.price)}