/** * Template Conditions — TypeScript port of the WordPress * `Nitrogen\TemplateConditions` scoring engine * (nitrogen-connector/includes/template-conditions.php). * * Resolves the best-matching nitrogen-template for a document by scoring * editor-authored condition groups (OR'd groups, AND'd conditions within a * group) and falling back to a legacy associatedCollection match. * * Everything here is pure/typed and defensive: the evaluators never throw — * malformed input simply yields a non-match (false). */ import type { Payload } from 'payload'; import type { JsonObject, NitrogenPageDoc, NitrogenTemplateDoc, NitrogenSettingsGlobal } from '../types.js'; import { type TemplateRef } from './helpers.js'; /** * Evaluation context for a single document. * * `dynamic` holds the buildDynamicData() namespace; `post` is the raw document. * The dynamic_data evaluator resolves its dot-path against both (dynamic first, * then post) so editor-authored paths match leniently. */ export interface TemplateContext { post: NitrogenPageDoc | NitrogenTemplateDoc | Record; postType: string; postId: string; dynamic: JsonObject; } /** * Evaluate authored conditions against a context (php:45-100). * * Groups are OR'd; conditions within a group are AND'd. An `exclude` flag * inverts a condition's result. An unknown condition type fails the whole group. * * Returns the matched-condition count (score) of the first matching group, or * false. If there are no conditionGroups, returns false (the caller handles the * legacy fallback). */ export declare function evaluateConditions(templateConditions: unknown, context: TemplateContext): number | false; /** * Build the evaluation context for a document (php:187-216, Payload-adapted). */ export declare function buildTemplateContext(doc: NitrogenPageDoc | NitrogenTemplateDoc, collectionSlug: string, settings: NitrogenSettingsGlobal): TemplateContext; /** * Resolve the best-matching template for a document * (php:140-182 resolve_template + php:106-132 evaluate_legacy). * * Returns a { ID, content } ref with ctrl-links resolved and content * JSON-stringified — the same shape getTemplateForType() returns — or null if * no template matches. */ export declare function resolveTemplateForDocument(payload: Payload, doc: NitrogenPageDoc | NitrogenTemplateDoc, collectionSlug: string, settings: NitrogenSettingsGlobal): Promise;