import React, { PureComponent } from 'react';

function bytesToSize(bytes) {
  if (bytes === 0) return '0 B';
  let k = 1024,
  sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
  i = Math.floor(Math.log(bytes) / Math.log(k));
  return (bytes / Math.pow(k, i)). toFixed(2) + ' ' + sizes[i];
}
class FileList extends PureComponent{

  render(){
    let { list , className } = this.props;

    const listMap = list && list.map((item)=>{
      return(
        <li>
          <i className="iconfont icon-fujian color-blue font-16 mr8"></i>
          <a href={item.url} className="color-blue" target="_self">{item.filename}</a>
          <span className="color-grey-9 ml10">（{bytesToSize(`${item.filesize}`)}）</span>
        </li>
      )
    })
    return(
      <ul className={className}>
        { listMap }
      </ul>
    )
  }
}

export default FileList;