import React, { Component } from "react";
import PropTypes from 'prop-types';

import { fetchEntity, saveEntity, selector } from './redux.js';
import { connect } from 'react-redux';
import { injectIntl } from 'react-intl';

import SettingsForm from "components/SettingsForm";
import { ActivityIndicator, PortalContainer, PortalLinks, PortalLink, PageTitle } from 'lib/components';

import Toast from 'components/Toast';

import { updateIntl } from 'lib/i18n';
import { fromJS } from 'immutable';
import icons from 'constants/icons';

export { default as About } from './About';
export { default as Company } from './Company';
export { default as Customization } from './Customization';
export { default as Local } from './Local';
export { default as Password } from './Password';
export { default as Tax } from './Tax';
export { default as Payment } from './Payment';
export { default as LinkedAccounts } from './LinkedAccounts';

import messages from './messages';


require("./style.scss");


class Settings extends Component {

	render() {
		let { router } = this.context;
		let intl = this.props.intl;

		return (
			<div>
				<PortalContainer>
					<div className="pv10">
						<PageTitle title={ intl.formatMessage(messages.title) } titleIcon={ icons.settings } />
					</div>

					<PortalLinks>
						<PortalLink 
							icon=""
							title={ intl.formatMessage(messages.passwordTitle) }
							description={ intl.formatMessage(messages.passwordDescription) }
							className="settings-password"
							onClick={ () => router.push('/settings/password') } />
						<PortalLink 
							icon=""
							title={ intl.formatMessage(messages.companyTitle) }
							description={ intl.formatMessage(messages.companyDescription) }
							className="settings-company"
							onClick={ () => router.push('/settings/company') } />
					</PortalLinks>

					<PortalLinks>
						<PortalLink
							icon="" 
							title={ intl.formatMessage(messages.localTitle) }
							description={ intl.formatMessage(messages.localDescription) }
							className="settings-local"
							onClick={ () => router.push('/settings/local') } />
						<PortalLink 
							icon=""
							title={ intl.formatMessage(messages.taxTitle) }
							description={ intl.formatMessage(messages.taxDescription) }
							className="settings-taxes"
							onClick={ () => router.push('/settings/taxes') } />
					</PortalLinks>

					<PortalLinks>
						<PortalLink 
							icon=""
							title={ intl.formatMessage(messages.paymentTitle) }
							description={ intl.formatMessage(messages.paymentDescription) }
							className="settings-payment"
							onClick={ () => router.push('/settings/payment') } />
						<PortalLink 
							icon=""
							title={ intl.formatMessage(messages.customizationTitle) }
							description={ intl.formatMessage(messages.customizationDescription) }
							className="settings-customization"
							onClick={ () => router.push('/settings/customization') } />
					</PortalLinks>

					<PortalLinks>
						<PortalLink 
							icon={ icons.linkedAccountsSettings }
							title={ intl.formatMessage(messages.linkedAccountsTitle) }
							description={ intl.formatMessage(messages.linkedAccountsDescription) }
							className="settings-linked-accounts"
							onClick={ () => router.push('/settings/linked') } />
					</PortalLinks>

					<PortalLinks>
						<PortalLink 
							icon=""
							title={ intl.formatMessage(messages.aboutTitle) }
							description={ intl.formatMessage(messages.aboutDescription) }
							className="settings-about"
							onClick={ () => router.push('/settings/about') } />
					</PortalLinks>
				</PortalContainer>
			</div>
		);
	}

}


Settings.contextTypes = {
	router: PropTypes.object.isRequired
};



function mapDispatchToProps(dispatch, props) {
	return {
    	dispatch,
    	fetchEntity: (unitId) => dispatch(fetchEntity(unitId, { unitId })),
    	saveEntity: (unitId, data) => dispatch(saveEntity(unitId, data, { unitId })),
    	updateIntl: (locale, messages) => dispatch(updateIntl(locale))
  	};
}


export default injectIntl(connect(selector, mapDispatchToProps)(Settings));
