{"version":3,"file":"date-field-comparison-rules.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/date/date-field-comparison-rules.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\r\nimport { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport { isDateValue } from \"../../helpers/date-helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Before field rule - date must be < given date or field\r\n * Smart detection: date value or field name\r\n * Supports both global and sibling scope\r\n */\r\nexport const beforeFieldRule: SchemaRule<{\r\n  dateOrField: Date | string | number;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"beforeField\",\r\n  description: \"The date must be before the given date or field\",\r\n  defaultErrorMessage: \"The :input must be before :dateOrField\",\r\n  async validate(value: Date, context) {\r\n    const { dateOrField, scope = \"global\" } = this.context.options;\r\n    let compareDate: Date;\r\n\r\n    if (isDateValue(dateOrField)) {\r\n      // Value comparison\r\n      compareDate = new Date(dateOrField);\r\n    } else {\r\n      // Field comparison\r\n      const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n      const fieldValue = get(source, dateOrField as string);\r\n\r\n      if (fieldValue === undefined) {\r\n        return VALID_RULE;\r\n      }\r\n\r\n      compareDate = new Date(fieldValue);\r\n    }\r\n\r\n    const inputDate = new Date(value);\r\n\r\n    if (inputDate < compareDate) {\r\n      return VALID_RULE;\r\n    }\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * After field rule - date must be > given date or field\r\n * Smart detection: date value or field name\r\n * Supports both global and sibling scope\r\n */\r\nexport const afterFieldRule: SchemaRule<{\r\n  dateOrField: Date | string | number;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"afterField\",\r\n  description: \"The date must be after the given date or field\",\r\n  defaultErrorMessage: \"The :input must be after :dateOrField\",\r\n  async validate(value: Date, context) {\r\n    const { dateOrField, scope = \"global\" } = this.context.options;\r\n    let compareDate: Date;\r\n\r\n    if (isDateValue(dateOrField)) {\r\n      // Value comparison\r\n      compareDate = new Date(dateOrField);\r\n      this.context.translationParams.dateOrField = compareDate.toISOString();\r\n    } else {\r\n      // Field comparison\r\n      const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n      const fieldValue = get(source, dateOrField as string);\r\n\r\n      if (fieldValue === undefined) {\r\n        return VALID_RULE;\r\n      }\r\n\r\n      compareDate = new Date(fieldValue);\r\n      this.context.translatableParams.dateOrField = fieldValue;\r\n    }\r\n\r\n    const inputDate = new Date(value);\r\n\r\n    if (inputDate > compareDate) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * Same as field rule - date must be the same as another field's date\r\n * Supports both global and sibling scope\r\n */\r\nexport const sameAsFieldDateRule: SchemaRule<{\r\n  field: string;\r\n  scope?: \"global\" | \"sibling\";\r\n}> = {\r\n  name: \"sameAsFieldDate\",\r\n  description: \"The date must be the same as another field's date\",\r\n  defaultErrorMessage: \"The :input must be the same as :field\",\r\n  async validate(value: Date, context) {\r\n    const { field, scope = \"global\" } = this.context.options;\r\n    const source = scope === \"sibling\" ? context.parent : context.allValues;\r\n    const fieldValue = get(source, field);\r\n\r\n    // Both fields must exist to be considered \"the same\"\r\n    if (fieldValue === undefined || value === undefined) {\r\n      this.context.translatableParams.field = fieldValue;\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    const inputDate = new Date(value);\r\n    inputDate.setHours(0, 0, 0, 0);\r\n    const compareDate = new Date(fieldValue);\r\n    compareDate.setHours(0, 0, 0, 0);\r\n\r\n    if (inputDate.getTime() === compareDate.getTime()) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    this.context.translatableParams.field = fieldValue;\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,kBAGR;CACH,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,EAAE,aAAa,QAAQ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