import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
import { findOneWithDecryption } from "@open-mercato/shared/lib/encryption/find";
import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
import { ResourcesResource } from "../data/entities.js";
async function resolveEm() {
  const { resolve } = await createRequestContainer();
  return resolve("em");
}
async function loadResourcePreview(entityId, ctx) {
  const { t } = await resolveTranslations();
  const defaultTitle = t("resources.messageObjects.resource.title");
  if (!ctx.organizationId) {
    return { title: defaultTitle, subtitle: entityId };
  }
  const em = await resolveEm();
  const entity = await findOneWithDecryption(
    em,
    ResourcesResource,
    {
      id: entityId,
      tenantId: ctx.tenantId,
      organizationId: ctx.organizationId,
      deletedAt: null
    },
    void 0,
    { tenantId: ctx.tenantId, organizationId: ctx.organizationId }
  );
  if (!entity) {
    return {
      title: defaultTitle,
      subtitle: entityId,
      status: t("customers.messageObjects.notFound"),
      statusColor: "gray"
    };
  }
  return {
    title: entity.name
  };
}
export {
  loadResourcePreview
};
//# sourceMappingURL=messageObjectPreviews.js.map
