import './style.scss';

export default new Class({
	Extends: Hedera.Form,
	Template: require('./ui.xml')

	,activate() {
		this.$.userModel.setInfo('c', 'myClient', 'hedera');
		this.$.addresses.setInfo('a', 'myAddress', 'hedera');
	}
	
	,onAddAddressClick() {
		this.hash.setAll({
			form: 'account/address',
			address: 0
		});
	}
	
	,onReturnClick() {
		window.history.back();
	}

	,onSetDefaultClick(event, addressId) {
		if (event.defaultPrevented) return;
		this.$.defaultAddress.value = addressId;
		Htk.Toast.showMessage(_('DefaultAddressModified'));
	}
	
	,async onRemoveAddressClick(form) {
		if (confirm(_('AreYouSureDeleteAddress'))) {
			await form.set('isActive', false);
			await form.refresh();
		}
	}
	
	,onEditAddressClick(address) {
		this.hash.setAll({
			form: 'account/address',
			address
		});
	}
});

