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 { Currency } from "../data/entities.js";
async function resolveEm() {
  const { resolve } = await createRequestContainer();
  return resolve("em");
}
async function loadCurrencyPreview(entityId, ctx) {
  const { t } = await resolveTranslations();
  const defaultTitle = t("currencies.messageObjects.currency.title");
  if (!ctx.organizationId) {
    return { title: defaultTitle, subtitle: entityId };
  }
  const em = await resolveEm();
  const entity = await findOneWithDecryption(
    em,
    Currency,
    {
      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"
    };
  }
  const subtitleParts = [entity.code, entity.symbol].filter((part) => Boolean(part && part.trim().length > 0));
  const metadata = {};
  const codeLabel = t("currencies.form.field.code");
  const symbolLabel = t("currencies.form.field.symbol");
  if (entity.code) metadata[codeLabel] = entity.code;
  if (entity.symbol) metadata[symbolLabel] = entity.symbol;
  return {
    title: entity.name,
    subtitle: subtitleParts.join(" \xB7 ") || entityId,
    metadata: Object.keys(metadata).length > 0 ? metadata : void 0
  };
}
export {
  loadCurrencyPreview
};
//# sourceMappingURL=messageObjectPreviews.js.map
