import { jsx as e, jsxs as t } from "react/jsx-runtime";
import { useState as D, useEffect as X } from "react";
import J from "@kenjiuno/msgreader";
import { User as O, Users as E, Calendar as W, Clock as q, Tag as U, Mail as Q, Paperclip as V, Hash as Y } from "lucide-react";
import { u as Z } from "./index-Bk6WqXgW.mjs";
function P(l, d) {
  return l ? l.filter((o) => o.recipType === d).map((o) => {
    const p = o.name || "", y = o.smtpAddress || o.email || "";
    return p && y && p !== y ? `${p} <${y}>` : p || y;
  }).filter(Boolean).join("; ") : "";
}
function S(l) {
  if (!l) return "";
  try {
    const d = new Date(l);
    return isNaN(d.getTime()) ? l : d.toLocaleString();
  } catch {
    return l;
  }
}
function ee(l, d) {
  if (l.bodyHtml)
    return l.bodyHtml;
  if (l.html)
    try {
      return new TextDecoder("utf-8").decode(l.html);
    } catch {
    }
  return l.body ? `<pre style="white-space: pre-wrap; word-wrap: break-word; font-family: system-ui, sans-serif;">${l.body.replace(/&/g, "&amp;").replace(/\x3c/g, "&lt;").replace(/>/g, "&gt;")}</pre>` : `<p style="color: #999;">${d}</p>`;
}
function te(l) {
  return l ? {
    "IPM.Note": "Email",
    "IPM.Note.SMIME": "Encrypted Email",
    "IPM.Note.SMIME.MultipartSigned": "Signed Email",
    "IPM.Appointment": "Appointment",
    "IPM.Schedule.Meeting.Request": "Meeting Request",
    "IPM.Schedule.Meeting.Canceled": "Meeting Cancellation",
    "IPM.Contact": "Contact",
    "IPM.Task": "Task",
    "IPM.StickyNote": "Sticky Note"
  }[l] || l : "";
}
const n = {
  flexShrink: 0,
  color: "#6b7280",
  fontWeight: 500,
  marginRight: "8px",
  whiteSpace: "nowrap"
}, i = {
  display: "flex",
  alignItems: "flex-start",
  gap: "8px",
  padding: "6px 0"
}, r = {
  flexShrink: 0,
  display: "flex",
  alignItems: "center",
  height: "1.4em"
}, a = {
  flexShrink: 0,
  color: "#9ca3af"
}, c = {
  color: "#111827",
  wordBreak: "break-word",
  flex: 1
}, ce = ({ url: l }) => {
  const d = Z(), [o, p] = D(!0), [y, H] = D(null), [s, B] = D(null);
  if (X(() => {
    (async () => {
      p(!0), H(null), B(null);
      try {
        const m = await fetch(l);
        if (!m.ok)
          throw new Error("文件加载失败");
        const k = await m.arrayBuffer(), M = new J(k).getFileData();
        B(M);
      } catch (m) {
        console.error("MSG 解析错误:", m), H(d("msg.parse_failed"));
      } finally {
        p(!1);
      }
    })();
  }, [l]), o)
    return /* @__PURE__ */ e("div", { className: "rfp-flex rfp-items-center rfp-justify-center rfp-w-full rfp-h-full", children: /* @__PURE__ */ e("div", { className: "rfp-w-12 rfp-h-12 rfp-border-4 rfp-border-line-strong rfp-border-t-spinner-head rfp-rounded-full rfp-animate-spin" }) });
  if (y || !s)
    return /* @__PURE__ */ e("div", { className: "rfp-flex rfp-items-center rfp-justify-center rfp-w-full rfp-h-full", children: /* @__PURE__ */ e("div", { className: "rfp-text-fg-secondary rfp-text-center", children: /* @__PURE__ */ e("p", { className: "rfp-text-lg", children: y || d("msg.parse_failed_short") }) }) });
  const R = P(s.recipients, "to"), C = P(s.recipients, "cc"), L = P(s.recipients, "bcc"), u = s.senderName || "", v = s.senderSmtpAddress || s.senderEmail || "", $ = u && v && u !== v ? `${u} <${v}>` : u || v, x = S(s.clientSubmitTime), g = S(s.messageDeliveryTime), j = S(s.creationTime), b = S(s.lastModificationTime), G = s.subject || "（无主题）", z = (s.attachments || []).filter((h) => !h.attachmentHidden), K = ee(s, d("msg.empty_body")), T = te(s.messageClass), F = s.messageId || "", w = s, I = typeof w.importance == "number" ? w.importance : void 0, A = I === 2 ? "High" : I === 0 ? "Low" : "", N = typeof w.sensitivity == "number" ? w.sensitivity : void 0, _ = N !== void 0 && N !== 0 && {
    0: "Normal",
    1: "Personal",
    2: "Private",
    3: "Confidential"
  }[N] || "";
  return /* @__PURE__ */ e(
    "div",
    {
      className: "rfp-w-full rfp-h-full rfp-overflow-auto",
      style: { background: "white" },
      children: /* @__PURE__ */ t(
        "div",
        {
          style: {
            width: "100%",
            background: "white",
            minHeight: "100%"
          },
          children: [
            /* @__PURE__ */ t("div", { style: { borderBottom: "1px solid #e5e7eb", padding: "clamp(12px, 3vw, 24px) clamp(16px, 3vw, 28px)", background: "#f9fafb" }, children: [
              /* @__PURE__ */ e("h2", { style: { margin: "0 0 16px 0", fontSize: "clamp(16px, 2.5vw, 20px)", fontWeight: 600, color: "#111827", lineHeight: 1.4 }, children: G }),
              /* @__PURE__ */ t("div", { style: { display: "flex", flexDirection: "column", fontSize: "clamp(12px, 1.8vw, 14px)", color: "#4b5563" }, children: [
                $ && /* @__PURE__ */ t("div", { style: i, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(O, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "From" }),
                    /* @__PURE__ */ e("span", { style: c, children: $ })
                  ] })
                ] }),
                R && /* @__PURE__ */ t("div", { style: i, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(E, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "To" }),
                    /* @__PURE__ */ e("span", { style: c, children: R })
                  ] })
                ] }),
                C && /* @__PURE__ */ t("div", { style: i, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(E, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "Cc" }),
                    /* @__PURE__ */ e("span", { style: c, children: C })
                  ] })
                ] }),
                L && /* @__PURE__ */ t("div", { style: i, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(E, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "Bcc" }),
                    /* @__PURE__ */ e("span", { style: c, children: L })
                  ] })
                ] }),
                x && /* @__PURE__ */ t("div", { style: i, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(W, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "Sent" }),
                    /* @__PURE__ */ e("span", { style: c, children: x })
                  ] })
                ] }),
                g && g !== x && /* @__PURE__ */ t("div", { style: i, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(q, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "Received" }),
                    /* @__PURE__ */ e("span", { style: c, children: g })
                  ] })
                ] }),
                !x && !g && j && /* @__PURE__ */ t("div", { style: i, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(W, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "Date" }),
                    /* @__PURE__ */ e("span", { style: c, children: j })
                  ] })
                ] }),
                A && /* @__PURE__ */ t("div", { style: i, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(U, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "Importance" }),
                    /* @__PURE__ */ e("span", { style: {
                      ...c,
                      color: I === 2 ? "#dc2626" : "#2563eb",
                      fontWeight: 500
                    }, children: A })
                  ] })
                ] }),
                _ && /* @__PURE__ */ t("div", { style: i, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(U, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "Sensitivity" }),
                    /* @__PURE__ */ e("span", { style: c, children: _ })
                  ] })
                ] }),
                T && T !== "Email" && /* @__PURE__ */ t("div", { style: i, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(Q, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "Type" }),
                    /* @__PURE__ */ e("span", { style: c, children: T })
                  ] })
                ] }),
                z.length > 0 && /* @__PURE__ */ t("div", { style: { ...i, borderTop: "1px solid #e5e7eb", marginTop: "4px", paddingTop: "10px" }, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(V, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "Attachments" }),
                    /* @__PURE__ */ e("div", { style: { ...c, display: "flex", flexWrap: "wrap", gap: "6px" }, children: z.map((h, m) => {
                      const k = h.fileName || h.name || "未知文件", f = h.contentLength, M = f ? f > 1048576 ? `${(f / 1048576).toFixed(1)} MB` : f > 1024 ? `${(f / 1024).toFixed(0)} KB` : `${f} B` : "";
                      return /* @__PURE__ */ t(
                        "span",
                        {
                          style: {
                            display: "inline-flex",
                            alignItems: "center",
                            gap: "4px",
                            padding: "2px 8px",
                            background: "#f3f4f6",
                            borderRadius: "4px",
                            fontSize: "13px",
                            color: "#374151",
                            border: "1px solid #e5e7eb"
                          },
                          children: [
                            k,
                            M && /* @__PURE__ */ t("span", { style: { color: "#9ca3af", fontSize: "12px" }, children: [
                              "(",
                              M,
                              ")"
                            ] })
                          ]
                        },
                        m
                      );
                    }) })
                  ] })
                ] }),
                F && /* @__PURE__ */ t("div", { style: { ...i, borderTop: z.length > 0 ? "none" : "1px solid #e5e7eb", marginTop: "4px", paddingTop: "10px" }, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(Y, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "Message-ID" }),
                    /* @__PURE__ */ e("span", { style: { ...c, fontSize: "12px", color: "#9ca3af", fontFamily: "monospace" }, children: F })
                  ] })
                ] }),
                b && b !== x && b !== g && /* @__PURE__ */ t("div", { style: i, children: [
                  /* @__PURE__ */ e("span", { style: r, children: /* @__PURE__ */ e(q, { size: 16, style: a }) }),
                  /* @__PURE__ */ t("div", { style: { display: "flex", flex: 1 }, children: [
                    /* @__PURE__ */ e("span", { style: n, children: "Modified" }),
                    /* @__PURE__ */ e("span", { style: { ...c, fontSize: "12px", color: "#9ca3af" }, children: b })
                  ] })
                ] })
              ] })
            ] }),
            /* @__PURE__ */ e(
              "div",
              {
                style: {
                  padding: "clamp(12px, 3vw, 24px) clamp(16px, 3vw, 28px)",
                  fontFamily: "system-ui, -apple-system, sans-serif",
                  lineHeight: "1.6",
                  color: "#333",
                  overflowX: "auto"
                },
                dangerouslySetInnerHTML: { __html: K }
              }
            )
          ]
        }
      )
    }
  );
};
export {
  ce as MsgRenderer
};
//# sourceMappingURL=index-BqOX6zlZ.mjs.map
