/* global LIMITS */
const html = require('choo/html');
const { bytes, platform } = require('../utils');
const { canceledSignup, submittedSignup } = require('../metrics');
module.exports = function(trigger) {
return function(state, emit, close) {
const hidden = platform() === 'android' ? 'hidden' : '';
let submitting = false;
return html`
${state.translate('accountBenefitTitle')}
- ${state.translate('accountBenefitLargeFiles', {
size: bytes(LIMITS.MAX_FILE_SIZE)
})}
- ${state.translate('accountBenefitExpiry')}
- ${state.translate('accountBenefitExpiryTwo')}
- ${state.translate('accountBenefitSync')}
`;
function emailish(str) {
if (!str) {
return false;
}
// just check if it's the right shape
const a = str.split('@');
return a.length === 2 && a.every(s => s.length > 0);
}
function cancel(event) {
canceledSignup({ trigger });
close(event);
}
function submitEmail(event) {
event.preventDefault();
if (submitting) {
return;
}
submitting = true;
const el = document.getElementById('email-input');
const email = el.value;
submittedSignup({ trigger });
emit('login', emailish(email) ? email : null);
}
};
};