{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "persian-date-zod",
  "title": "Persian Date (Zod)",
  "description": "zod schemas for persian-date: zPersianDate coerces an ISO string, a shamsi yyyy/MM/dd string, an epoch number, or a Date into a Date with optional min/max bounds; zPersianDateRange validates a from/to reservation-style range.",
  "dependencies": [
    "date-fns",
    "date-fns-jalali",
    "zod"
  ],
  "registryDependencies": [
    "@persianlabsui/persian-date"
  ],
  "files": [
    {
      "path": "registry/base/lib/persian-date-zod.ts",
      "content": "import { parseISO } from \"date-fns\"\nimport { z } from \"zod\"\n\nimport {\n  isAfter,\n  isBefore,\n  isValidDate,\n  parseDate,\n  validateRange,\n  type RangeValidationOptions,\n} from \"@/lib/persian-date\"\n\n/** Matches an ISO-8601 date, e.g. \"2026-08-10\" or \"2026-08-10T12:00:00Z\". */\nconst ISO_DATE_PATTERN = /^\\d{4}-\\d{2}-\\d{2}/\n\n/** A fixed, non-time-dependent stand-in for parseDate's referenceDate. */\nconst EPOCH = new Date(0)\n\n/** Anything zPersianDate can coerce: an ISO string, a \"yyyy/MM/dd\" shamsi string, an epoch number, or a Date. */\nexport type PersianDateInput = string | number | Date\n\nfunction coerceToDate(value: unknown): Date | null {\n  if (value instanceof Date) {\n    return isValidDate(value) ? value : null\n  }\n\n  if (typeof value === \"number\") {\n    const date = new Date(value)\n    return isValidDate(date) ? date : null\n  }\n\n  if (typeof value === \"string\") {\n    // Try a strict ISO-8601 string first (Gregorian), then fall back to a\n    // \"yyyy/MM/dd\" shamsi string -- the two most common serialized forms.\n    // Deliberately not `new Date(value)`: its native parsing is dangerously\n    // lenient and will happily misinterpret \"1405/05/19\" as some other date\n    // instead of rejecting it, silently producing the wrong result.\n    if (ISO_DATE_PATTERN.test(value)) {\n      const iso = parseISO(value)\n      if (isValidDate(iso)) return iso\n    }\n    // Every field is explicit in \"yyyy/MM/dd\", so referenceDate never\n    // actually affects the result -- pass a fixed value instead of relying\n    // on parseDate's `new Date()` default, which would otherwise make this\n    // function's output depend on the current time (and break SSR/prerender\n    // for any caller that runs it synchronously during render).\n    return parseDate(value, \"yyyy/MM/dd\", EPOCH)\n  }\n\n  return null\n}\n\nexport interface ZPersianDateOptions {\n  /** Inclusive lower bound. Accepts anything zPersianDate itself accepts. */\n  min?: PersianDateInput\n  /** Inclusive upper bound. Accepts anything zPersianDate itself accepts. */\n  max?: PersianDateInput\n}\n\n/**\n * A zod schema that accepts an ISO-8601 string, a \"yyyy/MM/dd\" shamsi string,\n * an epoch number, or a native Date, and outputs a plain `Date`. `min`/`max`\n * bounds are inclusive.\n */\nexport function zPersianDate(options: ZPersianDateOptions = {}) {\n  const minDate = options.min != null ? coerceToDate(options.min) : undefined\n  const maxDate = options.max != null ? coerceToDate(options.max) : undefined\n\n  return z.custom<PersianDateInput>().transform((value, ctx): Date => {\n    const date = coerceToDate(value)\n\n    if (!date) {\n      ctx.addIssue({ code: \"custom\", message: \"Invalid date\" })\n      return z.NEVER\n    }\n\n    if (minDate && isBefore(date, minDate)) {\n      ctx.addIssue({\n        code: \"custom\",\n        message: `Date must be on or after ${minDate.toISOString()}`,\n      })\n      return z.NEVER\n    }\n\n    if (maxDate && isAfter(date, maxDate)) {\n      ctx.addIssue({\n        code: \"custom\",\n        message: `Date must be on or before ${maxDate.toISOString()}`,\n      })\n      return z.NEVER\n    }\n\n    return date\n  })\n}\n\n/**\n * A zod schema for a `{ from, to }` reservation-style range, validated with\n * the same rules as `validateRange` from persian-date (ordering, minDays,\n * maxDays, disablePast, disabledDates). The failure reason is attached to\n * the `to` field.\n */\nexport function zPersianDateRange(options: RangeValidationOptions = {}) {\n  return z\n    .object({\n      from: zPersianDate(),\n      to: zPersianDate(),\n    })\n    .superRefine((value, ctx) => {\n      const reason = validateRange(value, options)\n      if (reason) {\n        ctx.addIssue({ code: \"custom\", message: reason, path: [\"to\"] })\n      }\n    })\n}\n",
      "type": "registry:lib"
    }
  ],
  "type": "registry:lib"
}