File size: 3,499 Bytes
71ac096
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Shared JavaScript across all pages

// Initialize app
document.addEventListener('DOMContentLoaded', function() {
    console.log('AutoDev Agent Orchestrator Pro loaded successfully! ๐Ÿš€');
    
    // Add loading states for better UX
    const links = document.querySelectorAll('a[href]');
    links.forEach(link => {
        link.addEventListener('click', function(e) {
            if (this.getAttribute('href').startsWith('/') && this.getAttribute('href') !== window.location.pathname) {
                // Show loading state (could be enhanced with a proper loader component)
                document.body.style.opacity = '0.7';
                setTimeout(() => {
                    document.body.style.opacity = '1';
                }, 500);
            }
        });
    });
    
    // Add intersection observer for scroll animations
    const observerOptions = {
        threshold: 0.1,
        rootMargin: '0px 0px -50px 0px'
    };
    
    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.style.opacity = '1';
                entry.target.style.transform = 'translateY(0)';
            }
        });
    }, observerOptions);
    
    // Observe all cards and sections for animation
    document.querySelectorAll('.grid > div, section').forEach(el => {
        el.style.opacity = '0';
        el.style.transform = 'translateY(20px)';
        el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
        observer.observe(el);
    });
});

// API integration for agent status (placeholder)
class AgentAPI {
    static async getAgentStatus(agentId) {
        // This would connect to your backend API
        try {
            const response = await fetch(`/api/agents/${agentId}/status`);
            return await response.json();
        } catch (error) {
            console.error('Failed to fetch agent status:', error);
            return { status: 'unknown', lastActivity: new Date() };
        }
    }
    
    static async startDevelopment(projectData) {
        try {
            const response = await fetch('/api/projects/start', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(projectData)
            });
            return await response.json();
        } catch (error) {
            console.error('Failed to start development:', error);
            return { success: false, projectId: null };
        }
    }
}

// Utility functions
const Utils = {
    // Format date for display
    formatDate: (date) => {
        return new Date(date).toLocaleDateString('en-US', {
            year: 'numeric',
            month: 'short',
            day: 'numeric'
        });
    },
    
    // Debounce function for search and filter inputs
    debounce: (func, wait) => {
        let timeout;
        return function executedFunction(...args) {
            const later = () => {
                clearTimeout(timeout);
                func(...args);
            };
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
        };
    },
    
    // Generate random project ID
    generateProjectId: () => {
        return 'proj_' + Math.random().toString(36).substr(2, 9);
    }
};

// Export for module usage
if (typeof module !== 'undefined' && module.exports) {
    module.exports = { AgentAPI, Utils };
}