var React = require('react');
var request = require('superagent');

var CreateForm = require('../components/CreateForm');
var EditForm = require('../components/EditForm');
var EditFormHeader = require('../components/EditFormHeader');

var Spinner = require('elemental').Spinner;

var View = React.createClass({

	displayName: 'ItemView',

	getInitialState () {
		return {
			createIsOpen: false,
			list: Keystone.list,
			itemData: null
		};
	},

	componentDidMount () {
		this.loadItemData();
	},

	loadItemData () {
		request.get('/keystone/api/' + Keystone.list.path + '/' + this.props.itemId + '?drilldown=true')
			.set('Accept', 'application/json')
			.end((err, res) => {
				if (err || !res.ok) {
					// TODO: nicer error handling
					console.log('Error loading item data:', res ? res.text : err);
					alert('Error loading data (details logged to console)');
					return;
				}
				this.setState({
					itemData: res.body
				});
			});
	},

	toggleCreate (visible) {
		this.setState({
			createIsOpen: visible
		});
	},

	renderCreateForm () {
		return <CreateForm list={Keystone.list} isOpen={this.state.createIsOpen} onCancel={this.toggleCreate.bind(this, false)} />;
	},

	render () {
		if (!this.state.itemData) return <div className="view-loading-indicator"><Spinner /></div>;
		return (
			<div>
				<EditFormHeader list={this.state.list} data={this.state.itemData} drilldown={this.state.itemDrilldown} toggleCreate={this.toggleCreate} />
				<div className="container">
					{this.renderCreateForm()}
					<EditForm list={this.state.list} data={this.state.itemData} />
				</div>
			</div>
		);
	}

});

React.render(<View itemId={Keystone.itemId} />, document.getElementById('item-view'));

@@ -235,16 +235,18 @@
 %0Avar
+ %7B
  Spinner
  = r
@@ -241,16 +241,18 @@
  Spinner
+ %7D
  = requi
@@ -270,16 +270,8 @@
 al')
-.Spinner
 ;%0A%0Av
@@ -1273,16 +1273,26 @@
 %3CSpinner
+ size=%22md%22
  /%3E%3C/div

fix spinner (use medium) on item view