import React from 'react';
import classNames from 'classnames';
import { CloseCircleOutlined } from '@ant-design/icons';
import Iconfont from "../../iconfont";
import { prefix, ErrorTypeTheme, errorTypes } from "../types";
import { getText } from "../../../locales";
import "./index.less";

// 错误级别映射
var ERROR_LEVEL_MAP = {
  0: 'fatal',
  // 致命错误
  1: 'critical',
  // 严重错误
  2: 'normal',
  // 一般错误
  3: 'info' // 提示信息
};

// 设备类型映射
var DEVICE_TYPE_MAP = {
  printer: getText('pisell2.text.hardware-error.device.printer'),
  barcode_scanner: getText('pisell2.text.hardware-error.device.barcode-scanner'),
  cds: getText('pisell2.text.hardware-error.device.cds'),
  kds: getText('pisell2.text.hardware-error.device.kds'),
  display: getText('pisell2.text.hardware-error.device.display'),
  card_reader: getText('pisell2.text.hardware-error.device.card-reader'),
  till: getText('pisell2.text.hardware-error.device.till'),
  scale: getText('pisell2.text.hardware-error.device.scale')
};

// 设备图标映射
var DEVICE_ICON_MAP = {
  printer: 'pisell2-printer',
  barcode_scanner: 'pisell2-a-Scanner1',
  cds: 'pisell2-a-device1',
  kds: 'pisell2-a-device1',
  display: 'pisell2-monitor-03',
  card_reader: 'pisell2-a-NFC2',
  till: 'pisell2-coins-hand',
  scale: 'pisell2-scales-02'
};
var ErrorCard = function ErrorCard(props) {
  var data = props.data,
    onClose = props.onClose;
  var errorType = ERROR_LEVEL_MAP[data.error_level];
  var errorConfig = errorTypes.find(function (type) {
    return type.type === errorType;
  });
  var theme = ErrorTypeTheme[errorType];
  var deviceTypeName = DEVICE_TYPE_MAP[data.device.device_type] || data.device.device_type;
  var deviceIcon = DEVICE_ICON_MAP[data.device.device_type] || 'pisell2-container';
  if (!errorConfig) {
    return null;
  }
  var IconComponent = errorConfig.icon;
  return /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(prefix, "-error-card"), errorType),
    style: {
      backgroundColor: theme.backgroundColor,
      borderLeft: "4px solid ".concat(theme.iconColor)
    }
  }, onClose && !['fatal', 'critical'].includes(errorType) && /*#__PURE__*/React.createElement(CloseCircleOutlined, {
    className: "".concat(prefix, "-error-card-close"),
    onClick: onClose
  }), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-error-card-header")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-error-card-level")
  }, /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "-error-card-level-text"),
    style: {
      color: theme.iconColor,
      backgroundColor: theme.badgeColor
    }
  }, errorConfig.title()), /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "-error-card-device")
  }, /*#__PURE__*/React.createElement(Iconfont, {
    type: deviceIcon,
    style: {
      marginRight: 8,
      fontSize: 16
    }
  }), deviceTypeName))), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-error-card-content")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-error-card-info-row")
  }, /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "-error-card-label")
  }, getText('pisell2.text.hardware-error.error-code'), ":"), /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "-error-card-value")
  }, data.error_code), /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "-error-card-label")
  }, getText('pisell2.text.hardware-error.time'), ":"), /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "-error-card-value")
  }, data.time)), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-error-card-description")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-error-card-label")
  }, getText('pisell2.text.hardware-error.error-description'), ":"), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-error-card-message")
  }, data.error_message)), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-error-card-solution")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-error-card-label")
  }, getText('pisell2.text.hardware-error.solution'), ":"), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-error-card-solution-text")
  }, "\u8BF7\u68C0\u67E5", deviceTypeName, "\u7535\u6E90\u548C\u8FDE\u63A5\u7EBF"))));
};
export default ErrorCard;