File size: 3,688 Bytes
0c45221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
```javascript
import store from './store.js';
import router from './router.js';

document.addEventListener('DOMContentLoaded', () => {
    // Initialize Feather Icons
    if (window.feather) {
        feather.replace();
    }

    // Check auth state
    if (!store.state.user) {
        window.location.hash = '#/login';
        document.getElementById('app-container').classList.add('hidden');
        document.getElementById('auth-container').classList.remove('hidden');
    } else {
        document.getElementById('app-container').classList.remove('hidden');
        document.getElementById('auth-container').classList.add('hidden');
    }

    // Set up event listeners
    document.addEventListener('click', (e) => {
        // Handle project clicks
        if (e.target.closest('[data-project-id]')) {
            const projectId = e.target.closest('[data-project-id]').getAttribute('data-project-id');
            window.location.hash = `#/projects/${projectId}`;
        }

        // Handle bucket clicks
        if (e.target.closest('[data-bucket-id]')) {
            const bucketId = e.target.closest('[data-bucket-id]').getAttribute('data-bucket-id');
            window.location.hash = `#/buckets/${bucketId}`;
        }

        // Handle file actions
        if (e.target.closest('[data-file-id]')) {
            const fileId = e.target.closest('[data-file-id]').getAttribute('data-file-id');
            const action = e.target.closest('[data-file-id]').getAttribute('data-action');
            
            if (action === 'download') {
                store.addNotification({
                    id: Date.now(),
                    type: 'success',
                    message: 'Download started'
                });
            } else if (action === 'delete') {
                store.removeFile(fileId);
                store.addNotification({
                    id: Date.now(),
                    type: 'success',
                    message: 'File deleted'
                });
            }
        }

        // Handle API key deletion
        if (e.target.closest('[data-key-id]')) {
            const keyId = e.target.closest('[data-key-id]').getAttribute('data-key-id');
            store.removeApiKey(keyId);
            store.addNotification({
                id: Date.now(),
                type: 'success',
                message: 'API key deleted'
            });
        }

        // Handle create project button
        if (e.target.closest('#create-project-btn')) {
            const modal = document.createElement('bucketmaster-modal');
            modal.setAttribute('title', 'Create Project');
            modal.innerHTML = `
                <form id="create-project-form" class="space-y-4">
                    <div>
                        <label class="block text-metal mb-1">Project Name</label>
                        <input type="text" required class="w-full px-3 py-2 border border-metal-200 rounded">
                    </div>
                    <div class="pt-2">
                        <bucketmaster-button type="submit">Create Project</bucketmaster-button>
                    </div>
                </form>
            `;
            document.body.appendChild(modal);
        }

        // Handle create bucket button
        if (e.target.closest('#create-bucket-btn')) {
            const modal = document.createElement('bucketmaster-modal');
            modal.setAttribute('title', 'Create Bucket');
            modal.innerHTML = `
                <form id="create-bucket-form" class="space-y-4">
                    <div>
                        <label class="block text-metal mb-1">Bucket Name</label>
                        <