You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
/**
|
|
* ============================================================================
|
|
* DISPLAY FLAG EVALUATOR
|
|
* ============================================================================
|
|
*/
|
|
|
|
import type {JsonLogic, ID, Value, AttrID} from '@/types';
|
|
import type { JsonLogicEvaluator } from '@/engine';
|
|
import { extractIdPart } from '@/utils';
|
|
|
|
/**
|
|
* Evalúa display flags con soporte para condicionales
|
|
*/
|
|
export function evaluateDisplayFlag(
|
|
flag: boolean | JsonLogic | undefined,
|
|
defaultValue: boolean,
|
|
attributeValues: Record<AttrID, Value>,
|
|
evaluator: JsonLogicEvaluator
|
|
): boolean {
|
|
if (flag === undefined) return defaultValue;
|
|
if (typeof flag === 'boolean') return flag;
|
|
|
|
// Es JsonLogic: evaluar
|
|
const data = {
|
|
attributes: Object.fromEntries(
|
|
(Object.entries(attributeValues) as [AttrID, Value][]).map(([id, value]) => [
|
|
extractIdPart(id, 'at'),
|
|
value
|
|
])
|
|
)
|
|
};
|
|
|
|
return evaluator.evaluate(flag, data);
|
|
}
|