{"version":3,"file":"present-if-rules.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/conditional/present-if-rules.ts"],"sourcesContent":["import { getFieldValue, invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\nimport { isEmptyValue } from \"./../../helpers/is-empty-value\";\r\n\r\n/**\r\n * Present if rule - field must be present if another field equals a specific value\r\n * Supports both global and sibling scope\r\n */\r\nexport const presentIfRule: SchemaRule<{\r\n  field: string;\r\n  value: any;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"presentIf\",\r\n  description: \"The field must be present if another field equals a specific value\",\r\n  sortOrder: -2,\r\n  requiresValue: false,\r\n  defaultErrorMessage: \"The :input field must be present\",\r\n  async validate(value: any, context) {\r\n    const { value: expectedValue } = this.context.options;\r\n    const fieldValue = getFieldValue(this, context);\r\n\r\n    // Field must be present if the other field equals the expected value\r\n    if (value === undefined && fieldValue === expectedValue) {\r\n      this.context.translationParams.value = expectedValue;\r\n      this.context.translatableParams.field = this.context.options.field;\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    return VALID_RULE;\r\n  },\r\n};\r\n\r\n/**\r\n * Present if empty rule - field must be present if another field is empty\r\n * Supports both global and sibling scope\r\n */\r\nexport const presentIfEmptyRule: SchemaRule<{\r\n  field: string;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"presentIfEmpty\",\r\n  description: \"The field must be present if another field is empty\",\r\n  sortOrder: -2,\r\n  requiresValue: false,\r\n  defaultErrorMessage: \"The :input field must be present\",\r\n  async validate(value: any, context) {\r\n    const fieldValue = getFieldValue(this, context);\r\n\r\n    // Field must be present if the other field is empty\r\n    if (value === undefined && isEmptyValue(fieldValue)) {\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    return VALID_RULE;\r\n  },\r\n};\r\n\r\n/**\r\n * Present if not empty rule - field must be present if another field is not empty\r\n * Supports both global and sibling scope\r\n */\r\nexport const presentIfNotEmptyRule: SchemaRule<{\r\n  field: string;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"presentIfNotEmpty\",\r\n  description: \"The field must be present if another field is not empty\",\r\n  sortOrder: -2,\r\n  requiresValue: false,\r\n  defaultErrorMessage: \"The :input field must be present\",\r\n  async validate(value: any, context) {\r\n    const fieldValue = getFieldValue(this, context);\r\n\r\n    // Field must be present if the other field is not empty\r\n    if (value === undefined && !isEmptyValue(fieldValue)) {\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    return VALID_RULE;\r\n  },\r\n};\r\n\r\n/**\r\n * Present if in rule - field must be present if another field's value is in the given array\r\n * Supports both global and sibling scope\r\n */\r\nexport const presentIfInRule: SchemaRule<{\r\n  field: string;\r\n  values: any[];\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"presentIfIn\",\r\n  description: \"The field must be present if another field's value is in the given array\",\r\n  sortOrder: -2,\r\n  requiresValue: false,\r\n  defaultErrorMessage: \"The :input field must be present\",\r\n  async validate(value: any, context) {\r\n    const { values } = this.context.options;\r\n    const fieldValue = getFieldValue(this, context);\r\n\r\n    // Field must be present if the other field's value is in the array\r\n    if (value === undefined && values.includes(fieldValue)) {\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    return VALID_RULE;\r\n  },\r\n};\r\n\r\n/**\r\n * Present if not in rule - field must be present if another field's value is NOT in the given array\r\n * Supports both global and sibling scope\r\n */\r\nexport const presentIfNotInRule: SchemaRule<{\r\n  field: string;\r\n  values: any[];\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"presentIfNotIn\",\r\n  description: \"The field must be present if another field's value is NOT in the given array\",\r\n  sortOrder: -2,\r\n  requiresValue: false,\r\n  defaultErrorMessage: \"The :input field must be present\",\r\n  async validate(value: any, context) {\r\n    const { values } = this.context.options;\r\n    const fieldValue = getFieldValue(this, context);\r\n\r\n    // Field must be present if the other field's value is NOT in the array\r\n    if (value === undefined && !values.includes(fieldValue)) {\r\n      return invalid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