import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
import { findOneWithDecryption } from "@open-mercato/shared/lib/encryption/find";
import { InboxEmail } from "../data/entities.js";
async function resolveEm() {
  const { resolve } = await createRequestContainer();
  return resolve("em");
}
async function loadInboxEmailPreview(entityId, ctx) {
  if (!ctx.organizationId) {
    return { title: "Inbox Email", subtitle: entityId };
  }
  try {
    const em = await resolveEm();
    const email = await findOneWithDecryption(
      em,
      InboxEmail,
      {
        id: entityId,
        tenantId: ctx.tenantId,
        organizationId: ctx.organizationId,
        deletedAt: null
      },
      void 0,
      { tenantId: ctx.tenantId, organizationId: ctx.organizationId }
    );
    if (!email) {
      return { title: "Inbox Email", subtitle: entityId, status: "Not found", statusColor: "gray" };
    }
    const statusColorMap = {
      received: "blue",
      processing: "amber",
      processed: "green",
      needs_review: "amber",
      failed: "red"
    };
    return {
      title: email.subject || "Inbox Email",
      subtitle: email.forwardedByName || email.forwardedByAddress || void 0,
      status: email.status,
      statusColor: statusColorMap[email.status] || "gray",
      metadata: {
        ...email.forwardedByAddress ? { from: email.forwardedByAddress } : {}
      }
    };
  } catch {
    return { title: "Inbox Email", subtitle: entityId };
  }
}
export {
  loadInboxEmailPreview
};
//# sourceMappingURL=messageObjectPreviews.js.map
