`;
document.body.appendChild(modal);
// Setup event listeners
const closeBtn = modal.querySelector('.modal-close');
const closeModalBtn = modal.querySelector('.close-modal');
const createBtn = modal.querySelector('.create-client');
const closeModal = () => {
modal.classList.remove('active');
setTimeout(() => modal.remove(), 300);
};
closeBtn.addEventListener('click', closeModal);
closeModalBtn.addEventListener('click', closeModal);
createBtn.addEventListener('click', () => {
const name = modal.querySelector('#client-name').value;
if (!name.trim()) {
if (window.authManager) {
window.authManager.showToast('Client name is required', 'error');
}
return;
}
// In a real app, this would create the client via API
if (window.authManager) {
window.authManager.showToast(`Client "${name}" created successfully`, 'success');
}
// Refresh clients list
this.loadClients();
closeModal();
});
// Close on background click
modal.addEventListener('click', (e) => {
if (e.target === modal) {
closeModal();
}
});
}
editClient(clientId) {
const client = this.clients.find(c => c.id === clientId);
if (!client) return;
// Show edit modal
const modal = document.createElement('div');
modal.className = 'modal active';
modal.innerHTML = `
Edit Client: ${client.name}
Client editing would be implemented here.
In a real implementation, this would include forms for updating client settings.
`;
document.body.appendChild(modal);
// Setup event listeners
const closeBtn = modal.querySelector('.modal-close');
const closeModalBtn = modal.querySelector('.close-modal');
const saveBtn = modal.querySelector('.save-client');
const closeModal = () => {
modal.classList.remove('active');
setTimeout(() => modal.remove(), 300);
};
closeBtn.addEventListener('click', closeModal);
closeModalBtn.addEventListener('click', closeModal);
saveBtn.addEventListener('click', () => {
// In a real app, this would save client changes
if (window.authManager) {
window.authManager.showToast('Client updated successfully', 'success');
}
closeModal();
});
// Close on background click
modal.addEventListener('click', (e) => {
if (e.target === modal) {
closeModal();
}
});
}
rotateToken(clientId) {
const client = this.clients.find(c => c.id === clientId);
if (!client) return;
// Show confirmation modal
if (confirm(`Are you sure you want to rotate the token for "${client.name}"? The old token will be invalidated.`)) {
// In a real app, this would rotate the token via API
if (window.authManager) {
window.authManager.showToast(`Token rotated for "${client.name}"`, 'success');
}
// Refresh clients list
this.loadClients();
}
}
revokeClient(clientId) {
const client = this.clients.find(c => c.id === clientId);
if (!client) return;
// Show confirmation modal
if (confirm(`Are you sure you want to revoke client "${client.name}"? This action cannot be undone.`)) {
// In a real app, this would revoke the client via API
if (window.authManager) {
window.authManager.showToast(`Client "${client.name}" revoked`, 'success');
}
// Refresh clients list
this.loadClients();
}
}
copyToClipboard(text) {
navigator.clipboard.writeText(text).catch(err => {
console.error('Failed to copy:', err);
});
}
refresh() {
this.loadClients();
this.loadClientUsageChart();
this.loadRateLimitStatus();
}
}
// Initialize clients page when needed
window.initClients = async () => {
window.clientsPage = new ClientsPage();
};
// Export for use in other modules
if (typeof module !== 'undefined' && module.exports) {
module.exports = ClientsPage;
}