import React from 'react';
import { Link } from 'react-router-dom';
import { AlignCenter } from '../../Component/layout';
import { TagInfo } from '../../Utils/TagColor';
import { getImageUrl } from 'educoder';

function Activity({list}) {
  function typeForUrl(trend_type,project,id){
    const { owner , identifier } = project;
    switch(trend_type){
      case 'Issue':
        return `/${owner && owner.login}/${identifier}/issues/${id}`;
      case 'VersionRelease':
        return `/${owner && owner.login}/${identifier}/releases`;
      case 'PullRequest':
        return `/${owner && owner.login}/${identifier}/pulls/${id}`;
      default :
        return '';
    }
  }
  return(
    <ul className="infosActivity">
      {
        list.map((i,k)=>{
          return(
            <li>
              <Link to={`/${i.user_login}`}><img src={getImageUrl(`/${i.user_avatar}`)} alt="" className="aImg"/></Link>
              <div className="aInfos">
                <AlignCenter>
                  <Link to={`/${i.user_login}`} className="name">{i.user_name}</Link>
                  <span className="time">{i.action_time}</span>
                  {i.priority && TagInfo(`${i.priority}`,"")}
                  {i.issue_status && <span className="status">{i.issue_status}</span> }
                </AlignCenter>
                <p className="aDesc"><Link to={typeForUrl(i.trend_type,i.project,i.trend_id)}>{i.action_type}：{i.name}</Link></p>
              </div>
            </li>
          )
        })
      }
    </ul>
  )
}
export default Activity;