import { getText } from "../../../locales/index.js";
import { prefix } from "../types.js";
import React from "react";
import classNames from "classnames";
import "./index.less";
//#region src/components/hardwareErrorTip/logCard/index.tsx
const LOG_LEVEL_MAP = {
	0: "debug",
	1: "info",
	2: "error"
};
const LOG_LEVEL_COLORS = {
	debug: "#666",
	info: "#1890ff",
	error: "#ff4d4f"
};
const 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")
};
const LogCard = (props) => {
	const { data } = props;
	const logLevel = LOG_LEVEL_MAP[data.log_level];
	const logLevelColor = LOG_LEVEL_COLORS[logLevel];
	const deviceTypeName = DEVICE_TYPE_MAP[data.device.device_type] || data.device.device_type;
	const formatTime = (timeStr) => {
		try {
			return new Date(timeStr).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;
		}
	};
	const formatLogLevel = (level) => {
		return {
			0: "DEBUG",
			1: "INFO",
			2: "ERROR"
		}[level];
	};
	const formatData = (dataStr) => {
		if (!dataStr) return null;
		try {
			const parsed = JSON.parse(dataStr);
			return JSON.stringify(parsed, null, 2);
		} catch (_unused2) {
			return dataStr;
		}
	};
	return /* @__PURE__ */ React.createElement("div", {
		className: classNames(`${prefix}-log-card`, logLevel),
		style: { borderLeftColor: logLevelColor }
	}, /* @__PURE__ */ React.createElement("div", { className: `${prefix}-log-card-header` }, /* @__PURE__ */ React.createElement("div", { className: `${prefix}-log-card-time` }, formatTime(data.time)), /* @__PURE__ */ React.createElement("div", {
		className: `${prefix}-log-card-level`,
		style: { color: logLevelColor }
	}, formatLogLevel(data.log_level)), /* @__PURE__ */ React.createElement("div", { className: `${prefix}-log-card-device-id` }, data.device.device_idfa)), /* @__PURE__ */ React.createElement("div", { className: `${prefix}-log-card-content` }, /* @__PURE__ */ React.createElement("div", { className: `${prefix}-log-card-service` }, "[", deviceTypeName, "] ", data.message), data.data && /* @__PURE__ */ React.createElement("div", { className: `pisell-lowcode-log-card-data` }, /* @__PURE__ */ React.createElement("pre", null, formatData(data.data)))));
};
//#endregion
export { LogCard as default };
