{"version":3,"file":"present-without-rules.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/conditional/present-without-rules.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\r\nimport { getFieldValue, invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Present without rule - field must be present if another field is missing\r\n * Supports both global and sibling scope\r\n */\r\nexport const presentWithoutRule: SchemaRule<{\r\n  field: string;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"presentWithout\",\r\n  description: \"The field must be present if another field is missing\",\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 missing\r\n    if (value === undefined && fieldValue === undefined) {\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 without all rule - field must be present if all specified fields are missing\r\n * Supports both global and sibling scope\r\n */\r\nexport const presentWithoutAllRule: SchemaRule<{\r\n  fields: string[];\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"presentWithoutAll\",\r\n  description: \"The field must be present if all specified fields are missing\",\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 { fields, scope = \"global\" } = this.context.options;\r\n    const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n\r\n    // Check if all fields are missing\r\n    const allMissing = fields.every((field) => get(source, field) === undefined);\r\n\r\n    // Field must be present if all other fields are missing\r\n    if (value === undefined && allMissing) {\r\n      fields.forEach((field) => {\r\n        this.context.translatableParams.field = field;\r\n      });\r\n\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 without any rule - field must be present if any of the specified fields is missing\r\n * Supports both global and sibling scope\r\n */\r\nexport const presentWithoutAnyRule: SchemaRule<{\r\n  fields: string[];\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"presentWithoutAny\",\r\n  description: \"The field must be present if any of the specified fields is missing\",\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 { fields, scope = \"global\" } = this.context.options;\r\n    const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n\r\n    // Check if any field is missing\r\n    const anyMissing = fields.some((field) => get(source, field) === undefined);\r\n\r\n    // Field must be present if any other field is missing\r\n    if (value === undefined && anyMissing) {\r\n      fields.forEach((field) => {\r\n        this.context.translatableParams.field = field;\r\n      });\r\n\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    return VALID_RULE;\r\n  },\r\n};\r\n"],"mappings":";;;;;;;;;;AAQA,MAAa,qBAGR;CACH,MAAM;CACN,aAAa;CACb,WAAW;CACX,eAAe;CACf,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,aAAa,cAAc,MAAM,OAAO;EAG9C,IAAI,UAAU,UAAa,eAAe,QAAW;GACnD,KAAK,QAAQ,mBAAmB,QAAQ,KAAK,QAAQ,QAAQ;GAC7D,OAAO,YAAY,MAAM,OAAO;EAClC;EAEA,OAAO;CACT;AACF;;;;;AAMA,MAAa,wBAGR;CACH,MAAM;CACN,aAAa;CACb,WAAW;CACX,eAAe;CACf,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,EAAE,QAAQ,QAAQ,aAAa,KAAK,QAAQ;EAClD,MAAM,SAAS,UAAU,YAAY,QAAQ,SAAS,QAAQ;EAG9D,MAAM,aAAa,OAAO,OAAO,UAAU,IAAI,QAAQ,KAAK,MAAM,MAAS;EAG3E,IAAI,UAAU,UAAa,YAAY;GACrC,OAAO,SAAS,UAAU;IACxB,KAAK,QAAQ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