import React from 'react';
import { Link } from 'react-router-dom';
import { truncateCommitId } from '../common/util';

const typeIco = {
  "submodule":"icon-file-submodule font-17",
  "file":'icon-wenjian6 font-15 color-blue-file',
  "dir":"icon-wenjianjia4 font-15 color-blue_4C"
}

function CoderDepotCatalogue({item , goToSubRoot , owner , projectsId , platform }){
  // 只显示第一个换行符前的内容
  function getMessage(value){
    let str = value.indexOf('\n') > 0 && value.split('\n');
    return str[0];
  }
  return(
    <li>
      <span>
        {
          (!platform && item.image_type) ? 
          <span><i className={`iconfont ${typeIco[`${item.type}`]} mr8`}></i>{item.name}</span>
          :
          <a onClick={()=>goToSubRoot(item.path,item.type,item.name)} className={item.type === "submodule" && "submoduleStyle"}>
            <i className={`iconfont ${typeIco[`${item.type}`]} mr8`}></i>{item.name}
          </a>
        }
      </span>
      <span title="init project">
        <Link to={`/${owner}/${projectsId}/commits/${truncateCommitId(`${item.commit && item.commit.sha}`)}`} title={item.commit && item.commit.message}>
          {getMessage(item.commit && item.commit.message)}
        </Link>
      </span>
      <span title={item.commit && item.commit.created_at}>{item.commit && item.commit.time_from_now}</span>
    </li>
  )
}
export default CoderDepotCatalogue;