import React from 'react';
import classNames from 'classnames';
import { prefix } from "../types";
import { getText } from "../../../locales";
import "./index.less";

// 日志级别映射
var LOG_LEVEL_MAP = {
  0: 'debug',
  // 调试信息
  1: 'info',
  // 重要操作信息
  2: 'error' // 错误信息
};

// 日志级别颜色配置
var LOG_LEVEL_COLORS = {
  debug: '#666',
  info: '#1890ff',
  error: '#ff4d4f'
};

// 设备类型映射
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 LogCard = function LogCard(props) {
  var data = props.data;
  var logLevel = LOG_LEVEL_MAP[data.log_level];
  var logLevelColor = LOG_LEVEL_COLORS[logLevel];
  var deviceTypeName = DEVICE_TYPE_MAP[data.device.device_type] || data.device.device_type;

  // 格式化时间显示
  var formatTime = function formatTime(timeStr) {
    try {
      var date = new Date(timeStr);
      return date.toLocaleString('zh-CN', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
        hour: '2-digit',
        minute: '2-digit',
        second: '2-digit',
        fractionalSecondDigits: 3
      });
    } catch (_unused) {
      return timeStr;
    }
  };

  // 格式化日志级别显示
  var formatLogLevel = function formatLogLevel(level) {
    var levelMap = {
      0: 'DEBUG',
      1: 'INFO',
      2: 'ERROR'
    };
    return levelMap[level];
  };

  // 解析并格式化数据
  var formatData = function formatData(dataStr) {
    if (!dataStr) return null;
    try {
      var parsed = JSON.parse(dataStr);
      return JSON.stringify(parsed, null, 2);
    } catch (_unused2) {
      return dataStr;
    }
  };
  return /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(prefix, "-log-card"), logLevel),
    style: {
      borderLeftColor: logLevelColor
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-log-card-header")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-log-card-time")
  }, formatTime(data.time)), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-log-card-level"),
    style: {
      color: logLevelColor
    }
  }, formatLogLevel(data.log_level)), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-log-card-device-id")
  }, data.device.device_idfa)), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-log-card-content")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-log-card-service")
  }, "[", deviceTypeName, "] ", data.message), data.data && /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-log-card-data")
  }, /*#__PURE__*/React.createElement("pre", null, formatData(data.data)))));
};
export default LogCard;