import React, { PureComponent } from 'react';
import { Popconfirm } from 'antd';
import './comment.css';
import RenderHtml from "../../components/render-html";

class CommentsItem extends PureComponent{

  cancelEvent=()=>{}
  
  render(){
    const { username , time , content , id , admin , deleteReplyEvent } = this.props

    // 当前用户是否是管理员或者版主，true为有权限删除评论
    const adminDelete = (
      admin && 
      <Popconfirm 
        title="确定删除这条评论？"
        onConfirm={()=>deleteReplyEvent(id)}
        onCancel={this.cancelEvent}
        okText="确定"
        cancelText="取消"
      >
        <a className="fr c_point color-grey-9">删除</a>
      </Popconfirm>
    )
    return(
      <React.Fragment>
        <p className="mt3 mb10 clearfix">
          <span className="color-grey3 font-16 mr20">{username}</span>
          <span className="color-grey9">{time}</span>

          { adminDelete }
        </p>
        <RenderHtml className="forumsDetailHtml" value={content} />
      </React.Fragment>
    )
  }
}

export default CommentsItem;