// Wire up nav + auth using native <dialog> elements
function bindNavButtons() {
document.getElementById('btn-sign-in').addEventListener('click', signIn);
document.getElementById('btn-sign-out').addEventListener('click', signOut);
document.getElementById('btn-admin-login').addEventListener('click', () => {
// Native <dialog>: call showModal() to open
document.getElementById('dialog-admin-login').showModal();
});
document.getElementById('btn-admin-logout').addEventListener('click', () => {
localStorage.removeItem('adminApiKey');
document.body.classList.remove('admin-active');
document.getElementById('admin-table-container').innerHTML = '';
});
}
// React to Clerk auth changes and keep the top bar in sync
onChange(({ user }) => {
const body = document.body;
if (user) {
body.classList.add('signed-in');
body.classList.remove('signed-out');
document.getElementById('user-name').textContent =
user.firstName || user.emailAddresses?.[0]?.emailAddress || 'User';
loadPrivateNotes();
} else {
body.classList.remove('signed-in');
body.classList.add('signed-out');
document.getElementById('user-name').textContent = '';
document.getElementById('private-notes-grid').innerHTML = '';
}
});