/**
 * Created by Mihail on 12/8/2016.
 */
'use strict';

import React from 'react';
import Button from './Button';
import EventsConsts from '../components/EventsConsts';
import SchemaEmail from '../schema-login-email-form';
import Form from './Form';
import CRUDStore from '../flux/CRUDStore';
import ViewManipulator from '../../utils/view-manipulator';

type State = {
	isLogged: boolean,
};

class Login extends React.Component {
	state: State;

	constructor() {
		super();
		this.state = {
			isLogged: CRUDStore.isLoggedIn()
		};

		Login.login = Login.login.bind(this);

		CRUDStore.addListener(EventsConsts.LOGIN_SUCCESS, () => {
			this.setState({isLogged: true});
			ViewManipulator.toggleErrorMessageView(document.querySelector('#errorMsg'),
				'Wrong login details.', false);
		});

		CRUDStore.addListener(EventsConsts.LOGIN_FAILED, () => {
			this.setState({isLogged: false});
			ViewManipulator.toggleErrorMessageView(document.querySelector('#errorMsg'),
				'Wrong login details.', true);
		});

		CRUDStore.addListener(EventsConsts.LOGOUT, () => {
			this.setState({isLogged: false});
		});
	}

	static login() {
		CRUDStore.checkLogin(this.refs.loginForm.getData());
	}

	render() {
		return <div style={{display: this.state.isLogged ? 'none' : 'block'}}>
			<h3>Bingo Bigul Back Office Login</h3>
			<Form fields={SchemaEmail} ref="loginForm" />
			<Button onClick={Login.login}>
				Login
			</Button>
			<footer>
				<span>© 2016 Copyrights <a href="mailto: me@mihail-gaberov.eu">Mihail Gaberov</a>.</span>
			</footer>
		</div>
	}
}
export default Login
@@ -1441,25 +1441,99 @@
 pan%3E
-%C2%A9 2016 Copyrights
+&copy; 2016%7Bnew Date().getFullYear()%3E2016 && document.write(%22-%22+new Date().getFullYear());%7D
  %3Ca 
@@ -1638,12 +1638,13 @@
 efault Login
+%0A

Update Login.js