import React from 'react';
import {NavLink} from 'fluxible-router';
import revertRevision from '../../../../actions/history/revertRevision';
import ActivityFeedUtil from '../util/ActivityFeedUtil';


class ContentHistoryItem extends React.Component {

    handleRevertClick() {
        this.context.executeAction(revertRevision, {
            selector: this.props.selector, revisionId: this.props.revision.id
        });
    }

    render() {
        // console.log('ContentHistoryItem render()', this.props.permissions);
        const revision = this.props.revision;
        const revertIcon = (this.props.userid !== '' && this.props.permissions.edit && !this.props.permissions.readOnly) ? (
        <a className="like" onClick={this.handleRevertClick.bind(this)}>
            <i className="undo icon"/>
        </a>
        ) : '';
        let revisionLink = <NavLink
        href={ActivityFeedUtil.makeNodeRevisionURL(this.props.selector, revision.id)}>Revision {revision.id} </NavLink>;
        return (
        <div className="item">
            <div className="content">
                <div className="header">
                    {revisionLink}
                    {revision.active ? <i className='check circle icon green'></i> : revertIcon}
                </div>
                <div className="description">
                    <span>{'by '}</span>
                    <a className="user" href={'/user/' + revision.user}>
                        {revision.username}
                    </a>
                    <span>{' ' + ActivityFeedUtil.formatDate(revision.timestamp)}</span>
                </div>
            </div>
        </div>
        );
    }
}

ContentHistoryItem.contextTypes = {
    executeAction: React.PropTypes.func.isRequired
};

export default ContentHistoryItem;

@@ -191,16 +191,44 @@
 dUtil';%0A
+import moment from 'moment';
 %0A%0Aclass 
@@ -859,165 +859,8 @@
 '';%0A
-        let revisionLink = %3CNavLink%0A        href=%7BActivityFeedUtil.makeNodeRevisionURL(this.props.selector, revision.id)%7D%3ERevision %7Brevision.id%7D %3C/NavLink%3E;%0A
     
@@ -872,16 +872,16 @@
 eturn (%0A
+
         
@@ -1006,22 +1006,84 @@
     
-%7BrevisionLink%7D
+%3Cspan%3E%7Bmoment(revision.lastUpdate).calendar(null, %7BsameElse: 'lll'%7D)%7D%3C/span%3E
 %0A   

Format revision date using moment.js