function appendLine(lines, label, value) {
  if (value === null || value === void 0) return;
  const text = Array.isArray(value) ? value.map((item) => item === null || item === void 0 ? "" : String(item)).filter(Boolean).join(", ") : typeof value === "object" ? JSON.stringify(value) : String(value);
  if (!text.trim()) return;
  lines.push(`${label}: ${text}`);
}
function pickString(...candidates) {
  for (const candidate of candidates) {
    if (typeof candidate !== "string") continue;
    const trimmed = candidate.trim();
    if (trimmed.length > 0) return trimmed;
  }
  return null;
}
function snippet(value, max = 140) {
  if (typeof value !== "string") return void 0;
  const trimmed = value.trim();
  if (!trimmed.length) return void 0;
  if (trimmed.length <= max) return trimmed;
  return `${trimmed.slice(0, max - 3)}...`;
}
function buildMessagePresenter(record) {
  const title = pickString(record.subject) ?? "Message";
  const body = snippet(record.body);
  const externalName = pickString(record.external_name, record.externalName);
  const subtitle = [externalName, body].filter(Boolean).join(" \xB7 ") || void 0;
  return {
    title: String(title),
    subtitle,
    icon: "mail",
    badge: "Message"
  };
}
const searchConfig = {
  entities: [
    {
      entityId: "messages:message",
      enabled: true,
      priority: 5,
      buildSource: async (ctx) => {
        const record = ctx.record;
        const lines = [];
        appendLine(lines, "Subject", record.subject);
        appendLine(lines, "Body", record.body);
        appendLine(lines, "From name", record.external_name ?? record.externalName);
        if (!lines.length) return null;
        return {
          text: lines,
          presenter: buildMessagePresenter(record),
          checksumSource: {
            record: {
              subject: record.subject,
              body: record.body,
              external_name: record.external_name ?? record.externalName,
              external_email_hash: record.external_email_hash ?? record.externalEmailHash
            }
          }
        };
      },
      formatResult: async (ctx) => buildMessagePresenter(ctx.record),
      resolveUrl: async (ctx) => {
        const id = pickString(ctx.record.id);
        return id ? `/backend/messages/${encodeURIComponent(id)}` : null;
      },
      fieldPolicy: {
        searchable: ["subject", "body", "external_name"],
        hashOnly: ["external_email"],
        excluded: ["action_data", "action_result"]
      }
    }
  ]
};
var search_default = searchConfig;
const config = searchConfig;
export {
  config,
  search_default as default,
  searchConfig
};
//# sourceMappingURL=search.js.map
