import React, { Component } from 'react';
import { Link } from 'react-router-dom'; 

class ErrorC extends Component {
	render() {
		return (
			<React.Fragment>
				{
					this.props.location.state &&
					this.props.location.state.error &&
					<React.Fragment>
					<h1 style={{textAlign:"center", color:"red"}}>Welcome to the error page!</h1>
					<h2 style={{textAlign:"center"}}> {this.props.location.state.error}</h2>
					</React.Fragment>
				}
				{
					this.props.location.state &&
					this.props.location.state.success &&
					<React.Fragment>
					<h1 style={{textAlign:"center", color: "green"}}>You did it! Let's celebrate!</h1>
					<h2 style={{textAlign:"center"}}> {this.props.location.state.success}</h2>
					</React.Fragment>
				}
				{
					this.props.location.state &&
					this.props.location.state.referrer &&
					<h3 style={{textAlign:"center"}}><Link to={this.props.location.state.referrer}>Go back.</Link></h3>
				}
				{
					this.props.location.state &&
					this.props.location.state.linkToItem &&
					<h3 style={{textAlign:"center"}}><Link to={this.props.location.state.linkToItem}>View item.</Link></h3>
				}
			</React.Fragment>
		)
	}

}

export default ErrorC;