/**
 * Check dependency utility
 *
 * Evaluates whether a dependency condition is satisfied based on form data.
 */
import { parse_dependency } from './parse_dependency.js';
/**
 * Check if a field should be visible based on its dependency condition
 *
 * A field is visible if:
 * - It has no dependency (always visible)
 * - Its dependency is in an invalid format (fails gracefully to visible)
 * - Its dependency condition is satisfied (field value matches expected value)
 *
 * @param dependency - Dependency string in "field_id:value" format
 * @param form_data - Current form data keyed by field ID
 * @returns true if field should be visible, false if dependency is not satisfied
 *
 * @example
 * ```ts
 * const form_data = { country: "AU", has_spouse: "true" };
 *
 * // No dependency - always visible
 * check_dependency(undefined, form_data) // => true
 *
 * // Satisfied dependency
 * check_dependency("country:AU", form_data) // => true
 *
 * // Unsatisfied dependency
 * check_dependency("country:US", form_data) // => false
 *
 * // Invalid format - defaults to visible
 * check_dependency("invalid", form_data) // => true
 * ```
 */
export function check_dependency(dependency, form_data) {
    if (!dependency) {
        return true; // No dependency, always show
    }
    const parsed = parse_dependency(dependency);
    if (!parsed) {
        return true; // Invalid dependency format, show by default
    }
    const dependency_value = form_data[parsed.field_id];
    return String(dependency_value) === parsed.value;
}
//# sourceMappingURL=check_dependency.js.map