File size: 8,077 Bytes
128987f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// Age verification functionality
document.addEventListener('DOMContentLoaded', function() {
    // Initialize feather icons
    if (typeof feather !== 'undefined') {
        feather.replace();
    }

    // Age verification logic
    const ageVerification = document.getElementById('ageVerification');
    const mainContent = document.getElementById('mainContent');
    const enterButton = document.getElementById('enterSite');
    const exitButton = document.getElementById('exitSite');

    // Check if user has already verified age
    const hasVerified = localStorage.getItem('ageVerified');
    if (hasVerified === 'true') {
        ageVerification.classList.add('hidden');
        mainContent.classList.remove('hidden');
    }

    enterButton.addEventListener('click', function() {
        localStorage.setItem('ageVerified', 'true');
        ageVerification.classList.add('hidden');
        mainContent.classList.remove('hidden');
        
        // Re-initialize feather icons for main content
        if (typeof feather !== 'undefined') {
            setTimeout(() => feather.replace(), 100);
        }
    });

    exitButton.addEventListener('click', function() {
        window.location.href = 'https://www.google.com';
    });

    // Theme toggle functionality
    const themeToggle = document.getElementById('themeToggle');
    const themeIcon = themeToggle.querySelector('i');

    themeToggle.addEventListener('click', function() {
        const html = document.documentElement;
        if (html.classList.contains('dark')) {
            html.classList.remove('dark');
            themeIcon.setAttribute('data-feather', 'moon');
        localStorage.setItem('theme', 'light');
    } else {
        html.classList.add('dark');
        themeIcon.setAttribute('data-feather', 'sun');
        localStorage.setItem('theme', 'dark');
    }
    
    if (typeof feather !== 'undefined') {
        feather.replace();
    }
    });

    // Set initial theme based on localStorage or system preference
    const savedTheme = localStorage.getItem('theme');
    if (savedTheme === 'dark' || (!savedTheme && window.matchMedia('(prefers-color-scheme: dark)').matches) {
        document.documentElement.classList.add('dark');
        themeIcon.setAttribute('data-feather', 'sun');
        if (typeof feather !== 'undefined') {
            feather.replace();
        }
    }

    // Upload modal functionality
    const uploadTrigger = document.getElementById('uploadTrigger');
    const uploadModal = document.getElementById('uploadModal');
    const closeModal = document.getElementById('closeModal');
    const cancelUpload = document.getElementById('cancelUpload');
    const uploadArea = document.getElementById('uploadArea');
    const fileInput = document.getElementById('fileInput');
    const uploadProgress = document.getElementById('uploadProgress');
    const progressBar = document.getElementById('progressBar');
    const uploadError = document.getElementById('uploadError');
    const confirmUpload = document.getElementById('confirmUpload');

    let selectedFile = null;

    // Open modal
    uploadTrigger.addEventListener('click', function() {
        uploadModal.classList.remove('hidden');
        resetUploadState();
    });

    // Close modal functions
    function closeUploadModal() {
        uploadModal.classList.add('hidden');
        resetUploadState();
    }

    closeModal.addEventListener('click', closeUploadModal);
    cancelUpload.addEventListener('click', closeUploadModal);

    // Click outside modal to close
    uploadModal.addEventListener('click', function(e) {
        if (e.target === uploadModal) {
            closeUploadModal();
        }
    });

    // File upload handling
    uploadArea.addEventListener('click', function() {
        fileInput.click();
    });

    uploadArea.addEventListener('dragover', function(e) {
        e.preventDefault();
        uploadArea.classList.add('border-primary', 'bg-primary-50', 'dark:bg-primary-900/20');
    });

    uploadArea.addEventListener('dragleave', function() {
        uploadArea.classList.remove('border-primary', 'bg-primary-50', 'dark:bg-primary-900/20');
    });

    uploadArea.addEventListener('drop', function(e) {
        e.preventDefault();
        uploadArea.classList.remove('border-primary', 'bg-primary-50', 'dark:bg-primary-900/20');
        handleFileSelect(e.dataTransfer.files[0]);
    });

    fileInput.addEventListener('change', function(e) {
        if (e.target.files.length > 0) {
            handleFileSelect(e.target.files[0]);
        }
    });

    function handleFileSelect(file) {
        // Validate file type
        const validTypes = ['image/jpeg', 'image/jpg', 'image/png'];
        if (!validTypes.includes(file.type)) {
            showUploadError('Please upload only JPG or PNG files.');
            return;
        }

        // Validate file size (10MB)
        const maxSize = 10 * 1024 * 1024;
        if (file.size > maxSize) {
            showUploadError('File size must be less than 10MB.');
            return;
        }

        selectedFile = file;
        uploadArea.innerHTML = `
            <i data-feather="check" class="w-12 h-12 text-green-500 mx-auto mb-4"></i>
            <p class="text-gray-600 dark:text-gray-300 mb-2">${file.name}</p>
            <p class="text-sm text-gray-500 dark:text-gray-400">${(file.size / 1024 / 1024).toFixed(2)} MB</p>
        `;
        
        confirmUpload.disabled = false;
        
        if (typeof feather !== 'undefined') {
            feather.replace();
        }
    }

    confirmUpload.addEventListener('click', function() {
        if (!selectedFile) return;

        // Show progress bar
        uploadProgress.classList.remove('hidden');
        progressBar.style.width = '0%';

        // Simulate upload progress
        let progress = 0;
        const interval = setInterval(() => {
            progress += Math.random() * 15;
            if (progress > 100) progress = 100;
            progressBar.style.width = progress + '%';

            if (progress === 100) {
                clearInterval(interval);
                simulateAIRating();
            }
        }, 200);
    });

    function simulateAIRating() {
        // Simulate AI processing
        setTimeout(() => {
            // Show success and redirect to results
            alert('Your photo has been analyzed! Here is your brutally honest rating...');
            closeUploadModal();
            // In a real implementation, this would redirect to the results page
        }, 1500);
    }

    function resetUploadState() {
        selectedFile = null;
        uploadArea.innerHTML = `
            <i data-feather="upload" class="w-12 h-12 text-gray-400 mx-auto mb-4"></i>
            <p class="text-gray-600 dark:text-gray-300 mb-2">Click to upload or drag and drop</p>
            <p class="text-sm text-gray-500 dark:text-gray-400">JPG, PNG up to 10MB</p>
        `;
        uploadProgress.classList.add('hidden');
        uploadError.classList.add('hidden');
        confirmUpload.disabled = true;
        fileInput.value = '';
        
        if (typeof feather !== 'undefined') {
            feather.replace();
        }
    }

    function showUploadError(message) {
        uploadError.querySelector('p').textContent = message;
        uploadError.classList.remove('hidden');
        
        setTimeout(() => {
            uploadError.classList.add('hidden');
        }, 5000);
    }

    // Keyboard navigation
    document.addEventListener('keydown', function(e) {
        if (e.key === 'Escape' && !uploadModal.classList.contains('hidden')) {
            closeUploadModal();
        }
    });

    // Performance optimization: Lazy loading for future implementations
    if ('IntersectionObserver' in window) {
        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    // Future: Load content when it comes into view
                }
            });
        });
    }
});