import React from 'react';
import styles from './index.less';
import commonStyles from '../common.less';
import classNames from 'classnames';
import { useHistory } from 'react-router-dom';


//'平台公告','{"noticeTitle":"光谷智慧园停水","noticeType":"停水公告","noticeContent":"从今天中午20点开始停水，停三个小时！","time":"2020-11-03 09:11:12"
export class NoticeContent {
  constructor({
    noticeTitle,
    noticeType,
    noticeContent,
    time
  } = content) {
    this.noticeTitle = noticeTitle;
    this.noticeType = noticeType;
    this.noticeContent = noticeContent;
    this.time = time;
  }
}

const Notice = ({ message, confirmRead }) => {
  let noticeContent = message.infoContent;
  const history = useHistory();
  const goPath = (item) => {
    confirmRead(false,[message.id]);
    let path= item.webPath ? `/civweb4/${item.webPath}` : `/civweb4/product/notification/HistoryNotice/HistoryNotice`
    history.push(path);
  }
  return (
    <div  className={classNames(styles.notice,commonStyles.messageContainer)} title="点击查看详情" onClick={()=> goPath(message)}>
      <div className={commonStyles.title}>
        <span>公告</span>
        <img
          className={commonStyles.confirm}
          title="点击标为已读"
          onClick={() => {
             confirmRead(false,[message.id]);
          }}
          src="https://panda-water.cn/Web4/assets/images/message/%E5%8B%BE%E6%B5%85.png"
        />
      </div>
      <div className={commonStyles.content}>
        <p>
          <i>{noticeContent.noticeType}</i>
          {noticeContent.noticeTitle}
        </p>
        <p>{noticeContent.noticeContent}</p>
        <p className={commonStyles.messageTime}>{message.time}</p>
      </div>
    </div>
  );
};

export default Notice;
