`,
this,
);
}
async _onSelect(account) {
if (this.state.$pendingAction.get() !== null) {
return;
}
if (account.did === this.state.$currentDid.get()) {
this.close();
return;
}
if (account.needsReauth) {
this.state.$pendingAction.set({ type: "switch", did: account.did });
try {
await this.auth.login({
handle: account.handle,
returnTo: window.location.pathname + window.location.search,
});
} catch (error) {
this.state.$pendingAction.set(null);
showToast(getLoginErrorMessage(error), { style: "error" });
}
return;
}
this.state.$pendingAction.set({ type: "switch", did: account.did });
try {
await this.auth.switchAccount(account.did);
} catch {
this.state.$pendingAction.set(null);
showToast("Failed to switch account", { style: "error" });
}
}
_onAdd() {
if (this.state.$pendingAction.get() !== null) {
return;
}
this.state.$pendingAction.set({ type: "add" });
window.location.href = linkToLogin({ query: { addAccount: 1 } });
}
open() {
this.scrollLock ??= scrollLocks.acquire({ target: this });
const dialog = this.querySelector("dialog");
if (dialog?.open) return;
dialog.showModal();
enableDragToDismiss(dialog, {
onDismiss: () => this.close(),
confirmDismiss: () => this.state.$pendingAction.get() === null,
allowOppositeStretch: true,
ignoreTouchTarget: (element) => element.closest("button") !== null,
});
}
close() {
return closeWithAnimation(this.querySelector("dialog"));
}
}
AccountSwitcherDialog.register();