const h = require('hyperscript') const TITLE = 'double - acounts' const Nav = require('../components/nav') function accountsView (state, emit) { return h('body.code.ph3.lh-copy', [ state.cache(Nav, 'nav').render(), h('table', [ h('thead', h('tr', [ h('td.pr2.red', 'account'), h('td.pr2', 'balance') ])), h('tbody', Object.keys(state.accounts).map(key => { return state.accounts[key].archived ? h('tr', [ h('td.strike', state.accounts[key].name), h('td.tr.strike', state.accounts[key].debit - state.accounts[key].credit) ]) : h('tr', [ h('td', {onclick: handleAccountArchive}, state.accounts[key].name), h('td.tr', state.accounts[key].debit - state.accounts[key].credit) ]) })) ]), h('div', [ h('div.pt4', 'create a new account'), h('form.pb3', h('input#account')), h('button', { onclick: handleAccountCreate }, 'create') ]) ]) function handleAccountCreate () { const name = document.getElementById('account').value emit('accounts', { type: 'accounts', msg: { name, debit: 0, credit: 0, archived: false } }) } function handleAccountArchive () { const name = this.innerHTML emit('accounts', { type: 'accounts', msg: { name, archived: true } }) } } module.exports = accountsView