{"size": 1110, "ext": "js", "max_stars_repo_path": "src/apps/team/admin/components/last_online_token.js", "max_stars_repo_name": "ccetc/mahaplatform.com", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/apps/team/admin/components/last_online_token.js", "max_issues_repo_name": "ccetc/mahaplatform.com", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/apps/team/admin/components/last_online_token.js", "max_forks_repo_name": "ccetc/mahaplatform.com", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.0, "max_line_length": 100, "alphanum_fraction": 0.6540540541}
import PropTypes from 'prop-types'
import moment from 'moment'
import React from 'react'

const LastOnlineToken = ({ last_online_at }) => {

  const status = _getStatus(last_online_at)

  return (
    <div className="maha-list-item-content">
      <div className="maha-list-item-content-label">Last Online</div>
      <div className="maha-list-item-content-value">
        <span>
          <i className={`fa fa-fw fa-circle ${status.icon}`}/>
          { status.text }
        </span>
      </div>
    </div>
  )

}

LastOnlineToken.propTypes = {
  last_online_at: PropTypes.object
}

const _getStatus = (last_online_at) => {
  const diff = moment().diff(moment(last_online_at), 'minutes')
  if(!last_online_at) return { icon: 'absent', text: 't(NEVER)' }
  if(diff > 15) return { icon: 'absent', text: moment(last_online_at).format('MM/DD/YY @ hh:mm A') }
  if(diff > 10) return { icon: 'abandoned', text: moment(last_online_at).fromNow() }
  if(diff > 5) return { icon: 'waiting', text: moment(last_online_at).fromNow() }
  return { icon: 'present', text: 't(ONLINE NOW)' }
}

export default LastOnlineToken
