import React from 'react';

import classNames from 'classnames';

import commonStyles from '../common.less';
import styles from './index.less';

// "caseType":"待办工单","flowName":"维修处理流程","nodeName":"审核关单","content":"请迅速到现场处理","time":"2020-11-03 09:11:12"
export class CaseContent {
  // eslint-disable-next-line no-use-before-define
  constructor({ caseType, flowName, nodeName, content, time } = content) {
    this.caseType = caseType;
    this.flowName = flowName;
    this.nodeName = nodeName;
    this.content = content;
    this.time = time;
  }
}

const Case = ({ message, confirmRead }) => {
  const caseContent = message.infoContent;
  const goPath = item => {
    confirmRead(false, [message.id]);
    const messageType = item.messType;
    let label = '';
    let widgetID = '';
    switch (messageType) {
      case '任务派发':
        label = '任务派发';
        widgetID = 'widget_city_综合运营_二供管理_维修管理_工单办理';
        break;
      case '任务驳回':
        label = '任务驳回';
        widgetID = 'widget_city_综合运营_二供管理_维修管理_工单办理';
        // eslint-disable-next-line no-underscore-dangle,no-case-declarations
        let _tab;
        // eslint-disable-next-line prefer-const
        _tab = '任务驳回';
        break;
      default:
        label = '工单办理';
        widgetID = 'widget_city_综合运营_二供管理_维修管理_工单办理';
        break;
    }
    const webPath =
      item.webPath ||
      'product/maintenance/CaseManage/CaseDoingBox/StardCaseDoingBoxView|isDelay=1';
    window.share.event.emit('listenerMointer', {
      widgetId: widgetID,
      label,
      url: webPath,
    });
  };
  return (
    <div
      className={classNames(styles.case, commonStyles.messageContainer)}
      title="点击查看详情"
      onClick={() => goPath(message)}
    >
      <div className={commonStyles.title}>
        <span>消息</span>
        {/* eslint-disable-next-line jsx-a11y/alt-text */}
        <img
          className={commonStyles.confirm}
          title="点击标为已读"
          onClick={e => {
            e.stopPropagation();
            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>{caseContent.caseType}</i>
          {caseContent.flowName}
        </p>
        <p>
          {caseContent.nodeName} : {caseContent.content}
        </p>
        <p className={commonStyles.messageTime}>{message.time}</p>
      </div>
    </div>
  );
};

export default Case;
