File size: 4,532 Bytes
4991312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Main JavaScript for CurlCraft Studio

// Initialize Feather Icons
document.addEventListener('DOMContentLoaded', function() {
    // Feather icons replacement
    if (typeof feather !== 'undefined') {
        feather.replace();
    }

    // Mobile menu toggle for navbar component
    document.addEventListener('click', function(event) {
        if (event.target.closest('[data-menu-toggle]')) {
            const navbar = document.querySelector('custom-navbar');
            if (navbar) {
                const shadowRoot = navbar.shadowRoot;
                const mobileMenu = shadowRoot.querySelector('#mobile-menu');
                if (mobileMenu) {
                    mobileMenu.classList.toggle('hidden');
                }
            }
        }
    });

    // Hairstyle filter functionality
    const filterButtons = document.querySelectorAll('[data-filter]');
    const hairstyleCards = document.querySelectorAll('hairstyle-card');

    filterButtons.forEach(button => {
        button.addEventListener('click', function() {
            const filter = this.getAttribute('data-filter');
            
            // Update active button
            filterButtons.forEach(btn => {
                btn.classList.remove('bg-purple-600', 'text-white');
                btn.classList.add('bg-gray-200', 'text-gray-700');
            });
            this.classList.remove('bg-gray-200', 'text-gray-700');
            this.classList.add('bg-purple-600', 'text-white');

            // Filter cards
            hairstyleCards.forEach(card => {
                const category = card.getAttribute('data-category');
                if (filter === 'all' || category === filter) {
                    card.style.display = 'block';
                    setTimeout(() => {
                        card.style.opacity = '1';
                        card.style.transform = 'translateY(0)';
                    }, 10);
                } else {
                    card.style.opacity = '0';
                    card.style.transform = 'translateY(20px)';
                    setTimeout(() => {
                        card.style.display = 'none';
                    }, 300);
                }
            });
        });
    });

    // Load hairstyles from API
    async function loadHairstyles() {
        try {
            // Using a public API for demonstration
            const response = await fetch('https://api.unsplash.com/search/photos?query=hairstyle&per_page=12&client_id=YOUR_UNSPLASH_ACCESS_KEY');
            const data = await response.json();
            
            // In a real implementation, you would update the hairstyle cards with actual data
            console.log('Hairstyles loaded:', data);
            
            // Update trending section if it exists
            const trendingSection = document.querySelector('custom-trending-section');
            if (trendingSection && data.results) {
                // You can implement actual data binding here
            }
        } catch (error) {
            console.log('Using placeholder data due to API limit');
            // Fallback to placeholder images
        }
    }

    // Load hairstyles on page load
    loadHairstyles();

    // Smooth scroll for anchor links
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            const targetId = this.getAttribute('href');
            if (targetId === '#') return;
            
            const targetElement = document.querySelector(targetId);
            if (targetElement) {
                window.scrollTo({
                    top: targetElement.offsetTop - 80,
                    behavior: 'smooth'
                });
            }
        });
    });

    // Newsletter form handling
    const newsletterForms = document.querySelectorAll('form[data-newsletter]');
    newsletterForms.forEach(form => {
        form.addEventListener('submit', function(e) {
            e.preventDefault();
            const email = this.querySelector('input[type="email"]').value;
            
            if (email && email.includes('@')) {
                // Simulate API call
                setTimeout(() => {
                    alert(`Thank you for subscribing with ${email}! You'll receive style inspiration weekly.`);
                    this.reset();
                }, 300);
            } else {
                alert('Please enter a valid email address.');
            }
        });
    });
});