File size: 10,249 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
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
class Router {
    constructor() {
        this.routes = {
            '/login': this.renderLogin,
            '/register': this.renderRegister,
            '/dashboard': this.renderDashboard,
            '/projects': this.renderProjects,
            '/projects/:id': this.renderProjectDetail,
            '/buckets/:id': this.renderBucketDetail,
            '/api-keys': this.renderApiKeys,
            '/settings': this.renderSettings
        };

        window.addEventListener('hashchange', () => this.handleRoute());
        this.handleRoute();
    }

    handleRoute() {
        const path = window.location.hash.substring(1) || '/dashboard';
        const route = Object.keys(this.routes).find(r => {
            if (r.includes(':')) {
                const basePath = r.split('/:')[0];
                return path.startsWith(basePath);
            }
            return r === path;
        });

        if (route) {
            this.routes[route]();
        } else {
            this.renderNotFound();
        }
    }

    renderLogin() {
        document.getElementById('auth-container').innerHTML = `
            <bucketmaster-auth type="login"></bucketmaster-auth>
        `;
    }

    renderRegister() {
        document.getElementById('auth-container').innerHTML = `
            <bucketmaster-auth type="register"></bucketmaster-auth>
        `;
    }

    renderDashboard() {
        document.getElementById('page-content').innerHTML = `
            <h1 class="text-2xl font-bold mb-6">Dashboard</h1>
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                <bucketmaster-card title="Projects" value="${store.state.projects.length}" icon="folder"></bucketmaster-card>
                <bucketmaster-card title="Buckets" value="${store.state.buckets.length}" icon="database"></bucketmaster-card>
                <bucketmaster-card title="Storage Used" value="2.5 GB" icon="hard-drive"></bucketmaster-card>
            </div>
        `;
    }

    renderProjects() {
        document.getElementById('page-content').innerHTML = `
            <div class="flex justify-between items-center mb-6">
                <h1 class="text-2xl font-bold">Projects</h1>
                <bucketmaster-button id="create-project-btn" icon="plus">New Project</bucketmaster-button>
            </div>
            ${store.state.projects.length > 0 ? `
                <bucketmaster-table>
                    ${store.state.projects.map(project => `
                        <tr class="hover:bg-sun/10 transition-200 cursor-pointer" data-project-id="${project.id}">
                            <td>${project.name}</td>
                            <td>${project.buckets.length} buckets</td>
                            <td>${new Date(project.createdAt).toLocaleDateString()}</td>
                        </tr>
                    `).join('')}
                </bucketmaster-table>
            ` : `
                <bucketmaster-empty-state 
                    title="No projects yet"
                    description="Get started by creating your first project"
                    action-text="Create Project"
                    action-id="create-project-btn"
                    icon="folder-plus">
                </bucketmaster-empty-state>
            `}
        `;
    }

    renderProjectDetail() {
        const projectId = window.location.hash.split('/')[2];
        store.setCurrentProject(projectId);
        
        document.getElementById('page-content').innerHTML = `
            <div class="flex justify-between items-center mb-6">
                <h1 class="text-2xl font-bold">${store.state.currentProject?.name || 'Project'}</h1>
                <bucketmaster-button id="create-bucket-btn" icon="plus">New Bucket</bucketmaster-button>
            </div>
            ${store.state.currentProject?.buckets.length > 0 ? `
                <bucketmaster-table>
                    ${store.state.currentProject.buckets.map(bucket => `
                        <tr class="hover:bg-sun/10 transition-200 cursor-pointer" data-bucket-id="${bucket.id}">
                            <td>${bucket.name}</td>
                            <td>${bucket.files.length} files</td>
                            <td>${bucket.size}</td>
                            <td>${new Date(bucket.createdAt).toLocaleDateString()}</td>
                        </tr>
                    `).join('')}
                </bucketmaster-table>
            ` : `
                <bucketmaster-empty-state 
                    title="No buckets yet"
                    description="Create your first bucket to start uploading files"
                    action-text="Create Bucket"
                    action-id="create-bucket-btn"
                    icon="database">
                </bucketmaster-empty-state>
            `}
        `;
    }

