const html = require('choo/html'); const Component = require('choo/component'); class Account extends Component { constructor(name, state, emit) { super(name); this.state = state; this.emit = emit; this.enabled = state.capabilities.account; this.local = state.components[name] = {}; this.buttonClass = ''; this.setState(); } avatarClick(event) { event.preventDefault(); const menu = document.getElementById('accountMenu'); menu.classList.toggle('invisible'); menu.focus(); } hideMenu(event) { event.stopPropagation(); const menu = document.getElementById('accountMenu'); menu.classList.add('invisible'); } login(event) { event.preventDefault(); this.emit('signup-cta', 'button'); } logout(event) { event.preventDefault(); this.emit('logout'); } changed() { return this.local.loggedIn !== this.state.user.loggedIn; } setState() { const changed = this.changed(); if (changed) { this.local.loggedIn = this.state.user.loggedIn; } return changed; } update() { return this.setState(); } createElement() { if (!this.enabled) { return html`
`; } const user = this.state.user; const translate = this.state.translate; if (!this.local.loggedIn) { return html`