{"version":3,"file":"forbidden-if-rules.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/conditional/forbidden-if-rules.ts"],"sourcesContent":["import { getFieldValue, invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport { isEmptyValue } from \"../../helpers/is-empty-value\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Forbidden if rule - field is forbidden if another field equals a specific value\r\n * Supports both global and sibling scope\r\n */\r\nexport const forbiddenIfRule: SchemaRule<{\r\n  field: string;\r\n  value: any;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"forbiddenIf\",\r\n  description: \"The field is forbidden if another field equals a specific value\",\r\n  sortOrder: -2,\r\n  defaultErrorMessage: \"The :input is forbidden\",\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 is forbidden if it has a value and the other field equals the expected value\r\n    if (!isEmptyValue(value) && fieldValue === expectedValue) {\r\n      this.context.translatableParams.field = this.context.options.field;\r\n      this.context.translationParams.value = expectedValue;\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 * Forbidden if not rule - field is forbidden if another field does NOT equal a specific value\r\n * Supports both global and sibling scope\r\n */\r\nexport const forbiddenIfNotRule: SchemaRule<{\r\n  field: string;\r\n  value: any;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"forbiddenIfNot\",\r\n  description: \"The field is forbidden if another field does NOT equal a specific value\",\r\n  sortOrder: -2,\r\n  defaultErrorMessage: \"The :input is forbidden\",\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 is forbidden if it has a value and the other field does NOT equal the expected value\r\n    if (!isEmptyValue(value) && fieldValue !== expectedValue) {\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 * Forbidden if empty rule - field is forbidden if another field is empty\r\n * Supports both global and sibling scope\r\n */\r\nexport const forbiddenIfEmptyRule: SchemaRule<{\r\n  field: string;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"forbiddenIfEmpty\",\r\n  description: \"The field is forbidden if another field is empty\",\r\n  sortOrder: -2,\r\n  defaultErrorMessage: \"The :input is forbidden\",\r\n  async validate(value: any, context) {\r\n    const fieldValue = getFieldValue(this, context);\r\n\r\n    // Field is forbidden if it has a value and the other field is empty\r\n    if (!isEmptyValue(value) && 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 * Forbidden if not empty rule - field is forbidden if another field is not empty\r\n * Supports both global and sibling scope\r\n */\r\nexport const forbiddenIfNotEmptyRule: SchemaRule<{\r\n  field: string;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"forbiddenIfNotEmpty\",\r\n  description: \"The field is forbidden if another field is not empty\",\r\n  sortOrder: -2,\r\n  defaultErrorMessage: \"The :input is forbidden\",\r\n  async validate(value: any, context) {\r\n    const fieldValue = getFieldValue(this, context);\r\n\r\n    // Field is forbidden if it has a value and the other field is not empty\r\n    if (!isEmptyValue(value) && !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 * Forbidden if in rule - field is forbidden if another field's value is in the given array\r\n * Supports both global and sibling scope\r\n */\r\nexport const forbiddenIfInRule: SchemaRule<{\r\n  field: string;\r\n  values: any[];\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"forbiddenIfIn\",\r\n  description: \"The field is forbidden if another field's value is in the given array\",\r\n  sortOrder: -2,\r\n  defaultErrorMessage: \"The :input is forbidden\",\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 is forbidden if it has a value and the other field's value is in the array\r\n    if (!isEmptyValue(value) && values.includes(fieldValue)) {\r\n      this.context.translationParams.values = values.join(\", \");\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 * Forbidden if not in rule - field is forbidden if another field's value is NOT in the given array\r\n * Supports both global and sibling scope\r\n */\r\nexport const forbiddenIfNotInRule: SchemaRule<{\r\n  field: string;\r\n  values: any[];\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"forbiddenIfNotIn\",\r\n  description: \"The field is forbidden if another field's value is NOT in the given array\",\r\n  sortOrder: -2,\r\n  defaultErrorMessage: \"The :input is forbidden\",\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 is forbidden if it has a value and the other field's value is NOT in the array\r\n    if (!isEmptyValue(value) && !values.includes(fieldValue)) {\r\n      this.context.translationParams.values = values.join(\", \");\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"],"mappings":";;;;;;;;;;AAQA,MAAa,kBAIR;CACH,MAAM;CACN,aAAa;CACb,WAAW;CACX,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,EAAE,OAAO,kBAAkB,KAAK,QAAQ;EAC9C,MAAM,aAAa,cAAc,MAAM,OAAO;EAG9C,IAAI,CAAC,aAAa,KAAK,KAAK,eAAe,eAAe;GACxD,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;GAC7D,KAAK,QAAQ,kBAAkB,QAAQ;GACvC,OAAO,YAAY,MAAM,OAAO;EAClC;EAEA,OAAO;CACT;AACF;;;;;AAMA,MAAa,qBAIR;CACH,MAAM;CACN,aAAa;CACb,WAAW;CACX,qBAAqB;CACrB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