    renderBucketDetail() {
        const bucketId = window.location.hash.split('/')[2];
        store.setCurrentBucket(bucketId);
        
        document.getElementById('page-content').innerHTML = `
            <div class="flex justify-between items-center mb-6">
                <h1 class="text-2xl font-bold">${store.state.currentBucket?.name || 'Bucket'}</h1>
                <bucketmaster-button id="upload-file-btn" icon="upload">Upload File</bucketmaster-button>
            </div>
            ${store.state.currentBucket?.files.length > 0 ? `
                <bucketmaster-table>
                    ${store.state.currentBucket.files.map(file => `
                        <tr>
                            <td class="flex items-center">
                                <i data-feather="${file.icon}" class="file-icon file-icon-${file.type.toLowerCase()}"></i>
                                ${file.name}
                            </td>
                            <td>${file.size}</td>
                            <td>${file.type}</td>
                            <td>${new Date(file.uploadedAt).toLocaleDateString()}</td>
                            <td class="text-right">
                                <div class="flex space-x-2">
                                    <button class="text-metal hover:text-sun transition-200" data-file-id="${file.id}" data-action="download">
                                        <i data-feather="download"></i>
                                    </button>
                                    <button class="text-metal hover:text-red-500 transition-200" data-file-id="${file.id}" data-action="delete">
                                        <i data-feather="trash-2"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                    `).join('')}
                </bucketmaster-table>
            ` : `
                <bucketmaster-empty-state 
                    title="No files yet"
                    description="Upload your first file to this bucket"
                    action-text="Upload File"
                    action-id="upload-file-btn"
                    icon="file">
                </bucketmaster-empty-state>
            `}
        `;
    }

    renderApiKeys() {
        document.getElementById('page-content').innerHTML = `
            <div class="flex justify-between items-center mb-6">
                <h1 class="text-2xl font-bold">API Keys</h1>
                <bucketmaster-button id="create-api-key-btn" icon="plus">New API Key</bucketmaster-button>
            </div>
            ${store.state.apiKeys.length > 0 ? `
                <bucketmaster-table>
                    ${store.state.apiKeys.map(key => `
                        <tr>
                            <td>${key.name}</td>
                            <td>${key.key.substring(0, 8)}...</td>
                            <td>${new Date(key.createdAt).toLocaleDateString()}</td>
                            <td class="text-right">
                                <button class="text-metal hover:text-red-500 transition-200" data-key-id="${key.id}">
                                    <i data-feather="trash-2"></i>
                                </button>
                            </td>
                        </tr>
                    `).join('')}
                </bucketmaster-table>
            ` : `
                <bucketmaster-empty-state 
                    title="No API Keys"
                    description="Create your first API key to access the BucketMaster API"
                    action-text="Create API Key"
                    action-id="create-api-key-btn"
                    icon="key">
                </bucketmaster-empty-state>
            `}
        `;
    }

    renderSettings() {
        document.getElementById('page-content').innerHTML = `
            <h1 class="text-2xl font-bold mb-6">Settings</h1>
            <div class="bg-pure rounded-lg shadow p-6 max-w-2xl">
                <h2 class="text-xl font-semibold mb-4">Account</h2>
                <form id="account-form" class="space-y-4">
                    <div>
                        <label class="block text-metal mb-1">Name</label>
                        <input type="text" value="${store.state.user?.name || ''}" class="w-full px-3 py-2 border border-metal-200 rounded">
                    </div>
                    <div>
                        <label class="block text-metal mb-1">Email</label>
                        <input type="email" value="${store.state.user?.email || ''}" class="w-full px-3 py-2 border border-metal-200 rounded">
                    </div>
                    <div class="pt-4">
                        <bucketmaster-button type="submit">Save Changes</bucketmaster-button>
                    </div>
                </form>
            </div>
        `;
    }

    renderNotFound() {
        document.getElementById('page-content').innerHTML = `
            <bucketmaster-empty-state 
                title="Page Not Found"
                description="The page you're looking for doesn't exist"
                action-text="Go to Dashboard"
                action-id="go-to-dashboard"
                icon="alert-circle">
            </bucketmaster-empty-state>
        `;
    }
}

const router = new Router();
export default router;