const React = require('react');
const _ = require('lodash');
const cx = require('classnames');

const Nav = require('naturalcrit/nav/nav.jsx');
const Navbar = require('../../navbar/navbar.jsx');
const PrintLink = require('../../navbar/print.navitem.jsx');
const ReportIssue = require('../../navbar/issue.navitem.jsx');
//const RecentlyViewed = require('../../navbar/recent.navitem.jsx').viewed;
const Account = require('../../navbar/account.navitem.jsx');

const BrewRenderer = require('homebrewery/brewRenderer/brewRenderer.jsx');
const Utils = require('homebrewery/utils.js');

const Actions = require('homebrewery/brew.actions.js');
const Store = require('homebrewery/brew.store.js');

const SharePage = React.createClass({
	getDefaultProps: function() {
		return {
			brew : {
				title : '',
				text : '',
				shareId : null,
				createdAt : null,
				updatedAt : null,
				views : 0
			}
		};
	},

	componentDidMount: function() {
		document.addEventListener('keydown', this.handleControlKeys);
	},
	componentWillUnmount: function() {
		document.removeEventListener('keydown', this.handleControlKeys);
	},
	handleControlKeys : Utils.controlKeys({
		p : Actions.print
	}),

	render : function(){
		const brew = Store.getBrew();
		return <div className='sharePage page'>
			<Navbar>
				<Nav.section>
					<Nav.item className='brewTitle'>{brew.title}</Nav.item>
				</Nav.section>

				<Nav.section>
					<ReportIssue />
					<PrintLink shareId={brew.shareId} />
					<Nav.item href={'/source/' + brew.shareId} color='teal' icon='fa-code'>
						source
					</Nav.item>
					<Account />
				</Nav.section>
			</Navbar>
			<div className='content'>
				<BrewRenderer brewText={brew.text} />
			</div>
		</div>
	}
});

module.exports = SharePage;
