File size: 13,298 Bytes
025db54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
// Gridiron Nexus Command - Main JavaScript

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

    // Dashboard Role Selection
    const roleCards = document.querySelectorAll('.dashboard-role-card');
    roleCards.forEach(card => {
        card.addEventListener('click', function() {
            // Remove active class from all cards
            roleCards.forEach(c => c.classList.remove('active'));
            
            // Add active class to clicked card
            this.classList.add('active');
            
            const role = this.dataset.role;
            simulateDashboardChange(role);
            
            // Show notification
            showNotification(`Switched to ${role.charAt(0).toUpperCase() + role.slice(1)} Dashboard`);
        });
    });

    // Map Layer Toggles
    const mapToggles = document.querySelectorAll('.map-toggle');
    mapToggles.forEach(toggle => {
        toggle.addEventListener('click', function() {
            const layer = this.dataset.layer;
            
            // Update active state
            mapToggles.forEach(t => t.classList.remove('bg-primary-700', 'text-white'));
            this.classList.add('bg-primary-700', 'text-white');
            
            // Simulate layer change
            simulateMapLayerChange(layer);
        });
    });

    // Live Data Simulation
    let liveDataInterval;
    function startLiveDataSimulation() {
        if (liveDataInterval) clearInterval(liveDataInterval);
        
        liveDataInterval = setInterval(() => {
            // Update live metrics
            updateLiveMetrics();
            
            // Animate data points
            animateDataBreath();
        }, 3000); // Update every 3 seconds
    }

    function updateLiveMetrics() {
        const metrics = document.querySelectorAll('.ai-insight-card p span');
        metrics.forEach(metric => {
            if (metric.textContent.includes('%')) {
                const currentValue = parseInt(metric.textContent);
                const change = Math.random() * 5 - 2.5; // Random change between -2.5 and +2.5
                const newValue = Math.max(0, Math.min(100, Math.round(currentValue + change)));
                metric.textContent = `${newValue}%`;
                
                // Add visual feedback
                metric.style.color = newValue > currentValue ? '#10b981' : '#ef4444';
                setTimeout(() => {
                    metric.style.color = '';
                }, 1000);
            }
        });
    }

    function animateDataBreath() {
        const breathElements = document.querySelectorAll('.animate-breath');
        breathElements.forEach(el => {
            el.style.animation = 'none';
            setTimeout(() => {
                el.style.animation = 'breath 6s ease-in-out infinite';
            }, 10);
        });
    }

    // Simulate Dashboard Change
    function simulateDashboardChange(role) {
        const insights = document.querySelectorAll('.ai-insight-card');
        const roleInsights = {
            coach: ['Game Management', 'Clock Control', 'Timeout Optimization'],
            analyst: ['Predictive Models', 'Trend Analysis', 'Statistical Significance'],
            scout: ['Player Evaluation', 'Opponent Weaknesses', 'Talent Projection'],
            player: ['Performance Review', 'Matchup Analysis', 'Development Goals']
        };
        
        insights.forEach((insight, index) => {
            const title = insight.querySelector('h4');
            const content = insight.querySelector('p');
            
            if (title && content) {
                title.textContent = `${roleInsights[role][index] || 'AI Insight'}`;
                content.textContent = getRandomInsightForRole(role);
                
                // Add animation
                insight.style.animation = 'slideInRight 0.5s ease-out';
                setTimeout(() => {
                    insight.style.animation = '';
                }, 500);
            }
        });
    }

    function getRandomInsightForRole(role) {
        const insights = {
            coach: [
                'Zone coverage showing 15% vulnerability on deep left side.',
                'Red zone efficiency up 8% when using 2-TE sets.',
                'Third down conversion rate optimal from 11 personnel.'
            ],
            analyst: [
                'EPA model predicts +0.12 advantage with RPO calls.',
                'Correlation detected between defensive alignment and run success.',
                'Machine learning identifies new passing lane vulnerability.'
            ],
            scout: [
                'WR prospect shows 95th percentile separation on go routes.',
                'DT anchor strength metrics exceed NFL average by 12%.',
                'RB vision score improved 22% over last season.'
            ],
            player: [
                'Your release time improved 0.08s from last game.',
                'Route efficiency at 92% on crossing patterns.',
                'Top speed reached 21.3 mph, career high.'
            ]
        };
        
        const roleInsights = insights[role] || insights.coach;
        return roleInsights[Math.floor(Math.random() * roleInsights.length)];
    }

    // Simulate Map Layer Change
    function simulateMapLayerChange(layer) {
        const map = document.querySelector('.map-visualization');
        if (!map) return;
        
        // Remove existing layer classes
        map.classList.remove('heatmap-active', 'tracking-active', 'zones-active');
        
        // Add new layer class
        map.classList.add(`${layer}-active`);
        
        // Update visual elements based on layer
        const aiCircle = map.querySelector('.ai-circle');
        if (aiCircle) {
            switch(layer) {
                case 'heatmap':
                    aiCircle.style.borderColor = '#ef4444';
                    aiCircle.querySelector('span').textContent = 'HOT';
                    break;
                case 'tracking':
                    aiCircle.style.borderColor = '#06b6d4';
                    aiCircle.querySelector('span').textContent = 'TRK';
                    break;
                case 'zones':
                    aiCircle.style.borderColor = '#10b981';
                    aiCircle.querySelector('span').textContent = 'ZONE';
                    break;
            }
        }
    }

    // Show Notification
    function showNotification(message, type = 'info') {
        const notification = document.createElement('div');
        notification.className = `fixed top-4 right-4 px-6 py-3 rounded-lg shadow-lg z-50 transform translate-x-full transition-transform duration-300 ${
            type === 'success' ? 'bg-green-900/90 border-l-4 border-green-500' :
            type === 'error' ? 'bg-red-900/90 border-l-4 border-red-500' :
            'bg-surface border-l-4 border-primary-500'
        }`;
        
        notification.innerHTML = `
            <div class="flex items-center">
                <i data-feather="${type === 'success' ? 'check-circle' : type === 'error' ? 'alert-circle' : 'info'}" class="mr-3"></i>
                <span>${message}</span>
            </div>
        `;
        
        document.body.appendChild(notification);
        
        // Animate in
        setTimeout(() => {
            notification.style.transform = 'translateX(0)';
        }, 10);
        
        // Animate out and remove
        setTimeout(() => {
            notification.style.transform = 'translateX(100%)';
            setTimeout(() => {
                document.body.removeChild(notification);
            }, 300);
        }, 3000);
        
        // Replace feather icon
        if (typeof feather !== 'undefined') {
            feather.replace();
        }
    }

    // Initialize Tooltips
    function initializeTooltips() {
        const tooltipElements = document.querySelectorAll('[data-tooltip]');
        tooltipElements.forEach(el => {
            el.addEventListener('mouseenter', showTooltip);
            el.addEventListener('mouseleave', hideTooltip);
        });
    }

    function showTooltip(e) {
        const tooltipText = this.dataset.tooltip;
        if (!tooltipText) return;
        
        const tooltip = document.createElement('div');
        tooltip.className = 'fixed z-50 px-3 py-2 text-sm bg-gray-900 text-gray-100 rounded-lg shadow-lg border border-gray-700';
        tooltip.textContent = tooltipText;
        
        document.body.appendChild(tooltip);
        
        const rect = this.getBoundingClientRect();
        tooltip.style.left = `${rect.left + rect.width / 2 - tooltip.offsetWidth / 2}px`;
        tooltip.style.top = `${rect.top - tooltip.offsetHeight - 10}px`;
        
        this._tooltip = tooltip;
    }

    function hideTooltip(e) {
        if (this._tooltip) {
            document.body.removeChild(this._tooltip);
            this._tooltip = null;
        }
    }

    // Sports API Integration Example
    async function fetchSportsData() {
        try {
            // Example using a public sports API (using NFL schedule as example)
            const response = await fetch('https://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard');
            const data = await response.json();
            
            // You would process the data here
            console.log('Sports data loaded:', data);
            
            // Update UI with live data if needed
            if (data.events && data.events.length > 0) {
                updateLiveScores(data.events);
            }
        } catch (error) {
            console.warn('Could not fetch live sports data:', error);
            // Fallback to simulated data
            simulateLiveScores();
        }
    }

    function updateLiveScores(events) {
        // Update a scores widget if it exists
        const scoresWidget = document.getElementById('live-scores');
        if (scoresWidget && events.length > 0) {
            const firstGame = events[0];
            const homeTeam = firstGame.competitions[0].competitors.find(c => c.homeAway === 'home');
            const awayTeam = firstGame.competitions[0].competitors.find(c => c.homeAway === 'away');
            
            scoresWidget.innerHTML = `
                <div class="text-xs text-gray-400 mb-1">LIVE</div>
                <div class="flex items-center justify-between">
                    <div class="flex items-center">
                        <span class="font-bold">${awayTeam.team.abbreviation}</span>
                        <span class="ml-2">${awayTeam.score}</span>
                    </div>
                    <div class="text-gray-500">@</div>
                    <div class="flex items-center">
                        <span class="font-bold">${homeTeam.team.abbreviation}</span>
                        <span class="ml-2">${homeTeam.score}</span>
                    </div>
                </div>
            `;
        }
    }

    function simulateLiveScores() {
        // Simulated live scores for demo
        const scores = [
            { away: 'KC', awayScore: 24, home: 'BUF', homeScore: 27, quarter: '4th', time: '2:15' },
            { away: 'SF', awayScore: 31, home: 'PHI', homeScore: 28, quarter: 'FINAL', time: '' },
            { away: 'DAL', awayScore: 17, home: 'GB', homeScore: 20, quarter: '3rd', time: '8:42' }
        ];
        
        // Update a scores widget if it exists
        const scoresWidget = document.getElementById('live-scores');
        if (scoresWidget) {
            const randomGame = scores[Math.floor(Math.random() * scores.length)];
            scoresWidget.innerHTML = `
                <div class="text-xs text-gray-400 mb-1">${randomGame.quarter} ${randomGame.time}</div>
                <div class="flex items-center justify-between">
                    <div class="flex items-center">
                        <span class="font-bold">${randomGame.away}</span>
                        <span class="ml-2">${randomGame.awayScore}</span>
                    </div>
                    <div class="text-gray-500">@</div>
                    <div class="flex items-center">
                        <span class="font-bold">${randomGame.home}</span>
                        <span class="ml-2">${randomGame.homeScore}</span>
                    </div>
                </div>
            `;
        }
    }

    // Initialize everything
    function init() {
        startLiveDataSimulation();
        initializeTooltips();
        
        // Fetch live sports data (commented out for demo - uncomment with real API)
        // fetchSportsData();
        
        // Simulate live scores for demo
        simulateLiveScores();
        
        // Set first role card as active
        if (roleCards.length > 0) {
            roleCards[0].classList.add('active');
        }
        
        // Set first map toggle as active
        if (mapToggles.length > 0) {
            mapToggles[0].classList.add('bg-primary-700', 'text-white');
        }
        
        console.log('Gridiron Nexus Command initialized');
    }

    // Start initialization
    init();
});