@bookinglab/booking-ui-react 1.10.0 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,7 +3,9 @@
3
3
  var react = require('react');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
 
6
- // src/components/BookingForm.tsx
6
+ var __defProp = Object.defineProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
9
  var cx = (...classes) => classes.filter(Boolean).join(" ");
8
10
  function FormField({
9
11
  question,
@@ -35,7 +37,13 @@ function FormField({
35
37
  };
36
38
  const renderHelpText = () => {
37
39
  if (!question.help_text) return null;
38
- return /* @__PURE__ */ jsxRuntime.jsx("p", { className: classNames?.helpText ?? defaultHelpText, children: question.help_text });
40
+ return /* @__PURE__ */ jsxRuntime.jsx(
41
+ "p",
42
+ {
43
+ className: classNames?.helpText ?? defaultHelpText,
44
+ dangerouslySetInnerHTML: { __html: question.help_text }
45
+ }
46
+ );
39
47
  };
40
48
  const renderError = () => {
41
49
  if (!error) return null;
@@ -105,6 +113,39 @@ function FormField({
105
113
  renderHelpText(),
106
114
  renderError()
107
115
  ] });
116
+ case "radio":
117
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classNames?.fieldWrapper ?? defaultFieldWrapper, children: [
118
+ renderLabel(),
119
+ /* @__PURE__ */ jsxRuntime.jsx(
120
+ "div",
121
+ {
122
+ role: "radiogroup",
123
+ "aria-labelledby": inputId,
124
+ className: classNames?.radioGroup ?? "flex flex-col gap-2 mt-1",
125
+ children: question.options?.map((option) => {
126
+ const optionId = `${inputId}-${option.id}`;
127
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
128
+ /* @__PURE__ */ jsxRuntime.jsx(
129
+ "input",
130
+ {
131
+ id: optionId,
132
+ type: "radio",
133
+ name: inputId,
134
+ value: option.id,
135
+ checked: String(value ?? "") === String(option.id),
136
+ onChange: () => onChange(option.id),
137
+ className: classNames?.radio ?? "h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500",
138
+ ...ariaProps
139
+ }
140
+ ),
141
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: optionId, className: classNames?.radioLabel ?? cx("text-sm", classNames?.label ?? "text-gray-700"), children: option.name })
142
+ ] }, option.id);
143
+ })
144
+ }
145
+ ),
146
+ renderHelpText(),
147
+ renderError()
148
+ ] });
108
149
  case "date":
109
150
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classNames?.fieldWrapper ?? defaultFieldWrapper, children: [
110
151
  renderLabel(),
@@ -174,6 +215,7 @@ function BookingForm({
174
215
  questions,
175
216
  onSubmit,
176
217
  submitLabel = "Submit",
218
+ isAdmin = false,
177
219
  className = "",
178
220
  labelClassName,
179
221
  classNames: classNamesProp
@@ -191,40 +233,70 @@ function BookingForm({
191
233
  if (!settings?.conditional_answers) {
192
234
  return true;
193
235
  }
194
- const conditionEntries = Object.entries(settings.conditional_answers);
195
- if (conditionEntries.length === 0) {
196
- return true;
197
- }
198
- return conditionEntries.some(([questionIdStr, expectedAnswer]) => {
199
- const questionId = Number(questionIdStr);
236
+ const conditionalAnswers = settings.conditional_answers;
237
+ const conditionalQuestion = settings.conditional_question;
238
+ const buildCandidates = (questionId) => {
200
239
  const currentValue = values[String(questionId)];
240
+ const candidates = /* @__PURE__ */ new Set();
201
241
  if (currentValue === void 0 || currentValue === "" || currentValue === null) {
202
- return false;
242
+ return candidates;
203
243
  }
204
- const normalizedCurrent = typeof currentValue === "object" && currentValue !== null && "id" in currentValue ? currentValue : currentValue;
205
- const candidates = /* @__PURE__ */ new Set();
206
244
  const addCandidate = (v) => {
207
245
  if (v === void 0 || v === null) return;
208
246
  const s = String(v).trim();
209
247
  if (s) candidates.add(s);
210
248
  };
211
- const sourceQuestion = questions.find((q) => q.id === questionId);
249
+ const normalizedCurrent = typeof currentValue === "object" && currentValue !== null && "id" in currentValue ? currentValue : currentValue;
212
250
  if (typeof normalizedCurrent === "object" && normalizedCurrent !== null) {
213
251
  addCandidate(normalizedCurrent.id);
214
252
  addCandidate(normalizedCurrent.name);
215
253
  } else {
216
254
  addCandidate(normalizedCurrent);
217
255
  }
218
- if (sourceQuestion?.detail_type === "select" && sourceQuestion.options?.length) {
256
+ const sourceQuestion = questions.find((q) => q.id === questionId);
257
+ if ((sourceQuestion?.detail_type === "select" || sourceQuestion?.detail_type === "radio") && sourceQuestion.options?.length) {
219
258
  const currentStr = [...candidates][0] ?? "";
220
259
  const optionById = sourceQuestion.options.find((o) => String(o.id) === currentStr);
221
- const optionByName = sourceQuestion.options.find((o) => String(o.name).trim() === currentStr);
260
+ const optionByName = sourceQuestion.options.find(
261
+ (o) => String(o.name).trim() === currentStr
262
+ );
222
263
  const opt = optionById ?? optionByName;
223
264
  if (opt) {
224
265
  addCandidate(opt.id);
225
266
  addCandidate(opt.name);
226
267
  }
227
268
  }
269
+ return candidates;
270
+ };
271
+ const isTruthyFlag = (v) => {
272
+ if (v === void 0 || v === null) return true;
273
+ if (typeof v === "boolean") return v;
274
+ if (typeof v === "number") return v !== 0;
275
+ if (typeof v === "string") {
276
+ const s = v.trim().toLowerCase();
277
+ return s !== "" && s !== "0" && s !== "false";
278
+ }
279
+ return !!v;
280
+ };
281
+ if (conditionalQuestion !== void 0 && conditionalQuestion !== null && conditionalQuestion !== "") {
282
+ const sourceId = Number(conditionalQuestion);
283
+ if (!Number.isFinite(sourceId)) return true;
284
+ const candidates = buildCandidates(sourceId);
285
+ if (candidates.size === 0) return false;
286
+ const entries = Object.entries(conditionalAnswers);
287
+ if (entries.length === 0) return true;
288
+ return entries.some(
289
+ ([optionKey, flag]) => isTruthyFlag(flag) && candidates.has(String(optionKey).trim())
290
+ );
291
+ }
292
+ const conditionEntries = Object.entries(conditionalAnswers);
293
+ if (conditionEntries.length === 0) {
294
+ return true;
295
+ }
296
+ return conditionEntries.some(([questionIdStr, expectedAnswer]) => {
297
+ const questionId = Number(questionIdStr);
298
+ const candidates = buildCandidates(questionId);
299
+ if (candidates.size === 0) return false;
228
300
  const matchesScalar = (expected) => {
229
301
  const expectedStr = String(expected).trim();
230
302
  return candidates.has(expectedStr);
@@ -247,7 +319,7 @@ function BookingForm({
247
319
  },
248
320
  [values, questions]
249
321
  );
250
- const visibleQuestions = questions.filter(isQuestionVisible);
322
+ const visibleQuestions = questions.filter((q) => isAdmin || !q.admin_only).filter(isQuestionVisible);
251
323
  const validateField = react.useCallback((question, value) => {
252
324
  if (question.detail_type === "heading") return null;
253
325
  if (question.required) {
@@ -271,16 +343,16 @@ function BookingForm({
271
343
  }, []);
272
344
  const validateAll = react.useCallback(() => {
273
345
  const newErrors = {};
274
- let isValid = true;
346
+ let isValid2 = true;
275
347
  visibleQuestions.forEach((question) => {
276
348
  const error = validateField(question, values[question.id]);
277
349
  if (error) {
278
350
  newErrors[question.id] = error;
279
- isValid = false;
351
+ isValid2 = false;
280
352
  }
281
353
  });
282
354
  setErrors(newErrors);
283
- return isValid;
355
+ return isValid2;
284
356
  }, [visibleQuestions, values, validateField]);
285
357
  react.useEffect(() => {
286
358
  const visibleIds = new Set(visibleQuestions.map((q) => q.id));
@@ -542,17 +614,17 @@ var RegistrationForm = react.forwardRef(
542
614
  );
543
615
  const validateAll = react.useCallback(() => {
544
616
  const newErrors = {};
545
- let isValid = true;
617
+ let isValid2 = true;
546
618
  for (const field of allFields) {
547
619
  const value = values[field.name] || "";
548
620
  const error = validateField(field, value, values);
549
621
  if (error) {
550
622
  newErrors[field.name] = error;
551
- isValid = false;
623
+ isValid2 = false;
552
624
  }
553
625
  }
554
626
  setErrors(newErrors);
555
- return isValid;
627
+ return isValid2;
556
628
  }, [allFields, values, validateField]);
557
629
  const checkIsValid = react.useCallback(
558
630
  (currentValues) => {
@@ -613,8 +685,8 @@ var RegistrationForm = react.forwardRef(
613
685
  }
614
686
  }
615
687
  if (onChange) {
616
- const isValid = checkIsValid(newValues);
617
- onChange(newValues, isValid);
688
+ const isValid2 = checkIsValid(newValues);
689
+ onChange(newValues, isValid2);
618
690
  }
619
691
  },
620
692
  [values, touched, allFields, validateField, onChange, checkIsValid]
@@ -1319,18 +1391,18 @@ var ResetPasswordForm = react.forwardRef(
1319
1391
  e.preventDefault();
1320
1392
  const allTouched = {};
1321
1393
  const newErrors = {};
1322
- let isValid = true;
1394
+ let isValid2 = true;
1323
1395
  for (const field of FIELDS) {
1324
1396
  allTouched[field.name] = true;
1325
1397
  const error = validateField(field.name, values[field.name], values);
1326
1398
  if (error) {
1327
1399
  newErrors[field.name] = error;
1328
- isValid = false;
1400
+ isValid2 = false;
1329
1401
  }
1330
1402
  }
1331
1403
  setTouched(allTouched);
1332
1404
  setErrors(newErrors);
1333
- if (isValid) {
1405
+ if (isValid2) {
1334
1406
  onSubmit(values);
1335
1407
  setValues({ currentPassword: "", newPassword: "", confirmNewPassword: "" });
1336
1408
  setErrors({});
@@ -1402,12 +1474,4245 @@ var ResetPasswordForm = react.forwardRef(
1402
1474
  );
1403
1475
  ResetPasswordForm.displayName = "ResetPasswordForm";
1404
1476
 
1477
+ // ../../node_modules/date-fns/toDate.mjs
1478
+ function toDate(argument) {
1479
+ const argStr = Object.prototype.toString.call(argument);
1480
+ if (argument instanceof Date || typeof argument === "object" && argStr === "[object Date]") {
1481
+ return new argument.constructor(+argument);
1482
+ } else if (typeof argument === "number" || argStr === "[object Number]" || typeof argument === "string" || argStr === "[object String]") {
1483
+ return new Date(argument);
1484
+ } else {
1485
+ return /* @__PURE__ */ new Date(NaN);
1486
+ }
1487
+ }
1488
+
1489
+ // ../../node_modules/date-fns/constructFrom.mjs
1490
+ function constructFrom(date, value) {
1491
+ if (date instanceof Date) {
1492
+ return new date.constructor(value);
1493
+ } else {
1494
+ return new Date(value);
1495
+ }
1496
+ }
1497
+
1498
+ // ../../node_modules/date-fns/addDays.mjs
1499
+ function addDays(date, amount) {
1500
+ const _date = toDate(date);
1501
+ if (isNaN(amount)) return constructFrom(date, NaN);
1502
+ if (!amount) {
1503
+ return _date;
1504
+ }
1505
+ _date.setDate(_date.getDate() + amount);
1506
+ return _date;
1507
+ }
1508
+ var millisecondsInWeek = 6048e5;
1509
+ var millisecondsInMinute = 6e4;
1510
+ var millisecondsInHour = 36e5;
1511
+ var millisecondsInSecond = 1e3;
1512
+
1513
+ // ../../node_modules/date-fns/_lib/defaultOptions.mjs
1514
+ var defaultOptions = {};
1515
+ function getDefaultOptions() {
1516
+ return defaultOptions;
1517
+ }
1518
+
1519
+ // ../../node_modules/date-fns/startOfWeek.mjs
1520
+ function startOfWeek(date, options) {
1521
+ const defaultOptions2 = getDefaultOptions();
1522
+ const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
1523
+ const _date = toDate(date);
1524
+ const day = _date.getDay();
1525
+ const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
1526
+ _date.setDate(_date.getDate() - diff);
1527
+ _date.setHours(0, 0, 0, 0);
1528
+ return _date;
1529
+ }
1530
+
1531
+ // ../../node_modules/date-fns/startOfISOWeek.mjs
1532
+ function startOfISOWeek(date) {
1533
+ return startOfWeek(date, { weekStartsOn: 1 });
1534
+ }
1535
+
1536
+ // ../../node_modules/date-fns/getISOWeekYear.mjs
1537
+ function getISOWeekYear(date) {
1538
+ const _date = toDate(date);
1539
+ const year = _date.getFullYear();
1540
+ const fourthOfJanuaryOfNextYear = constructFrom(date, 0);
1541
+ fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
1542
+ fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
1543
+ const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
1544
+ const fourthOfJanuaryOfThisYear = constructFrom(date, 0);
1545
+ fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
1546
+ fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
1547
+ const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
1548
+ if (_date.getTime() >= startOfNextYear.getTime()) {
1549
+ return year + 1;
1550
+ } else if (_date.getTime() >= startOfThisYear.getTime()) {
1551
+ return year;
1552
+ } else {
1553
+ return year - 1;
1554
+ }
1555
+ }
1556
+
1557
+ // ../../node_modules/date-fns/startOfDay.mjs
1558
+ function startOfDay(date) {
1559
+ const _date = toDate(date);
1560
+ _date.setHours(0, 0, 0, 0);
1561
+ return _date;
1562
+ }
1563
+
1564
+ // ../../node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.mjs
1565
+ function getTimezoneOffsetInMilliseconds(date) {
1566
+ const _date = toDate(date);
1567
+ const utcDate = new Date(
1568
+ Date.UTC(
1569
+ _date.getFullYear(),
1570
+ _date.getMonth(),
1571
+ _date.getDate(),
1572
+ _date.getHours(),
1573
+ _date.getMinutes(),
1574
+ _date.getSeconds(),
1575
+ _date.getMilliseconds()
1576
+ )
1577
+ );
1578
+ utcDate.setUTCFullYear(_date.getFullYear());
1579
+ return +date - +utcDate;
1580
+ }
1581
+
1582
+ // ../../node_modules/date-fns/startOfISOWeekYear.mjs
1583
+ function startOfISOWeekYear(date) {
1584
+ const year = getISOWeekYear(date);
1585
+ const fourthOfJanuary = constructFrom(date, 0);
1586
+ fourthOfJanuary.setFullYear(year, 0, 4);
1587
+ fourthOfJanuary.setHours(0, 0, 0, 0);
1588
+ return startOfISOWeek(fourthOfJanuary);
1589
+ }
1590
+
1591
+ // ../../node_modules/date-fns/isDate.mjs
1592
+ function isDate(value) {
1593
+ return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
1594
+ }
1595
+
1596
+ // ../../node_modules/date-fns/isValid.mjs
1597
+ function isValid(date) {
1598
+ if (!isDate(date) && typeof date !== "number") {
1599
+ return false;
1600
+ }
1601
+ const _date = toDate(date);
1602
+ return !isNaN(Number(_date));
1603
+ }
1604
+
1605
+ // ../../node_modules/date-fns/locale/en-US/_lib/formatDistance.mjs
1606
+ var formatDistanceLocale = {
1607
+ lessThanXSeconds: {
1608
+ one: "less than a second",
1609
+ other: "less than {{count}} seconds"
1610
+ },
1611
+ xSeconds: {
1612
+ one: "1 second",
1613
+ other: "{{count}} seconds"
1614
+ },
1615
+ halfAMinute: "half a minute",
1616
+ lessThanXMinutes: {
1617
+ one: "less than a minute",
1618
+ other: "less than {{count}} minutes"
1619
+ },
1620
+ xMinutes: {
1621
+ one: "1 minute",
1622
+ other: "{{count}} minutes"
1623
+ },
1624
+ aboutXHours: {
1625
+ one: "about 1 hour",
1626
+ other: "about {{count}} hours"
1627
+ },
1628
+ xHours: {
1629
+ one: "1 hour",
1630
+ other: "{{count}} hours"
1631
+ },
1632
+ xDays: {
1633
+ one: "1 day",
1634
+ other: "{{count}} days"
1635
+ },
1636
+ aboutXWeeks: {
1637
+ one: "about 1 week",
1638
+ other: "about {{count}} weeks"
1639
+ },
1640
+ xWeeks: {
1641
+ one: "1 week",
1642
+ other: "{{count}} weeks"
1643
+ },
1644
+ aboutXMonths: {
1645
+ one: "about 1 month",
1646
+ other: "about {{count}} months"
1647
+ },
1648
+ xMonths: {
1649
+ one: "1 month",
1650
+ other: "{{count}} months"
1651
+ },
1652
+ aboutXYears: {
1653
+ one: "about 1 year",
1654
+ other: "about {{count}} years"
1655
+ },
1656
+ xYears: {
1657
+ one: "1 year",
1658
+ other: "{{count}} years"
1659
+ },
1660
+ overXYears: {
1661
+ one: "over 1 year",
1662
+ other: "over {{count}} years"
1663
+ },
1664
+ almostXYears: {
1665
+ one: "almost 1 year",
1666
+ other: "almost {{count}} years"
1667
+ }
1668
+ };
1669
+ var formatDistance = (token, count, options) => {
1670
+ let result;
1671
+ const tokenValue = formatDistanceLocale[token];
1672
+ if (typeof tokenValue === "string") {
1673
+ result = tokenValue;
1674
+ } else if (count === 1) {
1675
+ result = tokenValue.one;
1676
+ } else {
1677
+ result = tokenValue.other.replace("{{count}}", count.toString());
1678
+ }
1679
+ if (options?.addSuffix) {
1680
+ if (options.comparison && options.comparison > 0) {
1681
+ return "in " + result;
1682
+ } else {
1683
+ return result + " ago";
1684
+ }
1685
+ }
1686
+ return result;
1687
+ };
1688
+
1689
+ // ../../node_modules/date-fns/locale/_lib/buildFormatLongFn.mjs
1690
+ function buildFormatLongFn(args) {
1691
+ return (options = {}) => {
1692
+ const width = options.width ? String(options.width) : args.defaultWidth;
1693
+ const format = args.formats[width] || args.formats[args.defaultWidth];
1694
+ return format;
1695
+ };
1696
+ }
1697
+
1698
+ // ../../node_modules/date-fns/locale/en-US/_lib/formatLong.mjs
1699
+ var dateFormats = {
1700
+ full: "EEEE, MMMM do, y",
1701
+ long: "MMMM do, y",
1702
+ medium: "MMM d, y",
1703
+ short: "MM/dd/yyyy"
1704
+ };
1705
+ var timeFormats = {
1706
+ full: "h:mm:ss a zzzz",
1707
+ long: "h:mm:ss a z",
1708
+ medium: "h:mm:ss a",
1709
+ short: "h:mm a"
1710
+ };
1711
+ var dateTimeFormats = {
1712
+ full: "{{date}} 'at' {{time}}",
1713
+ long: "{{date}} 'at' {{time}}",
1714
+ medium: "{{date}}, {{time}}",
1715
+ short: "{{date}}, {{time}}"
1716
+ };
1717
+ var formatLong = {
1718
+ date: buildFormatLongFn({
1719
+ formats: dateFormats,
1720
+ defaultWidth: "full"
1721
+ }),
1722
+ time: buildFormatLongFn({
1723
+ formats: timeFormats,
1724
+ defaultWidth: "full"
1725
+ }),
1726
+ dateTime: buildFormatLongFn({
1727
+ formats: dateTimeFormats,
1728
+ defaultWidth: "full"
1729
+ })
1730
+ };
1731
+
1732
+ // ../../node_modules/date-fns/locale/en-US/_lib/formatRelative.mjs
1733
+ var formatRelativeLocale = {
1734
+ lastWeek: "'last' eeee 'at' p",
1735
+ yesterday: "'yesterday at' p",
1736
+ today: "'today at' p",
1737
+ tomorrow: "'tomorrow at' p",
1738
+ nextWeek: "eeee 'at' p",
1739
+ other: "P"
1740
+ };
1741
+ var formatRelative = (token, _date, _baseDate, _options) => formatRelativeLocale[token];
1742
+
1743
+ // ../../node_modules/date-fns/locale/_lib/buildLocalizeFn.mjs
1744
+ function buildLocalizeFn(args) {
1745
+ return (value, options) => {
1746
+ const context = options?.context ? String(options.context) : "standalone";
1747
+ let valuesArray;
1748
+ if (context === "formatting" && args.formattingValues) {
1749
+ const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
1750
+ const width = options?.width ? String(options.width) : defaultWidth;
1751
+ valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
1752
+ } else {
1753
+ const defaultWidth = args.defaultWidth;
1754
+ const width = options?.width ? String(options.width) : args.defaultWidth;
1755
+ valuesArray = args.values[width] || args.values[defaultWidth];
1756
+ }
1757
+ const index = args.argumentCallback ? args.argumentCallback(value) : value;
1758
+ return valuesArray[index];
1759
+ };
1760
+ }
1761
+
1762
+ // ../../node_modules/date-fns/locale/en-US/_lib/localize.mjs
1763
+ var eraValues = {
1764
+ narrow: ["B", "A"],
1765
+ abbreviated: ["BC", "AD"],
1766
+ wide: ["Before Christ", "Anno Domini"]
1767
+ };
1768
+ var quarterValues = {
1769
+ narrow: ["1", "2", "3", "4"],
1770
+ abbreviated: ["Q1", "Q2", "Q3", "Q4"],
1771
+ wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
1772
+ };
1773
+ var monthValues = {
1774
+ narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
1775
+ abbreviated: [
1776
+ "Jan",
1777
+ "Feb",
1778
+ "Mar",
1779
+ "Apr",
1780
+ "May",
1781
+ "Jun",
1782
+ "Jul",
1783
+ "Aug",
1784
+ "Sep",
1785
+ "Oct",
1786
+ "Nov",
1787
+ "Dec"
1788
+ ],
1789
+ wide: [
1790
+ "January",
1791
+ "February",
1792
+ "March",
1793
+ "April",
1794
+ "May",
1795
+ "June",
1796
+ "July",
1797
+ "August",
1798
+ "September",
1799
+ "October",
1800
+ "November",
1801
+ "December"
1802
+ ]
1803
+ };
1804
+ var dayValues = {
1805
+ narrow: ["S", "M", "T", "W", "T", "F", "S"],
1806
+ short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
1807
+ abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
1808
+ wide: [
1809
+ "Sunday",
1810
+ "Monday",
1811
+ "Tuesday",
1812
+ "Wednesday",
1813
+ "Thursday",
1814
+ "Friday",
1815
+ "Saturday"
1816
+ ]
1817
+ };
1818
+ var dayPeriodValues = {
1819
+ narrow: {
1820
+ am: "a",
1821
+ pm: "p",
1822
+ midnight: "mi",
1823
+ noon: "n",
1824
+ morning: "morning",
1825
+ afternoon: "afternoon",
1826
+ evening: "evening",
1827
+ night: "night"
1828
+ },
1829
+ abbreviated: {
1830
+ am: "AM",
1831
+ pm: "PM",
1832
+ midnight: "midnight",
1833
+ noon: "noon",
1834
+ morning: "morning",
1835
+ afternoon: "afternoon",
1836
+ evening: "evening",
1837
+ night: "night"
1838
+ },
1839
+ wide: {
1840
+ am: "a.m.",
1841
+ pm: "p.m.",
1842
+ midnight: "midnight",
1843
+ noon: "noon",
1844
+ morning: "morning",
1845
+ afternoon: "afternoon",
1846
+ evening: "evening",
1847
+ night: "night"
1848
+ }
1849
+ };
1850
+ var formattingDayPeriodValues = {
1851
+ narrow: {
1852
+ am: "a",
1853
+ pm: "p",
1854
+ midnight: "mi",
1855
+ noon: "n",
1856
+ morning: "in the morning",
1857
+ afternoon: "in the afternoon",
1858
+ evening: "in the evening",
1859
+ night: "at night"
1860
+ },
1861
+ abbreviated: {
1862
+ am: "AM",
1863
+ pm: "PM",
1864
+ midnight: "midnight",
1865
+ noon: "noon",
1866
+ morning: "in the morning",
1867
+ afternoon: "in the afternoon",
1868
+ evening: "in the evening",
1869
+ night: "at night"
1870
+ },
1871
+ wide: {
1872
+ am: "a.m.",
1873
+ pm: "p.m.",
1874
+ midnight: "midnight",
1875
+ noon: "noon",
1876
+ morning: "in the morning",
1877
+ afternoon: "in the afternoon",
1878
+ evening: "in the evening",
1879
+ night: "at night"
1880
+ }
1881
+ };
1882
+ var ordinalNumber = (dirtyNumber, _options) => {
1883
+ const number = Number(dirtyNumber);
1884
+ const rem100 = number % 100;
1885
+ if (rem100 > 20 || rem100 < 10) {
1886
+ switch (rem100 % 10) {
1887
+ case 1:
1888
+ return number + "st";
1889
+ case 2:
1890
+ return number + "nd";
1891
+ case 3:
1892
+ return number + "rd";
1893
+ }
1894
+ }
1895
+ return number + "th";
1896
+ };
1897
+ var localize = {
1898
+ ordinalNumber,
1899
+ era: buildLocalizeFn({
1900
+ values: eraValues,
1901
+ defaultWidth: "wide"
1902
+ }),
1903
+ quarter: buildLocalizeFn({
1904
+ values: quarterValues,
1905
+ defaultWidth: "wide",
1906
+ argumentCallback: (quarter) => quarter - 1
1907
+ }),
1908
+ month: buildLocalizeFn({
1909
+ values: monthValues,
1910
+ defaultWidth: "wide"
1911
+ }),
1912
+ day: buildLocalizeFn({
1913
+ values: dayValues,
1914
+ defaultWidth: "wide"
1915
+ }),
1916
+ dayPeriod: buildLocalizeFn({
1917
+ values: dayPeriodValues,
1918
+ defaultWidth: "wide",
1919
+ formattingValues: formattingDayPeriodValues,
1920
+ defaultFormattingWidth: "wide"
1921
+ })
1922
+ };
1923
+
1924
+ // ../../node_modules/date-fns/locale/_lib/buildMatchFn.mjs
1925
+ function buildMatchFn(args) {
1926
+ return (string, options = {}) => {
1927
+ const width = options.width;
1928
+ const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
1929
+ const matchResult = string.match(matchPattern);
1930
+ if (!matchResult) {
1931
+ return null;
1932
+ }
1933
+ const matchedString = matchResult[0];
1934
+ const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
1935
+ const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) : (
1936
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type
1937
+ findKey(parsePatterns, (pattern) => pattern.test(matchedString))
1938
+ );
1939
+ let value;
1940
+ value = args.valueCallback ? args.valueCallback(key) : key;
1941
+ value = options.valueCallback ? (
1942
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type
1943
+ options.valueCallback(value)
1944
+ ) : value;
1945
+ const rest = string.slice(matchedString.length);
1946
+ return { value, rest };
1947
+ };
1948
+ }
1949
+ function findKey(object, predicate) {
1950
+ for (const key in object) {
1951
+ if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
1952
+ return key;
1953
+ }
1954
+ }
1955
+ return void 0;
1956
+ }
1957
+ function findIndex(array, predicate) {
1958
+ for (let key = 0; key < array.length; key++) {
1959
+ if (predicate(array[key])) {
1960
+ return key;
1961
+ }
1962
+ }
1963
+ return void 0;
1964
+ }
1965
+
1966
+ // ../../node_modules/date-fns/locale/_lib/buildMatchPatternFn.mjs
1967
+ function buildMatchPatternFn(args) {
1968
+ return (string, options = {}) => {
1969
+ const matchResult = string.match(args.matchPattern);
1970
+ if (!matchResult) return null;
1971
+ const matchedString = matchResult[0];
1972
+ const parseResult = string.match(args.parsePattern);
1973
+ if (!parseResult) return null;
1974
+ let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
1975
+ value = options.valueCallback ? options.valueCallback(value) : value;
1976
+ const rest = string.slice(matchedString.length);
1977
+ return { value, rest };
1978
+ };
1979
+ }
1980
+
1981
+ // ../../node_modules/date-fns/locale/en-US/_lib/match.mjs
1982
+ var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
1983
+ var parseOrdinalNumberPattern = /\d+/i;
1984
+ var matchEraPatterns = {
1985
+ narrow: /^(b|a)/i,
1986
+ abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
1987
+ wide: /^(before christ|before common era|anno domini|common era)/i
1988
+ };
1989
+ var parseEraPatterns = {
1990
+ any: [/^b/i, /^(a|c)/i]
1991
+ };
1992
+ var matchQuarterPatterns = {
1993
+ narrow: /^[1234]/i,
1994
+ abbreviated: /^q[1234]/i,
1995
+ wide: /^[1234](th|st|nd|rd)? quarter/i
1996
+ };
1997
+ var parseQuarterPatterns = {
1998
+ any: [/1/i, /2/i, /3/i, /4/i]
1999
+ };
2000
+ var matchMonthPatterns = {
2001
+ narrow: /^[jfmasond]/i,
2002
+ abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
2003
+ wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
2004
+ };
2005
+ var parseMonthPatterns = {
2006
+ narrow: [
2007
+ /^j/i,
2008
+ /^f/i,
2009
+ /^m/i,
2010
+ /^a/i,
2011
+ /^m/i,
2012
+ /^j/i,
2013
+ /^j/i,
2014
+ /^a/i,
2015
+ /^s/i,
2016
+ /^o/i,
2017
+ /^n/i,
2018
+ /^d/i
2019
+ ],
2020
+ any: [
2021
+ /^ja/i,
2022
+ /^f/i,
2023
+ /^mar/i,
2024
+ /^ap/i,
2025
+ /^may/i,
2026
+ /^jun/i,
2027
+ /^jul/i,
2028
+ /^au/i,
2029
+ /^s/i,
2030
+ /^o/i,
2031
+ /^n/i,
2032
+ /^d/i
2033
+ ]
2034
+ };
2035
+ var matchDayPatterns = {
2036
+ narrow: /^[smtwf]/i,
2037
+ short: /^(su|mo|tu|we|th|fr|sa)/i,
2038
+ abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
2039
+ wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
2040
+ };
2041
+ var parseDayPatterns = {
2042
+ narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
2043
+ any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
2044
+ };
2045
+ var matchDayPeriodPatterns = {
2046
+ narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
2047
+ any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
2048
+ };
2049
+ var parseDayPeriodPatterns = {
2050
+ any: {
2051
+ am: /^a/i,
2052
+ pm: /^p/i,
2053
+ midnight: /^mi/i,
2054
+ noon: /^no/i,
2055
+ morning: /morning/i,
2056
+ afternoon: /afternoon/i,
2057
+ evening: /evening/i,
2058
+ night: /night/i
2059
+ }
2060
+ };
2061
+ var match = {
2062
+ ordinalNumber: buildMatchPatternFn({
2063
+ matchPattern: matchOrdinalNumberPattern,
2064
+ parsePattern: parseOrdinalNumberPattern,
2065
+ valueCallback: (value) => parseInt(value, 10)
2066
+ }),
2067
+ era: buildMatchFn({
2068
+ matchPatterns: matchEraPatterns,
2069
+ defaultMatchWidth: "wide",
2070
+ parsePatterns: parseEraPatterns,
2071
+ defaultParseWidth: "any"
2072
+ }),
2073
+ quarter: buildMatchFn({
2074
+ matchPatterns: matchQuarterPatterns,
2075
+ defaultMatchWidth: "wide",
2076
+ parsePatterns: parseQuarterPatterns,
2077
+ defaultParseWidth: "any",
2078
+ valueCallback: (index) => index + 1
2079
+ }),
2080
+ month: buildMatchFn({
2081
+ matchPatterns: matchMonthPatterns,
2082
+ defaultMatchWidth: "wide",
2083
+ parsePatterns: parseMonthPatterns,
2084
+ defaultParseWidth: "any"
2085
+ }),
2086
+ day: buildMatchFn({
2087
+ matchPatterns: matchDayPatterns,
2088
+ defaultMatchWidth: "wide",
2089
+ parsePatterns: parseDayPatterns,
2090
+ defaultParseWidth: "any"
2091
+ }),
2092
+ dayPeriod: buildMatchFn({
2093
+ matchPatterns: matchDayPeriodPatterns,
2094
+ defaultMatchWidth: "any",
2095
+ parsePatterns: parseDayPeriodPatterns,
2096
+ defaultParseWidth: "any"
2097
+ })
2098
+ };
2099
+
2100
+ // ../../node_modules/date-fns/locale/en-US.mjs
2101
+ var enUS = {
2102
+ code: "en-US",
2103
+ formatDistance,
2104
+ formatLong,
2105
+ formatRelative,
2106
+ localize,
2107
+ match,
2108
+ options: {
2109
+ weekStartsOn: 0,
2110
+ firstWeekContainsDate: 1
2111
+ }
2112
+ };
2113
+
2114
+ // ../../node_modules/date-fns/getISOWeek.mjs
2115
+ function getISOWeek(date) {
2116
+ const _date = toDate(date);
2117
+ const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
2118
+ return Math.round(diff / millisecondsInWeek) + 1;
2119
+ }
2120
+
2121
+ // ../../node_modules/date-fns/getWeekYear.mjs
2122
+ function getWeekYear(date, options) {
2123
+ const _date = toDate(date);
2124
+ const year = _date.getFullYear();
2125
+ const defaultOptions2 = getDefaultOptions();
2126
+ const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
2127
+ const firstWeekOfNextYear = constructFrom(date, 0);
2128
+ firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
2129
+ firstWeekOfNextYear.setHours(0, 0, 0, 0);
2130
+ const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
2131
+ const firstWeekOfThisYear = constructFrom(date, 0);
2132
+ firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
2133
+ firstWeekOfThisYear.setHours(0, 0, 0, 0);
2134
+ const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
2135
+ if (_date.getTime() >= startOfNextYear.getTime()) {
2136
+ return year + 1;
2137
+ } else if (_date.getTime() >= startOfThisYear.getTime()) {
2138
+ return year;
2139
+ } else {
2140
+ return year - 1;
2141
+ }
2142
+ }
2143
+
2144
+ // ../../node_modules/date-fns/startOfWeekYear.mjs
2145
+ function startOfWeekYear(date, options) {
2146
+ const defaultOptions2 = getDefaultOptions();
2147
+ const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
2148
+ const year = getWeekYear(date, options);
2149
+ const firstWeek = constructFrom(date, 0);
2150
+ firstWeek.setFullYear(year, 0, firstWeekContainsDate);
2151
+ firstWeek.setHours(0, 0, 0, 0);
2152
+ const _date = startOfWeek(firstWeek, options);
2153
+ return _date;
2154
+ }
2155
+
2156
+ // ../../node_modules/date-fns/getWeek.mjs
2157
+ function getWeek(date, options) {
2158
+ const _date = toDate(date);
2159
+ const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
2160
+ return Math.round(diff / millisecondsInWeek) + 1;
2161
+ }
2162
+
2163
+ // ../../node_modules/date-fns/_lib/format/longFormatters.mjs
2164
+ var dateLongFormatter = (pattern, formatLong2) => {
2165
+ switch (pattern) {
2166
+ case "P":
2167
+ return formatLong2.date({ width: "short" });
2168
+ case "PP":
2169
+ return formatLong2.date({ width: "medium" });
2170
+ case "PPP":
2171
+ return formatLong2.date({ width: "long" });
2172
+ case "PPPP":
2173
+ default:
2174
+ return formatLong2.date({ width: "full" });
2175
+ }
2176
+ };
2177
+ var timeLongFormatter = (pattern, formatLong2) => {
2178
+ switch (pattern) {
2179
+ case "p":
2180
+ return formatLong2.time({ width: "short" });
2181
+ case "pp":
2182
+ return formatLong2.time({ width: "medium" });
2183
+ case "ppp":
2184
+ return formatLong2.time({ width: "long" });
2185
+ case "pppp":
2186
+ default:
2187
+ return formatLong2.time({ width: "full" });
2188
+ }
2189
+ };
2190
+ var dateTimeLongFormatter = (pattern, formatLong2) => {
2191
+ const matchResult = pattern.match(/(P+)(p+)?/) || [];
2192
+ const datePattern = matchResult[1];
2193
+ const timePattern = matchResult[2];
2194
+ if (!timePattern) {
2195
+ return dateLongFormatter(pattern, formatLong2);
2196
+ }
2197
+ let dateTimeFormat;
2198
+ switch (datePattern) {
2199
+ case "P":
2200
+ dateTimeFormat = formatLong2.dateTime({ width: "short" });
2201
+ break;
2202
+ case "PP":
2203
+ dateTimeFormat = formatLong2.dateTime({ width: "medium" });
2204
+ break;
2205
+ case "PPP":
2206
+ dateTimeFormat = formatLong2.dateTime({ width: "long" });
2207
+ break;
2208
+ case "PPPP":
2209
+ default:
2210
+ dateTimeFormat = formatLong2.dateTime({ width: "full" });
2211
+ break;
2212
+ }
2213
+ return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong2)).replace("{{time}}", timeLongFormatter(timePattern, formatLong2));
2214
+ };
2215
+ var longFormatters = {
2216
+ p: timeLongFormatter,
2217
+ P: dateTimeLongFormatter
2218
+ };
2219
+
2220
+ // ../../node_modules/date-fns/_lib/protectedTokens.mjs
2221
+ var dayOfYearTokenRE = /^D+$/;
2222
+ var weekYearTokenRE = /^Y+$/;
2223
+ var throwTokens = ["D", "DD", "YY", "YYYY"];
2224
+ function isProtectedDayOfYearToken(token) {
2225
+ return dayOfYearTokenRE.test(token);
2226
+ }
2227
+ function isProtectedWeekYearToken(token) {
2228
+ return weekYearTokenRE.test(token);
2229
+ }
2230
+ function warnOrThrowProtectedError(token, format, input) {
2231
+ const _message = message(token, format, input);
2232
+ console.warn(_message);
2233
+ if (throwTokens.includes(token)) throw new RangeError(_message);
2234
+ }
2235
+ function message(token, format, input) {
2236
+ const subject = token[0] === "Y" ? "years" : "days of the month";
2237
+ return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
2238
+ }
2239
+
2240
+ // ../../node_modules/date-fns/getDefaultOptions.mjs
2241
+ function getDefaultOptions2() {
2242
+ return Object.assign({}, getDefaultOptions());
2243
+ }
2244
+
2245
+ // ../../node_modules/date-fns/getISODay.mjs
2246
+ function getISODay(date) {
2247
+ const _date = toDate(date);
2248
+ let day = _date.getDay();
2249
+ if (day === 0) {
2250
+ day = 7;
2251
+ }
2252
+ return day;
2253
+ }
2254
+
2255
+ // ../../node_modules/date-fns/isAfter.mjs
2256
+ function isAfter(date, dateToCompare) {
2257
+ const _date = toDate(date);
2258
+ const _dateToCompare = toDate(dateToCompare);
2259
+ return _date.getTime() > _dateToCompare.getTime();
2260
+ }
2261
+
2262
+ // ../../node_modules/date-fns/isBefore.mjs
2263
+ function isBefore(date, dateToCompare) {
2264
+ const _date = toDate(date);
2265
+ const _dateToCompare = toDate(dateToCompare);
2266
+ return +_date < +_dateToCompare;
2267
+ }
2268
+
2269
+ // ../../node_modules/date-fns/transpose.mjs
2270
+ function transpose(fromDate, constructor) {
2271
+ const date = constructor instanceof Date ? constructFrom(constructor, 0) : new constructor(0);
2272
+ date.setFullYear(
2273
+ fromDate.getFullYear(),
2274
+ fromDate.getMonth(),
2275
+ fromDate.getDate()
2276
+ );
2277
+ date.setHours(
2278
+ fromDate.getHours(),
2279
+ fromDate.getMinutes(),
2280
+ fromDate.getSeconds(),
2281
+ fromDate.getMilliseconds()
2282
+ );
2283
+ return date;
2284
+ }
2285
+
2286
+ // ../../node_modules/date-fns/parse/_lib/Setter.mjs
2287
+ var TIMEZONE_UNIT_PRIORITY = 10;
2288
+ var Setter = class {
2289
+ constructor() {
2290
+ __publicField(this, "subPriority", 0);
2291
+ }
2292
+ validate(_utcDate, _options) {
2293
+ return true;
2294
+ }
2295
+ };
2296
+ var ValueSetter = class extends Setter {
2297
+ constructor(value, validateValue, setValue, priority, subPriority) {
2298
+ super();
2299
+ this.value = value;
2300
+ this.validateValue = validateValue;
2301
+ this.setValue = setValue;
2302
+ this.priority = priority;
2303
+ if (subPriority) {
2304
+ this.subPriority = subPriority;
2305
+ }
2306
+ }
2307
+ validate(date, options) {
2308
+ return this.validateValue(date, this.value, options);
2309
+ }
2310
+ set(date, flags, options) {
2311
+ return this.setValue(date, flags, this.value, options);
2312
+ }
2313
+ };
2314
+ var DateToSystemTimezoneSetter = class extends Setter {
2315
+ constructor() {
2316
+ super(...arguments);
2317
+ __publicField(this, "priority", TIMEZONE_UNIT_PRIORITY);
2318
+ __publicField(this, "subPriority", -1);
2319
+ }
2320
+ set(date, flags) {
2321
+ if (flags.timestampIsSet) return date;
2322
+ return constructFrom(date, transpose(date, Date));
2323
+ }
2324
+ };
2325
+
2326
+ // ../../node_modules/date-fns/parse/_lib/Parser.mjs
2327
+ var Parser = class {
2328
+ run(dateString, token, match2, options) {
2329
+ const result = this.parse(dateString, token, match2, options);
2330
+ if (!result) {
2331
+ return null;
2332
+ }
2333
+ return {
2334
+ setter: new ValueSetter(
2335
+ result.value,
2336
+ this.validate,
2337
+ this.set,
2338
+ this.priority,
2339
+ this.subPriority
2340
+ ),
2341
+ rest: result.rest
2342
+ };
2343
+ }
2344
+ validate(_utcDate, _value, _options) {
2345
+ return true;
2346
+ }
2347
+ };
2348
+
2349
+ // ../../node_modules/date-fns/parse/_lib/parsers/EraParser.mjs
2350
+ var EraParser = class extends Parser {
2351
+ constructor() {
2352
+ super(...arguments);
2353
+ __publicField(this, "priority", 140);
2354
+ __publicField(this, "incompatibleTokens", ["R", "u", "t", "T"]);
2355
+ }
2356
+ parse(dateString, token, match2) {
2357
+ switch (token) {
2358
+ // AD, BC
2359
+ case "G":
2360
+ case "GG":
2361
+ case "GGG":
2362
+ return match2.era(dateString, { width: "abbreviated" }) || match2.era(dateString, { width: "narrow" });
2363
+ // A, B
2364
+ case "GGGGG":
2365
+ return match2.era(dateString, { width: "narrow" });
2366
+ // Anno Domini, Before Christ
2367
+ case "GGGG":
2368
+ default:
2369
+ return match2.era(dateString, { width: "wide" }) || match2.era(dateString, { width: "abbreviated" }) || match2.era(dateString, { width: "narrow" });
2370
+ }
2371
+ }
2372
+ set(date, flags, value) {
2373
+ flags.era = value;
2374
+ date.setFullYear(value, 0, 1);
2375
+ date.setHours(0, 0, 0, 0);
2376
+ return date;
2377
+ }
2378
+ };
2379
+
2380
+ // ../../node_modules/date-fns/parse/_lib/constants.mjs
2381
+ var numericPatterns = {
2382
+ month: /^(1[0-2]|0?\d)/,
2383
+ // 0 to 12
2384
+ date: /^(3[0-1]|[0-2]?\d)/,
2385
+ // 0 to 31
2386
+ dayOfYear: /^(36[0-6]|3[0-5]\d|[0-2]?\d?\d)/,
2387
+ // 0 to 366
2388
+ week: /^(5[0-3]|[0-4]?\d)/,
2389
+ // 0 to 53
2390
+ hour23h: /^(2[0-3]|[0-1]?\d)/,
2391
+ // 0 to 23
2392
+ hour24h: /^(2[0-4]|[0-1]?\d)/,
2393
+ // 0 to 24
2394
+ hour11h: /^(1[0-1]|0?\d)/,
2395
+ // 0 to 11
2396
+ hour12h: /^(1[0-2]|0?\d)/,
2397
+ // 0 to 12
2398
+ minute: /^[0-5]?\d/,
2399
+ // 0 to 59
2400
+ second: /^[0-5]?\d/,
2401
+ // 0 to 59
2402
+ singleDigit: /^\d/,
2403
+ // 0 to 9
2404
+ twoDigits: /^\d{1,2}/,
2405
+ // 0 to 99
2406
+ threeDigits: /^\d{1,3}/,
2407
+ // 0 to 999
2408
+ fourDigits: /^\d{1,4}/,
2409
+ // 0 to 9999
2410
+ anyDigitsSigned: /^-?\d+/,
2411
+ singleDigitSigned: /^-?\d/,
2412
+ // 0 to 9, -0 to -9
2413
+ twoDigitsSigned: /^-?\d{1,2}/,
2414
+ // 0 to 99, -0 to -99
2415
+ threeDigitsSigned: /^-?\d{1,3}/,
2416
+ // 0 to 999, -0 to -999
2417
+ fourDigitsSigned: /^-?\d{1,4}/
2418
+ // 0 to 9999, -0 to -9999
2419
+ };
2420
+ var timezonePatterns = {
2421
+ basicOptionalMinutes: /^([+-])(\d{2})(\d{2})?|Z/,
2422
+ basic: /^([+-])(\d{2})(\d{2})|Z/,
2423
+ basicOptionalSeconds: /^([+-])(\d{2})(\d{2})((\d{2}))?|Z/,
2424
+ extended: /^([+-])(\d{2}):(\d{2})|Z/,
2425
+ extendedOptionalSeconds: /^([+-])(\d{2}):(\d{2})(:(\d{2}))?|Z/
2426
+ };
2427
+
2428
+ // ../../node_modules/date-fns/parse/_lib/utils.mjs
2429
+ function mapValue(parseFnResult, mapFn) {
2430
+ if (!parseFnResult) {
2431
+ return parseFnResult;
2432
+ }
2433
+ return {
2434
+ value: mapFn(parseFnResult.value),
2435
+ rest: parseFnResult.rest
2436
+ };
2437
+ }
2438
+ function parseNumericPattern(pattern, dateString) {
2439
+ const matchResult = dateString.match(pattern);
2440
+ if (!matchResult) {
2441
+ return null;
2442
+ }
2443
+ return {
2444
+ value: parseInt(matchResult[0], 10),
2445
+ rest: dateString.slice(matchResult[0].length)
2446
+ };
2447
+ }
2448
+ function parseTimezonePattern(pattern, dateString) {
2449
+ const matchResult = dateString.match(pattern);
2450
+ if (!matchResult) {
2451
+ return null;
2452
+ }
2453
+ if (matchResult[0] === "Z") {
2454
+ return {
2455
+ value: 0,
2456
+ rest: dateString.slice(1)
2457
+ };
2458
+ }
2459
+ const sign = matchResult[1] === "+" ? 1 : -1;
2460
+ const hours = matchResult[2] ? parseInt(matchResult[2], 10) : 0;
2461
+ const minutes = matchResult[3] ? parseInt(matchResult[3], 10) : 0;
2462
+ const seconds = matchResult[5] ? parseInt(matchResult[5], 10) : 0;
2463
+ return {
2464
+ value: sign * (hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * millisecondsInSecond),
2465
+ rest: dateString.slice(matchResult[0].length)
2466
+ };
2467
+ }
2468
+ function parseAnyDigitsSigned(dateString) {
2469
+ return parseNumericPattern(numericPatterns.anyDigitsSigned, dateString);
2470
+ }
2471
+ function parseNDigits(n, dateString) {
2472
+ switch (n) {
2473
+ case 1:
2474
+ return parseNumericPattern(numericPatterns.singleDigit, dateString);
2475
+ case 2:
2476
+ return parseNumericPattern(numericPatterns.twoDigits, dateString);
2477
+ case 3:
2478
+ return parseNumericPattern(numericPatterns.threeDigits, dateString);
2479
+ case 4:
2480
+ return parseNumericPattern(numericPatterns.fourDigits, dateString);
2481
+ default:
2482
+ return parseNumericPattern(new RegExp("^\\d{1," + n + "}"), dateString);
2483
+ }
2484
+ }
2485
+ function parseNDigitsSigned(n, dateString) {
2486
+ switch (n) {
2487
+ case 1:
2488
+ return parseNumericPattern(numericPatterns.singleDigitSigned, dateString);
2489
+ case 2:
2490
+ return parseNumericPattern(numericPatterns.twoDigitsSigned, dateString);
2491
+ case 3:
2492
+ return parseNumericPattern(numericPatterns.threeDigitsSigned, dateString);
2493
+ case 4:
2494
+ return parseNumericPattern(numericPatterns.fourDigitsSigned, dateString);
2495
+ default:
2496
+ return parseNumericPattern(new RegExp("^-?\\d{1," + n + "}"), dateString);
2497
+ }
2498
+ }
2499
+ function dayPeriodEnumToHours(dayPeriod) {
2500
+ switch (dayPeriod) {
2501
+ case "morning":
2502
+ return 4;
2503
+ case "evening":
2504
+ return 17;
2505
+ case "pm":
2506
+ case "noon":
2507
+ case "afternoon":
2508
+ return 12;
2509
+ case "am":
2510
+ case "midnight":
2511
+ case "night":
2512
+ default:
2513
+ return 0;
2514
+ }
2515
+ }
2516
+ function normalizeTwoDigitYear(twoDigitYear, currentYear) {
2517
+ const isCommonEra = currentYear > 0;
2518
+ const absCurrentYear = isCommonEra ? currentYear : 1 - currentYear;
2519
+ let result;
2520
+ if (absCurrentYear <= 50) {
2521
+ result = twoDigitYear || 100;
2522
+ } else {
2523
+ const rangeEnd = absCurrentYear + 50;
2524
+ const rangeEndCentury = Math.trunc(rangeEnd / 100) * 100;
2525
+ const isPreviousCentury = twoDigitYear >= rangeEnd % 100;
2526
+ result = twoDigitYear + rangeEndCentury - (isPreviousCentury ? 100 : 0);
2527
+ }
2528
+ return isCommonEra ? result : 1 - result;
2529
+ }
2530
+ function isLeapYearIndex(year) {
2531
+ return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
2532
+ }
2533
+
2534
+ // ../../node_modules/date-fns/parse/_lib/parsers/YearParser.mjs
2535
+ var YearParser = class extends Parser {
2536
+ constructor() {
2537
+ super(...arguments);
2538
+ __publicField(this, "priority", 130);
2539
+ __publicField(this, "incompatibleTokens", ["Y", "R", "u", "w", "I", "i", "e", "c", "t", "T"]);
2540
+ }
2541
+ parse(dateString, token, match2) {
2542
+ const valueCallback = (year) => ({
2543
+ year,
2544
+ isTwoDigitYear: token === "yy"
2545
+ });
2546
+ switch (token) {
2547
+ case "y":
2548
+ return mapValue(parseNDigits(4, dateString), valueCallback);
2549
+ case "yo":
2550
+ return mapValue(
2551
+ match2.ordinalNumber(dateString, {
2552
+ unit: "year"
2553
+ }),
2554
+ valueCallback
2555
+ );
2556
+ default:
2557
+ return mapValue(parseNDigits(token.length, dateString), valueCallback);
2558
+ }
2559
+ }
2560
+ validate(_date, value) {
2561
+ return value.isTwoDigitYear || value.year > 0;
2562
+ }
2563
+ set(date, flags, value) {
2564
+ const currentYear = date.getFullYear();
2565
+ if (value.isTwoDigitYear) {
2566
+ const normalizedTwoDigitYear = normalizeTwoDigitYear(
2567
+ value.year,
2568
+ currentYear
2569
+ );
2570
+ date.setFullYear(normalizedTwoDigitYear, 0, 1);
2571
+ date.setHours(0, 0, 0, 0);
2572
+ return date;
2573
+ }
2574
+ const year = !("era" in flags) || flags.era === 1 ? value.year : 1 - value.year;
2575
+ date.setFullYear(year, 0, 1);
2576
+ date.setHours(0, 0, 0, 0);
2577
+ return date;
2578
+ }
2579
+ };
2580
+
2581
+ // ../../node_modules/date-fns/parse/_lib/parsers/LocalWeekYearParser.mjs
2582
+ var LocalWeekYearParser = class extends Parser {
2583
+ constructor() {
2584
+ super(...arguments);
2585
+ __publicField(this, "priority", 130);
2586
+ __publicField(this, "incompatibleTokens", [
2587
+ "y",
2588
+ "R",
2589
+ "u",
2590
+ "Q",
2591
+ "q",
2592
+ "M",
2593
+ "L",
2594
+ "I",
2595
+ "d",
2596
+ "D",
2597
+ "i",
2598
+ "t",
2599
+ "T"
2600
+ ]);
2601
+ }
2602
+ parse(dateString, token, match2) {
2603
+ const valueCallback = (year) => ({
2604
+ year,
2605
+ isTwoDigitYear: token === "YY"
2606
+ });
2607
+ switch (token) {
2608
+ case "Y":
2609
+ return mapValue(parseNDigits(4, dateString), valueCallback);
2610
+ case "Yo":
2611
+ return mapValue(
2612
+ match2.ordinalNumber(dateString, {
2613
+ unit: "year"
2614
+ }),
2615
+ valueCallback
2616
+ );
2617
+ default:
2618
+ return mapValue(parseNDigits(token.length, dateString), valueCallback);
2619
+ }
2620
+ }
2621
+ validate(_date, value) {
2622
+ return value.isTwoDigitYear || value.year > 0;
2623
+ }
2624
+ set(date, flags, value, options) {
2625
+ const currentYear = getWeekYear(date, options);
2626
+ if (value.isTwoDigitYear) {
2627
+ const normalizedTwoDigitYear = normalizeTwoDigitYear(
2628
+ value.year,
2629
+ currentYear
2630
+ );
2631
+ date.setFullYear(
2632
+ normalizedTwoDigitYear,
2633
+ 0,
2634
+ options.firstWeekContainsDate
2635
+ );
2636
+ date.setHours(0, 0, 0, 0);
2637
+ return startOfWeek(date, options);
2638
+ }
2639
+ const year = !("era" in flags) || flags.era === 1 ? value.year : 1 - value.year;
2640
+ date.setFullYear(year, 0, options.firstWeekContainsDate);
2641
+ date.setHours(0, 0, 0, 0);
2642
+ return startOfWeek(date, options);
2643
+ }
2644
+ };
2645
+
2646
+ // ../../node_modules/date-fns/parse/_lib/parsers/ISOWeekYearParser.mjs
2647
+ var ISOWeekYearParser = class extends Parser {
2648
+ constructor() {
2649
+ super(...arguments);
2650
+ __publicField(this, "priority", 130);
2651
+ __publicField(this, "incompatibleTokens", [
2652
+ "G",
2653
+ "y",
2654
+ "Y",
2655
+ "u",
2656
+ "Q",
2657
+ "q",
2658
+ "M",
2659
+ "L",
2660
+ "w",
2661
+ "d",
2662
+ "D",
2663
+ "e",
2664
+ "c",
2665
+ "t",
2666
+ "T"
2667
+ ]);
2668
+ }
2669
+ parse(dateString, token) {
2670
+ if (token === "R") {
2671
+ return parseNDigitsSigned(4, dateString);
2672
+ }
2673
+ return parseNDigitsSigned(token.length, dateString);
2674
+ }
2675
+ set(date, _flags, value) {
2676
+ const firstWeekOfYear = constructFrom(date, 0);
2677
+ firstWeekOfYear.setFullYear(value, 0, 4);
2678
+ firstWeekOfYear.setHours(0, 0, 0, 0);
2679
+ return startOfISOWeek(firstWeekOfYear);
2680
+ }
2681
+ };
2682
+
2683
+ // ../../node_modules/date-fns/parse/_lib/parsers/ExtendedYearParser.mjs
2684
+ var ExtendedYearParser = class extends Parser {
2685
+ constructor() {
2686
+ super(...arguments);
2687
+ __publicField(this, "priority", 130);
2688
+ __publicField(this, "incompatibleTokens", ["G", "y", "Y", "R", "w", "I", "i", "e", "c", "t", "T"]);
2689
+ }
2690
+ parse(dateString, token) {
2691
+ if (token === "u") {
2692
+ return parseNDigitsSigned(4, dateString);
2693
+ }
2694
+ return parseNDigitsSigned(token.length, dateString);
2695
+ }
2696
+ set(date, _flags, value) {
2697
+ date.setFullYear(value, 0, 1);
2698
+ date.setHours(0, 0, 0, 0);
2699
+ return date;
2700
+ }
2701
+ };
2702
+
2703
+ // ../../node_modules/date-fns/parse/_lib/parsers/QuarterParser.mjs
2704
+ var QuarterParser = class extends Parser {
2705
+ constructor() {
2706
+ super(...arguments);
2707
+ __publicField(this, "priority", 120);
2708
+ __publicField(this, "incompatibleTokens", [
2709
+ "Y",
2710
+ "R",
2711
+ "q",
2712
+ "M",
2713
+ "L",
2714
+ "w",
2715
+ "I",
2716
+ "d",
2717
+ "D",
2718
+ "i",
2719
+ "e",
2720
+ "c",
2721
+ "t",
2722
+ "T"
2723
+ ]);
2724
+ }
2725
+ parse(dateString, token, match2) {
2726
+ switch (token) {
2727
+ // 1, 2, 3, 4
2728
+ case "Q":
2729
+ case "QQ":
2730
+ return parseNDigits(token.length, dateString);
2731
+ // 1st, 2nd, 3rd, 4th
2732
+ case "Qo":
2733
+ return match2.ordinalNumber(dateString, { unit: "quarter" });
2734
+ // Q1, Q2, Q3, Q4
2735
+ case "QQQ":
2736
+ return match2.quarter(dateString, {
2737
+ width: "abbreviated",
2738
+ context: "formatting"
2739
+ }) || match2.quarter(dateString, {
2740
+ width: "narrow",
2741
+ context: "formatting"
2742
+ });
2743
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
2744
+ case "QQQQQ":
2745
+ return match2.quarter(dateString, {
2746
+ width: "narrow",
2747
+ context: "formatting"
2748
+ });
2749
+ // 1st quarter, 2nd quarter, ...
2750
+ case "QQQQ":
2751
+ default:
2752
+ return match2.quarter(dateString, {
2753
+ width: "wide",
2754
+ context: "formatting"
2755
+ }) || match2.quarter(dateString, {
2756
+ width: "abbreviated",
2757
+ context: "formatting"
2758
+ }) || match2.quarter(dateString, {
2759
+ width: "narrow",
2760
+ context: "formatting"
2761
+ });
2762
+ }
2763
+ }
2764
+ validate(_date, value) {
2765
+ return value >= 1 && value <= 4;
2766
+ }
2767
+ set(date, _flags, value) {
2768
+ date.setMonth((value - 1) * 3, 1);
2769
+ date.setHours(0, 0, 0, 0);
2770
+ return date;
2771
+ }
2772
+ };
2773
+
2774
+ // ../../node_modules/date-fns/parse/_lib/parsers/StandAloneQuarterParser.mjs
2775
+ var StandAloneQuarterParser = class extends Parser {
2776
+ constructor() {
2777
+ super(...arguments);
2778
+ __publicField(this, "priority", 120);
2779
+ __publicField(this, "incompatibleTokens", [
2780
+ "Y",
2781
+ "R",
2782
+ "Q",
2783
+ "M",
2784
+ "L",
2785
+ "w",
2786
+ "I",
2787
+ "d",
2788
+ "D",
2789
+ "i",
2790
+ "e",
2791
+ "c",
2792
+ "t",
2793
+ "T"
2794
+ ]);
2795
+ }
2796
+ parse(dateString, token, match2) {
2797
+ switch (token) {
2798
+ // 1, 2, 3, 4
2799
+ case "q":
2800
+ case "qq":
2801
+ return parseNDigits(token.length, dateString);
2802
+ // 1st, 2nd, 3rd, 4th
2803
+ case "qo":
2804
+ return match2.ordinalNumber(dateString, { unit: "quarter" });
2805
+ // Q1, Q2, Q3, Q4
2806
+ case "qqq":
2807
+ return match2.quarter(dateString, {
2808
+ width: "abbreviated",
2809
+ context: "standalone"
2810
+ }) || match2.quarter(dateString, {
2811
+ width: "narrow",
2812
+ context: "standalone"
2813
+ });
2814
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
2815
+ case "qqqqq":
2816
+ return match2.quarter(dateString, {
2817
+ width: "narrow",
2818
+ context: "standalone"
2819
+ });
2820
+ // 1st quarter, 2nd quarter, ...
2821
+ case "qqqq":
2822
+ default:
2823
+ return match2.quarter(dateString, {
2824
+ width: "wide",
2825
+ context: "standalone"
2826
+ }) || match2.quarter(dateString, {
2827
+ width: "abbreviated",
2828
+ context: "standalone"
2829
+ }) || match2.quarter(dateString, {
2830
+ width: "narrow",
2831
+ context: "standalone"
2832
+ });
2833
+ }
2834
+ }
2835
+ validate(_date, value) {
2836
+ return value >= 1 && value <= 4;
2837
+ }
2838
+ set(date, _flags, value) {
2839
+ date.setMonth((value - 1) * 3, 1);
2840
+ date.setHours(0, 0, 0, 0);
2841
+ return date;
2842
+ }
2843
+ };
2844
+
2845
+ // ../../node_modules/date-fns/parse/_lib/parsers/MonthParser.mjs
2846
+ var MonthParser = class extends Parser {
2847
+ constructor() {
2848
+ super(...arguments);
2849
+ __publicField(this, "incompatibleTokens", [
2850
+ "Y",
2851
+ "R",
2852
+ "q",
2853
+ "Q",
2854
+ "L",
2855
+ "w",
2856
+ "I",
2857
+ "D",
2858
+ "i",
2859
+ "e",
2860
+ "c",
2861
+ "t",
2862
+ "T"
2863
+ ]);
2864
+ __publicField(this, "priority", 110);
2865
+ }
2866
+ parse(dateString, token, match2) {
2867
+ const valueCallback = (value) => value - 1;
2868
+ switch (token) {
2869
+ // 1, 2, ..., 12
2870
+ case "M":
2871
+ return mapValue(
2872
+ parseNumericPattern(numericPatterns.month, dateString),
2873
+ valueCallback
2874
+ );
2875
+ // 01, 02, ..., 12
2876
+ case "MM":
2877
+ return mapValue(parseNDigits(2, dateString), valueCallback);
2878
+ // 1st, 2nd, ..., 12th
2879
+ case "Mo":
2880
+ return mapValue(
2881
+ match2.ordinalNumber(dateString, {
2882
+ unit: "month"
2883
+ }),
2884
+ valueCallback
2885
+ );
2886
+ // Jan, Feb, ..., Dec
2887
+ case "MMM":
2888
+ return match2.month(dateString, {
2889
+ width: "abbreviated",
2890
+ context: "formatting"
2891
+ }) || match2.month(dateString, { width: "narrow", context: "formatting" });
2892
+ // J, F, ..., D
2893
+ case "MMMMM":
2894
+ return match2.month(dateString, {
2895
+ width: "narrow",
2896
+ context: "formatting"
2897
+ });
2898
+ // January, February, ..., December
2899
+ case "MMMM":
2900
+ default:
2901
+ return match2.month(dateString, { width: "wide", context: "formatting" }) || match2.month(dateString, {
2902
+ width: "abbreviated",
2903
+ context: "formatting"
2904
+ }) || match2.month(dateString, { width: "narrow", context: "formatting" });
2905
+ }
2906
+ }
2907
+ validate(_date, value) {
2908
+ return value >= 0 && value <= 11;
2909
+ }
2910
+ set(date, _flags, value) {
2911
+ date.setMonth(value, 1);
2912
+ date.setHours(0, 0, 0, 0);
2913
+ return date;
2914
+ }
2915
+ };
2916
+
2917
+ // ../../node_modules/date-fns/parse/_lib/parsers/StandAloneMonthParser.mjs
2918
+ var StandAloneMonthParser = class extends Parser {
2919
+ constructor() {
2920
+ super(...arguments);
2921
+ __publicField(this, "priority", 110);
2922
+ __publicField(this, "incompatibleTokens", [
2923
+ "Y",
2924
+ "R",
2925
+ "q",
2926
+ "Q",
2927
+ "M",
2928
+ "w",
2929
+ "I",
2930
+ "D",
2931
+ "i",
2932
+ "e",
2933
+ "c",
2934
+ "t",
2935
+ "T"
2936
+ ]);
2937
+ }
2938
+ parse(dateString, token, match2) {
2939
+ const valueCallback = (value) => value - 1;
2940
+ switch (token) {
2941
+ // 1, 2, ..., 12
2942
+ case "L":
2943
+ return mapValue(
2944
+ parseNumericPattern(numericPatterns.month, dateString),
2945
+ valueCallback
2946
+ );
2947
+ // 01, 02, ..., 12
2948
+ case "LL":
2949
+ return mapValue(parseNDigits(2, dateString), valueCallback);
2950
+ // 1st, 2nd, ..., 12th
2951
+ case "Lo":
2952
+ return mapValue(
2953
+ match2.ordinalNumber(dateString, {
2954
+ unit: "month"
2955
+ }),
2956
+ valueCallback
2957
+ );
2958
+ // Jan, Feb, ..., Dec
2959
+ case "LLL":
2960
+ return match2.month(dateString, {
2961
+ width: "abbreviated",
2962
+ context: "standalone"
2963
+ }) || match2.month(dateString, { width: "narrow", context: "standalone" });
2964
+ // J, F, ..., D
2965
+ case "LLLLL":
2966
+ return match2.month(dateString, {
2967
+ width: "narrow",
2968
+ context: "standalone"
2969
+ });
2970
+ // January, February, ..., December
2971
+ case "LLLL":
2972
+ default:
2973
+ return match2.month(dateString, { width: "wide", context: "standalone" }) || match2.month(dateString, {
2974
+ width: "abbreviated",
2975
+ context: "standalone"
2976
+ }) || match2.month(dateString, { width: "narrow", context: "standalone" });
2977
+ }
2978
+ }
2979
+ validate(_date, value) {
2980
+ return value >= 0 && value <= 11;
2981
+ }
2982
+ set(date, _flags, value) {
2983
+ date.setMonth(value, 1);
2984
+ date.setHours(0, 0, 0, 0);
2985
+ return date;
2986
+ }
2987
+ };
2988
+
2989
+ // ../../node_modules/date-fns/setWeek.mjs
2990
+ function setWeek(date, week, options) {
2991
+ const _date = toDate(date);
2992
+ const diff = getWeek(_date, options) - week;
2993
+ _date.setDate(_date.getDate() - diff * 7);
2994
+ return _date;
2995
+ }
2996
+
2997
+ // ../../node_modules/date-fns/parse/_lib/parsers/LocalWeekParser.mjs
2998
+ var LocalWeekParser = class extends Parser {
2999
+ constructor() {
3000
+ super(...arguments);
3001
+ __publicField(this, "priority", 100);
3002
+ __publicField(this, "incompatibleTokens", [
3003
+ "y",
3004
+ "R",
3005
+ "u",
3006
+ "q",
3007
+ "Q",
3008
+ "M",
3009
+ "L",
3010
+ "I",
3011
+ "d",
3012
+ "D",
3013
+ "i",
3014
+ "t",
3015
+ "T"
3016
+ ]);
3017
+ }
3018
+ parse(dateString, token, match2) {
3019
+ switch (token) {
3020
+ case "w":
3021
+ return parseNumericPattern(numericPatterns.week, dateString);
3022
+ case "wo":
3023
+ return match2.ordinalNumber(dateString, { unit: "week" });
3024
+ default:
3025
+ return parseNDigits(token.length, dateString);
3026
+ }
3027
+ }
3028
+ validate(_date, value) {
3029
+ return value >= 1 && value <= 53;
3030
+ }
3031
+ set(date, _flags, value, options) {
3032
+ return startOfWeek(setWeek(date, value, options), options);
3033
+ }
3034
+ };
3035
+
3036
+ // ../../node_modules/date-fns/setISOWeek.mjs
3037
+ function setISOWeek(date, week) {
3038
+ const _date = toDate(date);
3039
+ const diff = getISOWeek(_date) - week;
3040
+ _date.setDate(_date.getDate() - diff * 7);
3041
+ return _date;
3042
+ }
3043
+
3044
+ // ../../node_modules/date-fns/parse/_lib/parsers/ISOWeekParser.mjs
3045
+ var ISOWeekParser = class extends Parser {
3046
+ constructor() {
3047
+ super(...arguments);
3048
+ __publicField(this, "priority", 100);
3049
+ __publicField(this, "incompatibleTokens", [
3050
+ "y",
3051
+ "Y",
3052
+ "u",
3053
+ "q",
3054
+ "Q",
3055
+ "M",
3056
+ "L",
3057
+ "w",
3058
+ "d",
3059
+ "D",
3060
+ "e",
3061
+ "c",
3062
+ "t",
3063
+ "T"
3064
+ ]);
3065
+ }
3066
+ parse(dateString, token, match2) {
3067
+ switch (token) {
3068
+ case "I":
3069
+ return parseNumericPattern(numericPatterns.week, dateString);
3070
+ case "Io":
3071
+ return match2.ordinalNumber(dateString, { unit: "week" });
3072
+ default:
3073
+ return parseNDigits(token.length, dateString);
3074
+ }
3075
+ }
3076
+ validate(_date, value) {
3077
+ return value >= 1 && value <= 53;
3078
+ }
3079
+ set(date, _flags, value) {
3080
+ return startOfISOWeek(setISOWeek(date, value));
3081
+ }
3082
+ };
3083
+
3084
+ // ../../node_modules/date-fns/parse/_lib/parsers/DateParser.mjs
3085
+ var DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
3086
+ var DAYS_IN_MONTH_LEAP_YEAR = [
3087
+ 31,
3088
+ 29,
3089
+ 31,
3090
+ 30,
3091
+ 31,
3092
+ 30,
3093
+ 31,
3094
+ 31,
3095
+ 30,
3096
+ 31,
3097
+ 30,
3098
+ 31
3099
+ ];
3100
+ var DateParser = class extends Parser {
3101
+ constructor() {
3102
+ super(...arguments);
3103
+ __publicField(this, "priority", 90);
3104
+ __publicField(this, "subPriority", 1);
3105
+ __publicField(this, "incompatibleTokens", [
3106
+ "Y",
3107
+ "R",
3108
+ "q",
3109
+ "Q",
3110
+ "w",
3111
+ "I",
3112
+ "D",
3113
+ "i",
3114
+ "e",
3115
+ "c",
3116
+ "t",
3117
+ "T"
3118
+ ]);
3119
+ }
3120
+ parse(dateString, token, match2) {
3121
+ switch (token) {
3122
+ case "d":
3123
+ return parseNumericPattern(numericPatterns.date, dateString);
3124
+ case "do":
3125
+ return match2.ordinalNumber(dateString, { unit: "date" });
3126
+ default:
3127
+ return parseNDigits(token.length, dateString);
3128
+ }
3129
+ }
3130
+ validate(date, value) {
3131
+ const year = date.getFullYear();
3132
+ const isLeapYear = isLeapYearIndex(year);
3133
+ const month = date.getMonth();
3134
+ if (isLeapYear) {
3135
+ return value >= 1 && value <= DAYS_IN_MONTH_LEAP_YEAR[month];
3136
+ } else {
3137
+ return value >= 1 && value <= DAYS_IN_MONTH[month];
3138
+ }
3139
+ }
3140
+ set(date, _flags, value) {
3141
+ date.setDate(value);
3142
+ date.setHours(0, 0, 0, 0);
3143
+ return date;
3144
+ }
3145
+ };
3146
+
3147
+ // ../../node_modules/date-fns/parse/_lib/parsers/DayOfYearParser.mjs
3148
+ var DayOfYearParser = class extends Parser {
3149
+ constructor() {
3150
+ super(...arguments);
3151
+ __publicField(this, "priority", 90);
3152
+ __publicField(this, "subpriority", 1);
3153
+ __publicField(this, "incompatibleTokens", [
3154
+ "Y",
3155
+ "R",
3156
+ "q",
3157
+ "Q",
3158
+ "M",
3159
+ "L",
3160
+ "w",
3161
+ "I",
3162
+ "d",
3163
+ "E",
3164
+ "i",
3165
+ "e",
3166
+ "c",
3167
+ "t",
3168
+ "T"
3169
+ ]);
3170
+ }
3171
+ parse(dateString, token, match2) {
3172
+ switch (token) {
3173
+ case "D":
3174
+ case "DD":
3175
+ return parseNumericPattern(numericPatterns.dayOfYear, dateString);
3176
+ case "Do":
3177
+ return match2.ordinalNumber(dateString, { unit: "date" });
3178
+ default:
3179
+ return parseNDigits(token.length, dateString);
3180
+ }
3181
+ }
3182
+ validate(date, value) {
3183
+ const year = date.getFullYear();
3184
+ const isLeapYear = isLeapYearIndex(year);
3185
+ if (isLeapYear) {
3186
+ return value >= 1 && value <= 366;
3187
+ } else {
3188
+ return value >= 1 && value <= 365;
3189
+ }
3190
+ }
3191
+ set(date, _flags, value) {
3192
+ date.setMonth(0, value);
3193
+ date.setHours(0, 0, 0, 0);
3194
+ return date;
3195
+ }
3196
+ };
3197
+
3198
+ // ../../node_modules/date-fns/setDay.mjs
3199
+ function setDay(date, day, options) {
3200
+ const defaultOptions2 = getDefaultOptions();
3201
+ const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
3202
+ const _date = toDate(date);
3203
+ const currentDay = _date.getDay();
3204
+ const remainder = day % 7;
3205
+ const dayIndex = (remainder + 7) % 7;
3206
+ const delta = 7 - weekStartsOn;
3207
+ const diff = day < 0 || day > 6 ? day - (currentDay + delta) % 7 : (dayIndex + delta) % 7 - (currentDay + delta) % 7;
3208
+ return addDays(_date, diff);
3209
+ }
3210
+
3211
+ // ../../node_modules/date-fns/parse/_lib/parsers/DayParser.mjs
3212
+ var DayParser = class extends Parser {
3213
+ constructor() {
3214
+ super(...arguments);
3215
+ __publicField(this, "priority", 90);
3216
+ __publicField(this, "incompatibleTokens", ["D", "i", "e", "c", "t", "T"]);
3217
+ }
3218
+ parse(dateString, token, match2) {
3219
+ switch (token) {
3220
+ // Tue
3221
+ case "E":
3222
+ case "EE":
3223
+ case "EEE":
3224
+ return match2.day(dateString, {
3225
+ width: "abbreviated",
3226
+ context: "formatting"
3227
+ }) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
3228
+ // T
3229
+ case "EEEEE":
3230
+ return match2.day(dateString, {
3231
+ width: "narrow",
3232
+ context: "formatting"
3233
+ });
3234
+ // Tu
3235
+ case "EEEEEE":
3236
+ return match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
3237
+ // Tuesday
3238
+ case "EEEE":
3239
+ default:
3240
+ return match2.day(dateString, { width: "wide", context: "formatting" }) || match2.day(dateString, {
3241
+ width: "abbreviated",
3242
+ context: "formatting"
3243
+ }) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
3244
+ }
3245
+ }
3246
+ validate(_date, value) {
3247
+ return value >= 0 && value <= 6;
3248
+ }
3249
+ set(date, _flags, value, options) {
3250
+ date = setDay(date, value, options);
3251
+ date.setHours(0, 0, 0, 0);
3252
+ return date;
3253
+ }
3254
+ };
3255
+
3256
+ // ../../node_modules/date-fns/parse/_lib/parsers/LocalDayParser.mjs
3257
+ var LocalDayParser = class extends Parser {
3258
+ constructor() {
3259
+ super(...arguments);
3260
+ __publicField(this, "priority", 90);
3261
+ __publicField(this, "incompatibleTokens", [
3262
+ "y",
3263
+ "R",
3264
+ "u",
3265
+ "q",
3266
+ "Q",
3267
+ "M",
3268
+ "L",
3269
+ "I",
3270
+ "d",
3271
+ "D",
3272
+ "E",
3273
+ "i",
3274
+ "c",
3275
+ "t",
3276
+ "T"
3277
+ ]);
3278
+ }
3279
+ parse(dateString, token, match2, options) {
3280
+ const valueCallback = (value) => {
3281
+ const wholeWeekDays = Math.floor((value - 1) / 7) * 7;
3282
+ return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
3283
+ };
3284
+ switch (token) {
3285
+ // 3
3286
+ case "e":
3287
+ case "ee":
3288
+ return mapValue(parseNDigits(token.length, dateString), valueCallback);
3289
+ // 3rd
3290
+ case "eo":
3291
+ return mapValue(
3292
+ match2.ordinalNumber(dateString, {
3293
+ unit: "day"
3294
+ }),
3295
+ valueCallback
3296
+ );
3297
+ // Tue
3298
+ case "eee":
3299
+ return match2.day(dateString, {
3300
+ width: "abbreviated",
3301
+ context: "formatting"
3302
+ }) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
3303
+ // T
3304
+ case "eeeee":
3305
+ return match2.day(dateString, {
3306
+ width: "narrow",
3307
+ context: "formatting"
3308
+ });
3309
+ // Tu
3310
+ case "eeeeee":
3311
+ return match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
3312
+ // Tuesday
3313
+ case "eeee":
3314
+ default:
3315
+ return match2.day(dateString, { width: "wide", context: "formatting" }) || match2.day(dateString, {
3316
+ width: "abbreviated",
3317
+ context: "formatting"
3318
+ }) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
3319
+ }
3320
+ }
3321
+ validate(_date, value) {
3322
+ return value >= 0 && value <= 6;
3323
+ }
3324
+ set(date, _flags, value, options) {
3325
+ date = setDay(date, value, options);
3326
+ date.setHours(0, 0, 0, 0);
3327
+ return date;
3328
+ }
3329
+ };
3330
+
3331
+ // ../../node_modules/date-fns/parse/_lib/parsers/StandAloneLocalDayParser.mjs
3332
+ var StandAloneLocalDayParser = class extends Parser {
3333
+ constructor() {
3334
+ super(...arguments);
3335
+ __publicField(this, "priority", 90);
3336
+ __publicField(this, "incompatibleTokens", [
3337
+ "y",
3338
+ "R",
3339
+ "u",
3340
+ "q",
3341
+ "Q",
3342
+ "M",
3343
+ "L",
3344
+ "I",
3345
+ "d",
3346
+ "D",
3347
+ "E",
3348
+ "i",
3349
+ "e",
3350
+ "t",
3351
+ "T"
3352
+ ]);
3353
+ }
3354
+ parse(dateString, token, match2, options) {
3355
+ const valueCallback = (value) => {
3356
+ const wholeWeekDays = Math.floor((value - 1) / 7) * 7;
3357
+ return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
3358
+ };
3359
+ switch (token) {
3360
+ // 3
3361
+ case "c":
3362
+ case "cc":
3363
+ return mapValue(parseNDigits(token.length, dateString), valueCallback);
3364
+ // 3rd
3365
+ case "co":
3366
+ return mapValue(
3367
+ match2.ordinalNumber(dateString, {
3368
+ unit: "day"
3369
+ }),
3370
+ valueCallback
3371
+ );
3372
+ // Tue
3373
+ case "ccc":
3374
+ return match2.day(dateString, {
3375
+ width: "abbreviated",
3376
+ context: "standalone"
3377
+ }) || match2.day(dateString, { width: "short", context: "standalone" }) || match2.day(dateString, { width: "narrow", context: "standalone" });
3378
+ // T
3379
+ case "ccccc":
3380
+ return match2.day(dateString, {
3381
+ width: "narrow",
3382
+ context: "standalone"
3383
+ });
3384
+ // Tu
3385
+ case "cccccc":
3386
+ return match2.day(dateString, { width: "short", context: "standalone" }) || match2.day(dateString, { width: "narrow", context: "standalone" });
3387
+ // Tuesday
3388
+ case "cccc":
3389
+ default:
3390
+ return match2.day(dateString, { width: "wide", context: "standalone" }) || match2.day(dateString, {
3391
+ width: "abbreviated",
3392
+ context: "standalone"
3393
+ }) || match2.day(dateString, { width: "short", context: "standalone" }) || match2.day(dateString, { width: "narrow", context: "standalone" });
3394
+ }
3395
+ }
3396
+ validate(_date, value) {
3397
+ return value >= 0 && value <= 6;
3398
+ }
3399
+ set(date, _flags, value, options) {
3400
+ date = setDay(date, value, options);
3401
+ date.setHours(0, 0, 0, 0);
3402
+ return date;
3403
+ }
3404
+ };
3405
+
3406
+ // ../../node_modules/date-fns/setISODay.mjs
3407
+ function setISODay(date, day) {
3408
+ const _date = toDate(date);
3409
+ const currentDay = getISODay(_date);
3410
+ const diff = day - currentDay;
3411
+ return addDays(_date, diff);
3412
+ }
3413
+
3414
+ // ../../node_modules/date-fns/parse/_lib/parsers/ISODayParser.mjs
3415
+ var ISODayParser = class extends Parser {
3416
+ constructor() {
3417
+ super(...arguments);
3418
+ __publicField(this, "priority", 90);
3419
+ __publicField(this, "incompatibleTokens", [
3420
+ "y",
3421
+ "Y",
3422
+ "u",
3423
+ "q",
3424
+ "Q",
3425
+ "M",
3426
+ "L",
3427
+ "w",
3428
+ "d",
3429
+ "D",
3430
+ "E",
3431
+ "e",
3432
+ "c",
3433
+ "t",
3434
+ "T"
3435
+ ]);
3436
+ }
3437
+ parse(dateString, token, match2) {
3438
+ const valueCallback = (value) => {
3439
+ if (value === 0) {
3440
+ return 7;
3441
+ }
3442
+ return value;
3443
+ };
3444
+ switch (token) {
3445
+ // 2
3446
+ case "i":
3447
+ case "ii":
3448
+ return parseNDigits(token.length, dateString);
3449
+ // 2nd
3450
+ case "io":
3451
+ return match2.ordinalNumber(dateString, { unit: "day" });
3452
+ // Tue
3453
+ case "iii":
3454
+ return mapValue(
3455
+ match2.day(dateString, {
3456
+ width: "abbreviated",
3457
+ context: "formatting"
3458
+ }) || match2.day(dateString, {
3459
+ width: "short",
3460
+ context: "formatting"
3461
+ }) || match2.day(dateString, {
3462
+ width: "narrow",
3463
+ context: "formatting"
3464
+ }),
3465
+ valueCallback
3466
+ );
3467
+ // T
3468
+ case "iiiii":
3469
+ return mapValue(
3470
+ match2.day(dateString, {
3471
+ width: "narrow",
3472
+ context: "formatting"
3473
+ }),
3474
+ valueCallback
3475
+ );
3476
+ // Tu
3477
+ case "iiiiii":
3478
+ return mapValue(
3479
+ match2.day(dateString, {
3480
+ width: "short",
3481
+ context: "formatting"
3482
+ }) || match2.day(dateString, {
3483
+ width: "narrow",
3484
+ context: "formatting"
3485
+ }),
3486
+ valueCallback
3487
+ );
3488
+ // Tuesday
3489
+ case "iiii":
3490
+ default:
3491
+ return mapValue(
3492
+ match2.day(dateString, {
3493
+ width: "wide",
3494
+ context: "formatting"
3495
+ }) || match2.day(dateString, {
3496
+ width: "abbreviated",
3497
+ context: "formatting"
3498
+ }) || match2.day(dateString, {
3499
+ width: "short",
3500
+ context: "formatting"
3501
+ }) || match2.day(dateString, {
3502
+ width: "narrow",
3503
+ context: "formatting"
3504
+ }),
3505
+ valueCallback
3506
+ );
3507
+ }
3508
+ }
3509
+ validate(_date, value) {
3510
+ return value >= 1 && value <= 7;
3511
+ }
3512
+ set(date, _flags, value) {
3513
+ date = setISODay(date, value);
3514
+ date.setHours(0, 0, 0, 0);
3515
+ return date;
3516
+ }
3517
+ };
3518
+
3519
+ // ../../node_modules/date-fns/parse/_lib/parsers/AMPMParser.mjs
3520
+ var AMPMParser = class extends Parser {
3521
+ constructor() {
3522
+ super(...arguments);
3523
+ __publicField(this, "priority", 80);
3524
+ __publicField(this, "incompatibleTokens", ["b", "B", "H", "k", "t", "T"]);
3525
+ }
3526
+ parse(dateString, token, match2) {
3527
+ switch (token) {
3528
+ case "a":
3529
+ case "aa":
3530
+ case "aaa":
3531
+ return match2.dayPeriod(dateString, {
3532
+ width: "abbreviated",
3533
+ context: "formatting"
3534
+ }) || match2.dayPeriod(dateString, {
3535
+ width: "narrow",
3536
+ context: "formatting"
3537
+ });
3538
+ case "aaaaa":
3539
+ return match2.dayPeriod(dateString, {
3540
+ width: "narrow",
3541
+ context: "formatting"
3542
+ });
3543
+ case "aaaa":
3544
+ default:
3545
+ return match2.dayPeriod(dateString, {
3546
+ width: "wide",
3547
+ context: "formatting"
3548
+ }) || match2.dayPeriod(dateString, {
3549
+ width: "abbreviated",
3550
+ context: "formatting"
3551
+ }) || match2.dayPeriod(dateString, {
3552
+ width: "narrow",
3553
+ context: "formatting"
3554
+ });
3555
+ }
3556
+ }
3557
+ set(date, _flags, value) {
3558
+ date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
3559
+ return date;
3560
+ }
3561
+ };
3562
+
3563
+ // ../../node_modules/date-fns/parse/_lib/parsers/AMPMMidnightParser.mjs
3564
+ var AMPMMidnightParser = class extends Parser {
3565
+ constructor() {
3566
+ super(...arguments);
3567
+ __publicField(this, "priority", 80);
3568
+ __publicField(this, "incompatibleTokens", ["a", "B", "H", "k", "t", "T"]);
3569
+ }
3570
+ parse(dateString, token, match2) {
3571
+ switch (token) {
3572
+ case "b":
3573
+ case "bb":
3574
+ case "bbb":
3575
+ return match2.dayPeriod(dateString, {
3576
+ width: "abbreviated",
3577
+ context: "formatting"
3578
+ }) || match2.dayPeriod(dateString, {
3579
+ width: "narrow",
3580
+ context: "formatting"
3581
+ });
3582
+ case "bbbbb":
3583
+ return match2.dayPeriod(dateString, {
3584
+ width: "narrow",
3585
+ context: "formatting"
3586
+ });
3587
+ case "bbbb":
3588
+ default:
3589
+ return match2.dayPeriod(dateString, {
3590
+ width: "wide",
3591
+ context: "formatting"
3592
+ }) || match2.dayPeriod(dateString, {
3593
+ width: "abbreviated",
3594
+ context: "formatting"
3595
+ }) || match2.dayPeriod(dateString, {
3596
+ width: "narrow",
3597
+ context: "formatting"
3598
+ });
3599
+ }
3600
+ }
3601
+ set(date, _flags, value) {
3602
+ date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
3603
+ return date;
3604
+ }
3605
+ };
3606
+
3607
+ // ../../node_modules/date-fns/parse/_lib/parsers/DayPeriodParser.mjs
3608
+ var DayPeriodParser = class extends Parser {
3609
+ constructor() {
3610
+ super(...arguments);
3611
+ __publicField(this, "priority", 80);
3612
+ __publicField(this, "incompatibleTokens", ["a", "b", "t", "T"]);
3613
+ }
3614
+ parse(dateString, token, match2) {
3615
+ switch (token) {
3616
+ case "B":
3617
+ case "BB":
3618
+ case "BBB":
3619
+ return match2.dayPeriod(dateString, {
3620
+ width: "abbreviated",
3621
+ context: "formatting"
3622
+ }) || match2.dayPeriod(dateString, {
3623
+ width: "narrow",
3624
+ context: "formatting"
3625
+ });
3626
+ case "BBBBB":
3627
+ return match2.dayPeriod(dateString, {
3628
+ width: "narrow",
3629
+ context: "formatting"
3630
+ });
3631
+ case "BBBB":
3632
+ default:
3633
+ return match2.dayPeriod(dateString, {
3634
+ width: "wide",
3635
+ context: "formatting"
3636
+ }) || match2.dayPeriod(dateString, {
3637
+ width: "abbreviated",
3638
+ context: "formatting"
3639
+ }) || match2.dayPeriod(dateString, {
3640
+ width: "narrow",
3641
+ context: "formatting"
3642
+ });
3643
+ }
3644
+ }
3645
+ set(date, _flags, value) {
3646
+ date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
3647
+ return date;
3648
+ }
3649
+ };
3650
+
3651
+ // ../../node_modules/date-fns/parse/_lib/parsers/Hour1to12Parser.mjs
3652
+ var Hour1to12Parser = class extends Parser {
3653
+ constructor() {
3654
+ super(...arguments);
3655
+ __publicField(this, "priority", 70);
3656
+ __publicField(this, "incompatibleTokens", ["H", "K", "k", "t", "T"]);
3657
+ }
3658
+ parse(dateString, token, match2) {
3659
+ switch (token) {
3660
+ case "h":
3661
+ return parseNumericPattern(numericPatterns.hour12h, dateString);
3662
+ case "ho":
3663
+ return match2.ordinalNumber(dateString, { unit: "hour" });
3664
+ default:
3665
+ return parseNDigits(token.length, dateString);
3666
+ }
3667
+ }
3668
+ validate(_date, value) {
3669
+ return value >= 1 && value <= 12;
3670
+ }
3671
+ set(date, _flags, value) {
3672
+ const isPM = date.getHours() >= 12;
3673
+ if (isPM && value < 12) {
3674
+ date.setHours(value + 12, 0, 0, 0);
3675
+ } else if (!isPM && value === 12) {
3676
+ date.setHours(0, 0, 0, 0);
3677
+ } else {
3678
+ date.setHours(value, 0, 0, 0);
3679
+ }
3680
+ return date;
3681
+ }
3682
+ };
3683
+
3684
+ // ../../node_modules/date-fns/parse/_lib/parsers/Hour0to23Parser.mjs
3685
+ var Hour0to23Parser = class extends Parser {
3686
+ constructor() {
3687
+ super(...arguments);
3688
+ __publicField(this, "priority", 70);
3689
+ __publicField(this, "incompatibleTokens", ["a", "b", "h", "K", "k", "t", "T"]);
3690
+ }
3691
+ parse(dateString, token, match2) {
3692
+ switch (token) {
3693
+ case "H":
3694
+ return parseNumericPattern(numericPatterns.hour23h, dateString);
3695
+ case "Ho":
3696
+ return match2.ordinalNumber(dateString, { unit: "hour" });
3697
+ default:
3698
+ return parseNDigits(token.length, dateString);
3699
+ }
3700
+ }
3701
+ validate(_date, value) {
3702
+ return value >= 0 && value <= 23;
3703
+ }
3704
+ set(date, _flags, value) {
3705
+ date.setHours(value, 0, 0, 0);
3706
+ return date;
3707
+ }
3708
+ };
3709
+
3710
+ // ../../node_modules/date-fns/parse/_lib/parsers/Hour0To11Parser.mjs
3711
+ var Hour0To11Parser = class extends Parser {
3712
+ constructor() {
3713
+ super(...arguments);
3714
+ __publicField(this, "priority", 70);
3715
+ __publicField(this, "incompatibleTokens", ["h", "H", "k", "t", "T"]);
3716
+ }
3717
+ parse(dateString, token, match2) {
3718
+ switch (token) {
3719
+ case "K":
3720
+ return parseNumericPattern(numericPatterns.hour11h, dateString);
3721
+ case "Ko":
3722
+ return match2.ordinalNumber(dateString, { unit: "hour" });
3723
+ default:
3724
+ return parseNDigits(token.length, dateString);
3725
+ }
3726
+ }
3727
+ validate(_date, value) {
3728
+ return value >= 0 && value <= 11;
3729
+ }
3730
+ set(date, _flags, value) {
3731
+ const isPM = date.getHours() >= 12;
3732
+ if (isPM && value < 12) {
3733
+ date.setHours(value + 12, 0, 0, 0);
3734
+ } else {
3735
+ date.setHours(value, 0, 0, 0);
3736
+ }
3737
+ return date;
3738
+ }
3739
+ };
3740
+
3741
+ // ../../node_modules/date-fns/parse/_lib/parsers/Hour1To24Parser.mjs
3742
+ var Hour1To24Parser = class extends Parser {
3743
+ constructor() {
3744
+ super(...arguments);
3745
+ __publicField(this, "priority", 70);
3746
+ __publicField(this, "incompatibleTokens", ["a", "b", "h", "H", "K", "t", "T"]);
3747
+ }
3748
+ parse(dateString, token, match2) {
3749
+ switch (token) {
3750
+ case "k":
3751
+ return parseNumericPattern(numericPatterns.hour24h, dateString);
3752
+ case "ko":
3753
+ return match2.ordinalNumber(dateString, { unit: "hour" });
3754
+ default:
3755
+ return parseNDigits(token.length, dateString);
3756
+ }
3757
+ }
3758
+ validate(_date, value) {
3759
+ return value >= 1 && value <= 24;
3760
+ }
3761
+ set(date, _flags, value) {
3762
+ const hours = value <= 24 ? value % 24 : value;
3763
+ date.setHours(hours, 0, 0, 0);
3764
+ return date;
3765
+ }
3766
+ };
3767
+
3768
+ // ../../node_modules/date-fns/parse/_lib/parsers/MinuteParser.mjs
3769
+ var MinuteParser = class extends Parser {
3770
+ constructor() {
3771
+ super(...arguments);
3772
+ __publicField(this, "priority", 60);
3773
+ __publicField(this, "incompatibleTokens", ["t", "T"]);
3774
+ }
3775
+ parse(dateString, token, match2) {
3776
+ switch (token) {
3777
+ case "m":
3778
+ return parseNumericPattern(numericPatterns.minute, dateString);
3779
+ case "mo":
3780
+ return match2.ordinalNumber(dateString, { unit: "minute" });
3781
+ default:
3782
+ return parseNDigits(token.length, dateString);
3783
+ }
3784
+ }
3785
+ validate(_date, value) {
3786
+ return value >= 0 && value <= 59;
3787
+ }
3788
+ set(date, _flags, value) {
3789
+ date.setMinutes(value, 0, 0);
3790
+ return date;
3791
+ }
3792
+ };
3793
+
3794
+ // ../../node_modules/date-fns/parse/_lib/parsers/SecondParser.mjs
3795
+ var SecondParser = class extends Parser {
3796
+ constructor() {
3797
+ super(...arguments);
3798
+ __publicField(this, "priority", 50);
3799
+ __publicField(this, "incompatibleTokens", ["t", "T"]);
3800
+ }
3801
+ parse(dateString, token, match2) {
3802
+ switch (token) {
3803
+ case "s":
3804
+ return parseNumericPattern(numericPatterns.second, dateString);
3805
+ case "so":
3806
+ return match2.ordinalNumber(dateString, { unit: "second" });
3807
+ default:
3808
+ return parseNDigits(token.length, dateString);
3809
+ }
3810
+ }
3811
+ validate(_date, value) {
3812
+ return value >= 0 && value <= 59;
3813
+ }
3814
+ set(date, _flags, value) {
3815
+ date.setSeconds(value, 0);
3816
+ return date;
3817
+ }
3818
+ };
3819
+
3820
+ // ../../node_modules/date-fns/parse/_lib/parsers/FractionOfSecondParser.mjs
3821
+ var FractionOfSecondParser = class extends Parser {
3822
+ constructor() {
3823
+ super(...arguments);
3824
+ __publicField(this, "priority", 30);
3825
+ __publicField(this, "incompatibleTokens", ["t", "T"]);
3826
+ }
3827
+ parse(dateString, token) {
3828
+ const valueCallback = (value) => Math.trunc(value * Math.pow(10, -token.length + 3));
3829
+ return mapValue(parseNDigits(token.length, dateString), valueCallback);
3830
+ }
3831
+ set(date, _flags, value) {
3832
+ date.setMilliseconds(value);
3833
+ return date;
3834
+ }
3835
+ };
3836
+
3837
+ // ../../node_modules/date-fns/parse/_lib/parsers/ISOTimezoneWithZParser.mjs
3838
+ var ISOTimezoneWithZParser = class extends Parser {
3839
+ constructor() {
3840
+ super(...arguments);
3841
+ __publicField(this, "priority", 10);
3842
+ __publicField(this, "incompatibleTokens", ["t", "T", "x"]);
3843
+ }
3844
+ parse(dateString, token) {
3845
+ switch (token) {
3846
+ case "X":
3847
+ return parseTimezonePattern(
3848
+ timezonePatterns.basicOptionalMinutes,
3849
+ dateString
3850
+ );
3851
+ case "XX":
3852
+ return parseTimezonePattern(timezonePatterns.basic, dateString);
3853
+ case "XXXX":
3854
+ return parseTimezonePattern(
3855
+ timezonePatterns.basicOptionalSeconds,
3856
+ dateString
3857
+ );
3858
+ case "XXXXX":
3859
+ return parseTimezonePattern(
3860
+ timezonePatterns.extendedOptionalSeconds,
3861
+ dateString
3862
+ );
3863
+ case "XXX":
3864
+ default:
3865
+ return parseTimezonePattern(timezonePatterns.extended, dateString);
3866
+ }
3867
+ }
3868
+ set(date, flags, value) {
3869
+ if (flags.timestampIsSet) return date;
3870
+ return constructFrom(
3871
+ date,
3872
+ date.getTime() - getTimezoneOffsetInMilliseconds(date) - value
3873
+ );
3874
+ }
3875
+ };
3876
+
3877
+ // ../../node_modules/date-fns/parse/_lib/parsers/ISOTimezoneParser.mjs
3878
+ var ISOTimezoneParser = class extends Parser {
3879
+ constructor() {
3880
+ super(...arguments);
3881
+ __publicField(this, "priority", 10);
3882
+ __publicField(this, "incompatibleTokens", ["t", "T", "X"]);
3883
+ }
3884
+ parse(dateString, token) {
3885
+ switch (token) {
3886
+ case "x":
3887
+ return parseTimezonePattern(
3888
+ timezonePatterns.basicOptionalMinutes,
3889
+ dateString
3890
+ );
3891
+ case "xx":
3892
+ return parseTimezonePattern(timezonePatterns.basic, dateString);
3893
+ case "xxxx":
3894
+ return parseTimezonePattern(
3895
+ timezonePatterns.basicOptionalSeconds,
3896
+ dateString
3897
+ );
3898
+ case "xxxxx":
3899
+ return parseTimezonePattern(
3900
+ timezonePatterns.extendedOptionalSeconds,
3901
+ dateString
3902
+ );
3903
+ case "xxx":
3904
+ default:
3905
+ return parseTimezonePattern(timezonePatterns.extended, dateString);
3906
+ }
3907
+ }
3908
+ set(date, flags, value) {
3909
+ if (flags.timestampIsSet) return date;
3910
+ return constructFrom(
3911
+ date,
3912
+ date.getTime() - getTimezoneOffsetInMilliseconds(date) - value
3913
+ );
3914
+ }
3915
+ };
3916
+
3917
+ // ../../node_modules/date-fns/parse/_lib/parsers/TimestampSecondsParser.mjs
3918
+ var TimestampSecondsParser = class extends Parser {
3919
+ constructor() {
3920
+ super(...arguments);
3921
+ __publicField(this, "priority", 40);
3922
+ __publicField(this, "incompatibleTokens", "*");
3923
+ }
3924
+ parse(dateString) {
3925
+ return parseAnyDigitsSigned(dateString);
3926
+ }
3927
+ set(date, _flags, value) {
3928
+ return [constructFrom(date, value * 1e3), { timestampIsSet: true }];
3929
+ }
3930
+ };
3931
+
3932
+ // ../../node_modules/date-fns/parse/_lib/parsers/TimestampMillisecondsParser.mjs
3933
+ var TimestampMillisecondsParser = class extends Parser {
3934
+ constructor() {
3935
+ super(...arguments);
3936
+ __publicField(this, "priority", 20);
3937
+ __publicField(this, "incompatibleTokens", "*");
3938
+ }
3939
+ parse(dateString) {
3940
+ return parseAnyDigitsSigned(dateString);
3941
+ }
3942
+ set(date, _flags, value) {
3943
+ return [constructFrom(date, value), { timestampIsSet: true }];
3944
+ }
3945
+ };
3946
+
3947
+ // ../../node_modules/date-fns/parse/_lib/parsers.mjs
3948
+ var parsers = {
3949
+ G: new EraParser(),
3950
+ y: new YearParser(),
3951
+ Y: new LocalWeekYearParser(),
3952
+ R: new ISOWeekYearParser(),
3953
+ u: new ExtendedYearParser(),
3954
+ Q: new QuarterParser(),
3955
+ q: new StandAloneQuarterParser(),
3956
+ M: new MonthParser(),
3957
+ L: new StandAloneMonthParser(),
3958
+ w: new LocalWeekParser(),
3959
+ I: new ISOWeekParser(),
3960
+ d: new DateParser(),
3961
+ D: new DayOfYearParser(),
3962
+ E: new DayParser(),
3963
+ e: new LocalDayParser(),
3964
+ c: new StandAloneLocalDayParser(),
3965
+ i: new ISODayParser(),
3966
+ a: new AMPMParser(),
3967
+ b: new AMPMMidnightParser(),
3968
+ B: new DayPeriodParser(),
3969
+ h: new Hour1to12Parser(),
3970
+ H: new Hour0to23Parser(),
3971
+ K: new Hour0To11Parser(),
3972
+ k: new Hour1To24Parser(),
3973
+ m: new MinuteParser(),
3974
+ s: new SecondParser(),
3975
+ S: new FractionOfSecondParser(),
3976
+ X: new ISOTimezoneWithZParser(),
3977
+ x: new ISOTimezoneParser(),
3978
+ t: new TimestampSecondsParser(),
3979
+ T: new TimestampMillisecondsParser()
3980
+ };
3981
+
3982
+ // ../../node_modules/date-fns/parse.mjs
3983
+ var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
3984
+ var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
3985
+ var escapedStringRegExp = /^'([^]*?)'?$/;
3986
+ var doubleQuoteRegExp = /''/g;
3987
+ var notWhitespaceRegExp = /\S/;
3988
+ var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
3989
+ function parse(dateStr, formatStr, referenceDate, options) {
3990
+ const defaultOptions2 = getDefaultOptions2();
3991
+ const locale = defaultOptions2.locale ?? enUS;
3992
+ const firstWeekContainsDate = defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
3993
+ const weekStartsOn = defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
3994
+ const subFnOptions = {
3995
+ firstWeekContainsDate,
3996
+ weekStartsOn,
3997
+ locale
3998
+ };
3999
+ const setters = [new DateToSystemTimezoneSetter()];
4000
+ const tokens = formatStr.match(longFormattingTokensRegExp).map((substring) => {
4001
+ const firstCharacter = substring[0];
4002
+ if (firstCharacter in longFormatters) {
4003
+ const longFormatter = longFormatters[firstCharacter];
4004
+ return longFormatter(substring, locale.formatLong);
4005
+ }
4006
+ return substring;
4007
+ }).join("").match(formattingTokensRegExp);
4008
+ const usedTokens = [];
4009
+ for (let token of tokens) {
4010
+ if (isProtectedWeekYearToken(token)) {
4011
+ warnOrThrowProtectedError(token, formatStr, dateStr);
4012
+ }
4013
+ if (isProtectedDayOfYearToken(token)) {
4014
+ warnOrThrowProtectedError(token, formatStr, dateStr);
4015
+ }
4016
+ const firstCharacter = token[0];
4017
+ const parser = parsers[firstCharacter];
4018
+ if (parser) {
4019
+ const { incompatibleTokens } = parser;
4020
+ if (Array.isArray(incompatibleTokens)) {
4021
+ const incompatibleToken = usedTokens.find(
4022
+ (usedToken) => incompatibleTokens.includes(usedToken.token) || usedToken.token === firstCharacter
4023
+ );
4024
+ if (incompatibleToken) {
4025
+ throw new RangeError(
4026
+ `The format string mustn't contain \`${incompatibleToken.fullToken}\` and \`${token}\` at the same time`
4027
+ );
4028
+ }
4029
+ } else if (parser.incompatibleTokens === "*" && usedTokens.length > 0) {
4030
+ throw new RangeError(
4031
+ `The format string mustn't contain \`${token}\` and any other token at the same time`
4032
+ );
4033
+ }
4034
+ usedTokens.push({ token: firstCharacter, fullToken: token });
4035
+ const parseResult = parser.run(
4036
+ dateStr,
4037
+ token,
4038
+ locale.match,
4039
+ subFnOptions
4040
+ );
4041
+ if (!parseResult) {
4042
+ return constructFrom(referenceDate, NaN);
4043
+ }
4044
+ setters.push(parseResult.setter);
4045
+ dateStr = parseResult.rest;
4046
+ } else {
4047
+ if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
4048
+ throw new RangeError(
4049
+ "Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
4050
+ );
4051
+ }
4052
+ if (token === "''") {
4053
+ token = "'";
4054
+ } else if (firstCharacter === "'") {
4055
+ token = cleanEscapedString(token);
4056
+ }
4057
+ if (dateStr.indexOf(token) === 0) {
4058
+ dateStr = dateStr.slice(token.length);
4059
+ } else {
4060
+ return constructFrom(referenceDate, NaN);
4061
+ }
4062
+ }
4063
+ }
4064
+ if (dateStr.length > 0 && notWhitespaceRegExp.test(dateStr)) {
4065
+ return constructFrom(referenceDate, NaN);
4066
+ }
4067
+ const uniquePrioritySetters = setters.map((setter) => setter.priority).sort((a, b) => b - a).filter((priority, index, array) => array.indexOf(priority) === index).map(
4068
+ (priority) => setters.filter((setter) => setter.priority === priority).sort((a, b) => b.subPriority - a.subPriority)
4069
+ ).map((setterArray) => setterArray[0]);
4070
+ let date = toDate(referenceDate);
4071
+ if (isNaN(date.getTime())) {
4072
+ return constructFrom(referenceDate, NaN);
4073
+ }
4074
+ const flags = {};
4075
+ for (const setter of uniquePrioritySetters) {
4076
+ if (!setter.validate(date, subFnOptions)) {
4077
+ return constructFrom(referenceDate, NaN);
4078
+ }
4079
+ const result = setter.set(date, flags, subFnOptions);
4080
+ if (Array.isArray(result)) {
4081
+ date = result[0];
4082
+ Object.assign(flags, result[1]);
4083
+ } else {
4084
+ date = result;
4085
+ }
4086
+ }
4087
+ return constructFrom(referenceDate, date);
4088
+ }
4089
+ function cleanEscapedString(input) {
4090
+ return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'");
4091
+ }
4092
+
4093
+ // src/types/schema-form-builder.ts
4094
+ function hydrateField(raw, currentPage) {
4095
+ return {
4096
+ ...raw,
4097
+ rules_count: Object.keys(raw.show ?? {}).length,
4098
+ show_on_this_page: raw.page === currentPage,
4099
+ visible: false,
4100
+ is_visible: false,
4101
+ aws_lookup: raw.lookup?.aws_table != null
4102
+ };
4103
+ }
4104
+
4105
+ // src/utils/formSchemaApi.ts
4106
+ function isApiError(result) {
4107
+ return result.error === true;
4108
+ }
4109
+ async function getFormSchema(formId, appConfig) {
4110
+ try {
4111
+ const response = await fetch(`${appConfig.apiBaseUrl}/form/schema`, {
4112
+ method: "POST",
4113
+ headers: {
4114
+ "Content-Type": "application/json",
4115
+ clienttoken: appConfig.blApiToken
4116
+ },
4117
+ body: JSON.stringify({
4118
+ company: appConfig.company_id,
4119
+ client: appConfig.customer_name,
4120
+ form_name: formId
4121
+ })
4122
+ });
4123
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
4124
+ return await response.json();
4125
+ } catch (err) {
4126
+ return { error: true, message: err.message };
4127
+ }
4128
+ }
4129
+ async function getAddressLookup(postcode, appConfig) {
4130
+ try {
4131
+ const response = await fetch(
4132
+ `${appConfig.apiBaseUrl}/ordnance_survey/postcode/${encodeURIComponent(postcode)}`,
4133
+ {
4134
+ headers: {
4135
+ "Content-Type": "application/json",
4136
+ clienttoken: appConfig.blApiToken
4137
+ }
4138
+ }
4139
+ );
4140
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
4141
+ const data = await response.json();
4142
+ return Array.isArray(data) ? data : data.results ?? [];
4143
+ } catch (err) {
4144
+ return { error: true, message: err.message };
4145
+ }
4146
+ }
4147
+ async function awsLookup(appConfig, table, field, reference, referenceExtra, fieldExtra) {
4148
+ try {
4149
+ const body = {
4150
+ client: appConfig.customer_name,
4151
+ reference,
4152
+ table,
4153
+ field
4154
+ };
4155
+ if (referenceExtra && fieldExtra) {
4156
+ body["referenceExtra"] = fieldExtra;
4157
+ body["field_extra"] = referenceExtra;
4158
+ }
4159
+ const response = await fetch(`${appConfig.apiBaseUrl}/eligibility_reference_lookup`, {
4160
+ method: "POST",
4161
+ headers: {
4162
+ "Content-Type": "application/json",
4163
+ clienttoken: appConfig.blApiToken
4164
+ },
4165
+ body: JSON.stringify(body)
4166
+ });
4167
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
4168
+ return await response.json();
4169
+ } catch (err) {
4170
+ return { error: true, message: err.message };
4171
+ }
4172
+ }
4173
+ async function getExtraItemProperties(bookingQuestionCode, companyId, serviceId, appConfig) {
4174
+ try {
4175
+ const response = await fetch(
4176
+ `${appConfig.apiBaseUrl}/company/${companyId}/extra-item/${bookingQuestionCode}/service/${serviceId}`,
4177
+ {
4178
+ headers: {
4179
+ "Content-Type": "application/json",
4180
+ clienttoken: appConfig.blApiToken
4181
+ }
4182
+ }
4183
+ );
4184
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
4185
+ return await response.json();
4186
+ } catch (err) {
4187
+ return { error: true, message: err.message };
4188
+ }
4189
+ }
4190
+ async function searchVenue(companyId, query, appConfig) {
4191
+ try {
4192
+ const response = await fetch(
4193
+ `${appConfig.apiBaseUrl}/company/${companyId}/venue-lookup?search=${encodeURIComponent(query.toLowerCase())}`,
4194
+ {
4195
+ headers: {
4196
+ "Content-Type": "application/json",
4197
+ "x-company-id": companyId,
4198
+ clienttoken: appConfig.blApiToken
4199
+ }
4200
+ }
4201
+ );
4202
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
4203
+ const data = await response.json();
4204
+ return Array.isArray(data) ? data : [];
4205
+ } catch (err) {
4206
+ return { error: true, message: err.message };
4207
+ }
4208
+ }
4209
+ function requiredValidator(value) {
4210
+ if (value === "" || value == null) return { key: "required" };
4211
+ return null;
4212
+ }
4213
+ var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
4214
+ function emailValidator(value) {
4215
+ if (!value) return null;
4216
+ return EMAIL_REGEX.test(value) ? null : { key: "email" };
4217
+ }
4218
+ var UK_MOBILE_REGEX = /^(?:0|\+44)7\d{9}$/;
4219
+ function mobileValidator(value) {
4220
+ if (!value) return null;
4221
+ return UK_MOBILE_REGEX.test(value) ? null : { key: "pattern", message: "Enter a valid UK mobile number." };
4222
+ }
4223
+ var UK_PHONE_REGEX = /^(?:0|\+44)\s?\d{10}$/;
4224
+ function phoneValidator(value) {
4225
+ if (!value) return null;
4226
+ return UK_PHONE_REGEX.test(value) ? null : { key: "pattern", message: "Enter a valid UK phone number." };
4227
+ }
4228
+ function minLengthValidator(min) {
4229
+ return (value) => {
4230
+ if (!value) return null;
4231
+ return value.length >= min ? null : { key: "minlength", requiredLength: min };
4232
+ };
4233
+ }
4234
+ function maxLengthValidator(max) {
4235
+ return (value) => {
4236
+ if (!value) return null;
4237
+ return value.length <= max ? null : { key: "maxlength", requiredLength: max };
4238
+ };
4239
+ }
4240
+ function minDateValidator(minDateStr) {
4241
+ return (value) => {
4242
+ if (!value) return null;
4243
+ const controlDate = startOfDay(new Date(value));
4244
+ const minDate = startOfDay(parse(minDateStr, "dd-MM-yyyy", /* @__PURE__ */ new Date()));
4245
+ if (!isValid(controlDate)) return { key: "invalidDate", message: "Invalid date format" };
4246
+ return isBefore(controlDate, minDate) ? { key: "minDate", message: "Date cannot be in the past" } : null;
4247
+ };
4248
+ }
4249
+ function maxDateValidator(noOfDays) {
4250
+ return (value) => {
4251
+ if (!value) return null;
4252
+ const maxDate = startOfDay(addDays(/* @__PURE__ */ new Date(), noOfDays));
4253
+ const controlDate = startOfDay(new Date(value));
4254
+ return isAfter(controlDate, maxDate) ? { key: "maxDate", message: "Date cannot be in the future" } : null;
4255
+ };
4256
+ }
4257
+ function buildValidators(field) {
4258
+ const validators = [];
4259
+ if (field.required) validators.push(requiredValidator);
4260
+ if (!Array.isArray(field.validation)) return validators;
4261
+ for (const rule of field.validation) {
4262
+ if (typeof rule === "string") {
4263
+ switch (rule) {
4264
+ case "email":
4265
+ validators.push(emailValidator);
4266
+ break;
4267
+ case "mobile":
4268
+ validators.push(mobileValidator);
4269
+ break;
4270
+ case "phone":
4271
+ case "contact":
4272
+ validators.push(phoneValidator);
4273
+ break;
4274
+ case "length":
4275
+ validators.push(maxLengthValidator(255));
4276
+ break;
4277
+ }
4278
+ } else if (typeof rule === "object" && rule !== null) {
4279
+ if ("minLength" in rule) validators.push(minLengthValidator(rule.minLength));
4280
+ if ("maxLength" in rule) validators.push(maxLengthValidator(rule.maxLength));
4281
+ if ("minDate" in rule) validators.push(minDateValidator(rule.minDate));
4282
+ if ("maxDate" in rule) validators.push(maxDateValidator(rule.maxDate));
4283
+ }
4284
+ }
4285
+ return validators;
4286
+ }
4287
+ function getErrorMessage(error) {
4288
+ switch (error.key) {
4289
+ case "required":
4290
+ return "This field is required.";
4291
+ case "minlength":
4292
+ return `Minimum length is ${error.requiredLength ?? 0} characters.`;
4293
+ case "maxlength":
4294
+ return `Maximum length is ${error.requiredLength ?? 0} characters.`;
4295
+ case "email":
4296
+ return "Enter a valid email address.";
4297
+ case "pattern":
4298
+ return error.message ?? "Invalid format.";
4299
+ case "minDate":
4300
+ return error.message ?? "Date cannot be in the past.";
4301
+ case "maxDate":
4302
+ return error.message ?? "Date cannot be in the future.";
4303
+ case "invalidDate":
4304
+ return error.message ?? "Enter a valid date.";
4305
+ default:
4306
+ return error.message ?? "Invalid input.";
4307
+ }
4308
+ }
4309
+ function getInputType(field) {
4310
+ if (field.type === "number" && Array.isArray(field.validation) && field.validation.some((v) => typeof v === "string" && ["phone", "mobile", "contact"].includes(v))) {
4311
+ return "tel";
4312
+ }
4313
+ return field.type;
4314
+ }
4315
+ var SESSION_STORAGE_KEY = "form_builder_answers";
4316
+ function getAnswerStore() {
4317
+ try {
4318
+ const raw = sessionStorage.getItem(SESSION_STORAGE_KEY);
4319
+ return raw ? JSON.parse(raw) : {};
4320
+ } catch {
4321
+ return {};
4322
+ }
4323
+ }
4324
+ function getStoredAnswer(formId, fieldName) {
4325
+ const store = getAnswerStore();
4326
+ const value = store?.[formId]?.[fieldName];
4327
+ return value != null ? String(value) : null;
4328
+ }
4329
+ function persistAnswer(formId, fieldName, value) {
4330
+ if (!formId) return;
4331
+ const store = getAnswerStore();
4332
+ if (!store[formId]) store[formId] = {};
4333
+ store[formId][fieldName] = value;
4334
+ try {
4335
+ sessionStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(store));
4336
+ } catch (err) {
4337
+ console.warn("[FormBuilder] Failed to persist answer to sessionStorage:", err);
4338
+ }
4339
+ }
4340
+ function SchemaFormBuilder(props) {
4341
+ const {
4342
+ formId,
4343
+ appConfig,
4344
+ currentPage,
4345
+ companyId,
4346
+ formData,
4347
+ showSubmit: showSubmitProp,
4348
+ formUpdateId,
4349
+ initialSchema,
4350
+ onFormSubmit,
4351
+ onFormStatus,
4352
+ onSchema,
4353
+ onCompanySet,
4354
+ onServiceSet,
4355
+ onResourceSet,
4356
+ onStaffSet,
4357
+ onAddDuration,
4358
+ onFormReady,
4359
+ onUpdateDatastore,
4360
+ onAddressSet,
4361
+ onAwsLookupSet,
4362
+ onExtraItemSet,
4363
+ onExtraItemChanged,
4364
+ onVenueSet,
4365
+ onProcessing
4366
+ } = props;
4367
+ const [formValues, setFormValues] = react.useState({});
4368
+ const [formFields, setFormFields] = react.useState([]);
4369
+ const [schema, setSchema] = react.useState(null);
4370
+ const [showSubmit, setShowSubmit] = react.useState(showSubmitProp ?? false);
4371
+ const [loading, setLoading] = react.useState(true);
4372
+ const [suggestions, setSuggestions] = react.useState([]);
4373
+ const [, _setSearching] = react.useState(false);
4374
+ const [searchText, setSearchText] = react.useState("");
4375
+ const [touchedFields, setTouchedFields] = react.useState(/* @__PURE__ */ new Set());
4376
+ const [dirtyFields, setDirtyFields] = react.useState(/* @__PURE__ */ new Set());
4377
+ const formServicesRef = react.useRef({});
4378
+ const extraItemsRef = react.useRef([]);
4379
+ const pendingExtraItemFetchesRef = react.useRef(/* @__PURE__ */ new Set());
4380
+ const venueSearchTimerRef = react.useRef(null);
4381
+ const activeFormIdRef = react.useRef("");
4382
+ const initialisedRef = react.useRef(false);
4383
+ const validatorMapRef = react.useRef(/* @__PURE__ */ new Map());
4384
+ react.useEffect(() => {
4385
+ if (initialisedRef.current && formUpdateId === activeFormIdRef.current && !initialSchema) return;
4386
+ initialisedRef.current = true;
4387
+ activeFormIdRef.current = formUpdateId ?? formId;
4388
+ initialiseForm(formUpdateId ?? formId);
4389
+ }, [formId, formUpdateId, initialSchema]);
4390
+ react.useEffect(() => {
4391
+ if (formFields.length > 0) {
4392
+ refreshVisibility();
4393
+ }
4394
+ if (formFields.length > 0) {
4395
+ const errors = [];
4396
+ for (const field of formFields) {
4397
+ if (field.page !== currentPage) continue;
4398
+ if (!field.visible && !field.is_visible) continue;
4399
+ const value = formValues[field.field] ?? "";
4400
+ const fieldErrors = validateField(field, value);
4401
+ if (fieldErrors) {
4402
+ errors.push({ fieldName: field.field, errors: fieldErrors });
4403
+ }
4404
+ }
4405
+ const serviceSetField = formFields.find(
4406
+ (f) => f.page === currentPage && f.service_set && (f.visible || f.is_visible)
4407
+ );
4408
+ onFormStatus?.({
4409
+ status: errors.length === 0,
4410
+ errors,
4411
+ formData: formValues,
4412
+ extraItems: extraItemsRef.current,
4413
+ setService: serviceSetField?.service_set
4414
+ });
4415
+ }
4416
+ }, [formValues]);
4417
+ react.useEffect(() => {
4418
+ if (!formFields.length) return;
4419
+ const visibleFieldsWithExtraItems = formFields.filter(
4420
+ (f) => f.page === currentPage && (f.visible || f.is_visible) && (f["extra-item"] || f.resource_ids)
4421
+ );
4422
+ for (const field of visibleFieldsWithExtraItems) {
4423
+ void setExtraItems(field);
4424
+ }
4425
+ }, [formFields, formValues]);
4426
+ react.useEffect(() => {
4427
+ return () => {
4428
+ if (venueSearchTimerRef.current) {
4429
+ clearTimeout(venueSearchTimerRef.current);
4430
+ }
4431
+ };
4432
+ }, []);
4433
+ const setFieldValue = react.useCallback(
4434
+ (fieldName, value, _options) => {
4435
+ setFormValues((prev) => ({ ...prev, [fieldName]: value }));
4436
+ persistAnswer(formId, fieldName, value);
4437
+ },
4438
+ [formId]
4439
+ );
4440
+ async function initialiseForm(resolvedFormId) {
4441
+ var _a;
4442
+ setLoading(true);
4443
+ setFormFields([]);
4444
+ setFormValues({});
4445
+ setSchema(null);
4446
+ setShowSubmit(false);
4447
+ extraItemsRef.current = [];
4448
+ pendingExtraItemFetchesRef.current = /* @__PURE__ */ new Set();
4449
+ (_a = formServicesRef.current)[resolvedFormId] ?? (_a[resolvedFormId] = {});
4450
+ let result;
4451
+ if (initialSchema) {
4452
+ result = initialSchema;
4453
+ } else {
4454
+ const apiResult = await getFormSchema(resolvedFormId, appConfig);
4455
+ if (isApiError(apiResult)) {
4456
+ console.error("[FormBuilder] Failed to fetch form schema:", apiResult.message);
4457
+ setLoading(false);
4458
+ return;
4459
+ }
4460
+ result = apiResult;
4461
+ }
4462
+ const rawFields = result.schema.fields.filter((f) => f.field !== "haf_id");
4463
+ const hydrated = rawFields.map((f) => hydrateField(f, currentPage));
4464
+ const initialValues = {};
4465
+ for (const field of hydrated) {
4466
+ if (!field.show_on_this_page) continue;
4467
+ initialValues[field.field] = "";
4468
+ if (field.address_lookup) {
4469
+ initialValues[`${field.field}_postcode`] = "";
4470
+ }
4471
+ }
4472
+ if (formData) {
4473
+ for (const [key, value] of Object.entries(formData)) {
4474
+ if (key in initialValues) {
4475
+ initialValues[key] = String(value ?? "");
4476
+ }
4477
+ }
4478
+ }
4479
+ const copyDataTargets = /* @__PURE__ */ new Set();
4480
+ for (const field of hydrated) {
4481
+ if (field.copy_data?.to) {
4482
+ for (const target of field.copy_data.to) {
4483
+ copyDataTargets.add(target);
4484
+ }
4485
+ }
4486
+ }
4487
+ if (copyDataTargets.size > 0) {
4488
+ const storedAnswers = getAnswerStore()[resolvedFormId] ?? {};
4489
+ for (const target of copyDataTargets) {
4490
+ if (target in initialValues && !initialValues[target] && storedAnswers[target] != null) {
4491
+ initialValues[target] = String(storedAnswers[target]);
4492
+ }
4493
+ }
4494
+ }
4495
+ validatorMapRef.current = /* @__PURE__ */ new Map();
4496
+ for (const field of hydrated) {
4497
+ validatorMapRef.current.set(field.field, buildValidators(field));
4498
+ }
4499
+ setSchema(result);
4500
+ setFormFields(hydrated);
4501
+ setFormValues(initialValues);
4502
+ setTouchedFields(/* @__PURE__ */ new Set());
4503
+ setDirtyFields(/* @__PURE__ */ new Set());
4504
+ onFormReady?.({
4505
+ form_id: resolvedFormId,
4506
+ extra_items: extraItemsRef.current
4507
+ });
4508
+ setLoading(false);
4509
+ }
4510
+ function validateField(field, value) {
4511
+ if (!field.visible && !field.is_visible) return null;
4512
+ const validators = validatorMapRef.current.get(field.field) ?? buildValidators(field);
4513
+ for (const validator of validators) {
4514
+ const error = validator(value);
4515
+ if (error) return error;
4516
+ }
4517
+ return null;
4518
+ }
4519
+ function markAsTouched(fieldName) {
4520
+ setTouchedFields((prev) => new Set(prev).add(fieldName));
4521
+ }
4522
+ function markAsDirty(fieldName) {
4523
+ setDirtyFields((prev) => new Set(prev).add(fieldName));
4524
+ }
4525
+ function markAllAsTouched() {
4526
+ const allFieldNames = formFields.filter((f) => f.show_on_this_page).map((f) => f.field);
4527
+ setTouchedFields(new Set(allFieldNames));
4528
+ }
4529
+ function shouldShowError(fieldName) {
4530
+ return touchedFields.has(fieldName) || dirtyFields.has(fieldName);
4531
+ }
4532
+ function refreshVisibility() {
4533
+ if (!formFields.length) return;
4534
+ let continueVisible = false;
4535
+ const schemaType = schema?.schema?.type ?? "extended";
4536
+ const updatedFields = formFields.map((field) => {
4537
+ if (field.page !== currentPage) return field;
4538
+ const wasVisible = field.visible;
4539
+ const hasShowRules = field.show != null && Object.keys(field.show).length > 0;
4540
+ let isVisible;
4541
+ if (schemaType === "extended") {
4542
+ isVisible = hasShowRules ? evaluateExtendedConditional(field) : evaluateAlwaysVisible(field);
4543
+ } else {
4544
+ isVisible = evaluateLegacyConditional(field);
4545
+ }
4546
+ if (!isVisible && wasVisible) {
4547
+ setFormValues((prev) => {
4548
+ if (prev[field.field] === "" || prev[field.field] == null) return prev;
4549
+ const next = { ...prev, [field.field]: "" };
4550
+ return next;
4551
+ });
4552
+ }
4553
+ if (isVisible && field.continue === true) {
4554
+ continueVisible = true;
4555
+ }
4556
+ return { ...field, visible: isVisible, is_visible: isVisible };
4557
+ });
4558
+ setFormFields(updatedFields);
4559
+ setShowSubmit(continueVisible);
4560
+ }
4561
+ function evaluateAlwaysVisible(field) {
4562
+ resolveDynamicTitle(field);
4563
+ fireVisibleSideEffects(field, true);
4564
+ if (isAppointmentTypeFiltered(field)) return false;
4565
+ return true;
4566
+ }
4567
+ function evaluateExtendedConditional(field) {
4568
+ resolveDynamicTitle(field);
4569
+ const rules = field.show;
4570
+ const customResults = [];
4571
+ const simpleResults = [];
4572
+ if ("custom_all_lookups_successful" in rules) {
4573
+ customResults.push(checkAllLookupsSuccessful(field.field));
4574
+ }
4575
+ if (rules.custom) {
4576
+ customResults.push(evaluateCustomCondition(rules.custom));
4577
+ }
4578
+ if (rules.custom_multiple_condition) {
4579
+ customResults.push(evaluateAndGroup(rules.custom_multiple_condition));
4580
+ }
4581
+ if (rules.custom_multiple_conditions) {
4582
+ customResults.push(evaluateOrOfAndGroups(rules.custom_multiple_conditions));
4583
+ }
4584
+ if (rules.custom_or_condition) {
4585
+ customResults.push(evaluateOrGroup(rules.custom_or_condition));
4586
+ }
4587
+ const RESERVED_RULE_KEYS = /* @__PURE__ */ new Set([
4588
+ "custom",
4589
+ "custom_multiple_condition",
4590
+ "custom_multiple_conditions",
4591
+ "custom_or_condition",
4592
+ "custom_all_lookups_successful"
4593
+ ]);
4594
+ for (const [targetField, expectedValue] of Object.entries(rules)) {
4595
+ if (RESERVED_RULE_KEYS.has(targetField)) continue;
4596
+ simpleResults.push(evaluateSimpleRule(targetField, expectedValue));
4597
+ }
4598
+ let isVisible;
4599
+ const simplePass = simpleResults.length === 0 || simpleResults.some((r) => r);
4600
+ const customPass = customResults.length === 0 || customResults.every((r) => r);
4601
+ if (simpleResults.length > 0 && customResults.length > 0) {
4602
+ isVisible = simplePass && customPass;
4603
+ } else if (customResults.length > 0) {
4604
+ isVisible = customPass;
4605
+ } else {
4606
+ isVisible = simplePass;
4607
+ }
4608
+ fireVisibleSideEffects(field, isVisible);
4609
+ if (isVisible && isAppointmentTypeFiltered(field)) return false;
4610
+ if (isVisible && field.appointment_type && currentPage === "services") {
4611
+ const stored = sessionStorage.getItem("appointment_type");
4612
+ if (!stored) {
4613
+ sessionStorage.setItem("appointment_type", field.appointment_type);
4614
+ }
4615
+ }
4616
+ return isVisible;
4617
+ }
4618
+ function evaluateSimpleRule(targetField, expectedValue) {
4619
+ const currentValue = formValues[targetField] ?? "";
4620
+ if (expectedValue === "*") {
4621
+ return currentValue !== "" && currentValue !== null && currentValue !== void 0;
4622
+ }
4623
+ if (typeof expectedValue === "string" && expectedValue.includes(" OR ")) {
4624
+ const options = expectedValue.split(" OR ").map((s) => s.trim());
4625
+ return options.some((opt) => {
4626
+ if (opt === "*") return currentValue !== "" && currentValue != null;
4627
+ return String(currentValue) === opt;
4628
+ });
4629
+ }
4630
+ return String(currentValue) === String(expectedValue);
4631
+ }
4632
+ function resolveNumericForComparison(fieldName, rawValue) {
4633
+ const field = formFields.find((f) => f.field === fieldName);
4634
+ if (field?.type === "date" && rawValue) {
4635
+ const dateVal = new Date(rawValue);
4636
+ if (isValid(dateVal)) {
4637
+ const today = startOfDay(/* @__PURE__ */ new Date());
4638
+ const target = startOfDay(dateVal);
4639
+ const diffMs = target.getTime() - today.getTime();
4640
+ return Math.round(diffMs / (1e3 * 60 * 60 * 24));
4641
+ }
4642
+ }
4643
+ return Number(rawValue);
4644
+ }
4645
+ function evaluateCustomExpression(fieldName, expression) {
4646
+ const rawValue = formValues[fieldName] ?? "";
4647
+ if (expression === "*") {
4648
+ return rawValue !== "" && rawValue != null;
4649
+ }
4650
+ if (expression.includes(" and ")) {
4651
+ const parts = expression.split(" and ").map((s) => s.trim());
4652
+ return parts.every((part) => evaluateCustomExpression(fieldName, part));
4653
+ }
4654
+ const match2 = expression.trim().match(/^([<>!=]=?)\s*(.+)$/);
4655
+ if (match2) {
4656
+ const [, operator, operand] = match2;
4657
+ const numericValue = resolveNumericForComparison(fieldName, rawValue);
4658
+ const numericOperand = Number(operand.trim());
4659
+ switch (operator) {
4660
+ case "<":
4661
+ return numericValue < numericOperand;
4662
+ case ">":
4663
+ return numericValue > numericOperand;
4664
+ case "<=":
4665
+ return numericValue <= numericOperand;
4666
+ case ">=":
4667
+ return numericValue >= numericOperand;
4668
+ case "==":
4669
+ return String(rawValue) === operand.trim();
4670
+ case "!=":
4671
+ return String(rawValue) !== operand.trim();
4672
+ default:
4673
+ return false;
4674
+ }
4675
+ }
4676
+ return String(rawValue) === expression.trim();
4677
+ }
4678
+ function evaluateCustomCondition(custom) {
4679
+ if (Array.isArray(custom)) {
4680
+ return custom.every((clause) => evaluateClause(clause));
4681
+ }
4682
+ if (typeof custom === "object" && custom !== null) {
4683
+ const entries = Object.entries(custom);
4684
+ return entries.every(
4685
+ ([fieldName, expression]) => evaluateCustomExpression(fieldName, String(expression))
4686
+ );
4687
+ }
4688
+ return false;
4689
+ }
4690
+ function evaluateAndGroup(data) {
4691
+ if (Array.isArray(data)) {
4692
+ return data.every((clause) => evaluateClause(clause));
4693
+ }
4694
+ if (typeof data === "object" && data !== null && "conditions" in data) {
4695
+ const conditions = data.conditions;
4696
+ return conditions.every((condObj) => {
4697
+ const entries = Object.entries(condObj);
4698
+ return entries.every(
4699
+ ([fieldName, expectedValue]) => evaluateSimpleRule(fieldName, String(expectedValue))
4700
+ );
4701
+ });
4702
+ }
4703
+ return false;
4704
+ }
4705
+ function evaluateOrOfAndGroups(data) {
4706
+ if (Array.isArray(data)) {
4707
+ return data.some(
4708
+ (group) => Array.isArray(group) && group.every((clause) => evaluateClause(clause))
4709
+ );
4710
+ }
4711
+ if (typeof data === "object" && data !== null && "groups" in data) {
4712
+ const groups = data.groups;
4713
+ return groups.some((group) => {
4714
+ if (!group.conditions || !Array.isArray(group.conditions)) return false;
4715
+ return group.conditions.every((condObj) => {
4716
+ const entries = Object.entries(condObj);
4717
+ return entries.every(
4718
+ ([fieldName, expectedValue]) => evaluateSimpleRule(fieldName, String(expectedValue))
4719
+ );
4720
+ });
4721
+ });
4722
+ }
4723
+ return false;
4724
+ }
4725
+ function evaluateOrGroup(clauses) {
4726
+ return clauses.some((clause) => evaluateClause(clause));
4727
+ }
4728
+ function evaluateClause(clause) {
4729
+ const rawValue = formValues[clause.field] ?? "";
4730
+ const operator = clause.operator ?? "==";
4731
+ if (clause.value === "*") {
4732
+ return rawValue !== "" && rawValue != null;
4733
+ }
4734
+ switch (operator) {
4735
+ case "==":
4736
+ return String(rawValue) === String(clause.value);
4737
+ case "!=":
4738
+ return String(rawValue) !== String(clause.value);
4739
+ case ">":
4740
+ return Number(rawValue) > Number(clause.value);
4741
+ case "<":
4742
+ return Number(rawValue) < Number(clause.value);
4743
+ case ">=":
4744
+ return Number(rawValue) >= Number(clause.value);
4745
+ case "<=":
4746
+ return Number(rawValue) <= Number(clause.value);
4747
+ default:
4748
+ return false;
4749
+ }
4750
+ }
4751
+ function checkAllLookupsSuccessful(excludeFieldName) {
4752
+ const allLookupFields = formFields.filter(
4753
+ (f) => f.lookup?.aws_table && f.page === currentPage
4754
+ );
4755
+ const visibleLookupFields = allLookupFields.filter(
4756
+ (f) => (f.visible === true || f.is_visible === true) && f.field !== excludeFieldName
4757
+ );
4758
+ if (visibleLookupFields.length === 0) return false;
4759
+ return visibleLookupFields.every((f) => f.lookupSuccess === true);
4760
+ }
4761
+ function resolveDynamicTitle(field) {
4762
+ const TOKEN_REGEX = /\{([^}]+)\}/g;
4763
+ field.rendered_title = field.title.replace(TOKEN_REGEX, (_, fieldName) => {
4764
+ const value = formValues[fieldName];
4765
+ return value != null && value !== "" ? String(value) : "";
4766
+ });
4767
+ }
4768
+ function isAppointmentTypeFiltered(field) {
4769
+ if (currentPage !== "booking-details") return false;
4770
+ if (!field.appointment_type) return false;
4771
+ const storedType = sessionStorage.getItem("appointment_type");
4772
+ if (!storedType) return false;
4773
+ return field.appointment_type !== storedType;
4774
+ }
4775
+ function evaluateLegacyConditional(field) {
4776
+ if (!field.conditional) {
4777
+ resolveDynamicTitle(field);
4778
+ fireVisibleSideEffects(field, true);
4779
+ return true;
4780
+ }
4781
+ if (!field.trigger || !field.trigger_value) {
4782
+ return true;
4783
+ }
4784
+ const triggerFields = field.trigger.split("|");
4785
+ const triggerExpressions = String(field.trigger_value).split("|");
4786
+ const results = [];
4787
+ triggerFields.forEach((triggerFieldName, i) => {
4788
+ const expression = triggerExpressions[i] ?? "";
4789
+ const parts = expression.split("&");
4790
+ for (const part of parts) {
4791
+ const trimmedPart = part.trim();
4792
+ const parentValue = formValues[triggerFieldName] ?? "";
4793
+ if (trimmedPart === "*") {
4794
+ results.push(parentValue !== "" && parentValue != null && parentValue !== void 0);
4795
+ continue;
4796
+ }
4797
+ const firstChar = trimmedPart[0];
4798
+ if (["<", ">", "!"].includes(firstChar)) {
4799
+ const operand = Number(trimmedPart.substring(1));
4800
+ const numericParentValue = Number(parentValue);
4801
+ switch (firstChar) {
4802
+ case "<":
4803
+ if (numericParentValue < operand) results.push(true);
4804
+ break;
4805
+ case ">":
4806
+ if (numericParentValue > operand) results.push(true);
4807
+ break;
4808
+ case "!":
4809
+ if (String(parentValue) !== String(operand)) results.push(true);
4810
+ break;
4811
+ }
4812
+ } else {
4813
+ results.push(String(parentValue) === String(trimmedPart));
4814
+ }
4815
+ }
4816
+ });
4817
+ const isVisible = results.filter(Boolean).length >= 1;
4818
+ fireVisibleSideEffects(field, isVisible);
4819
+ return isVisible;
4820
+ }
4821
+ const BOOKER_FIELD_KEYS = [
4822
+ "booker_first_name",
4823
+ "booker_last_name",
4824
+ "booker_email",
4825
+ "booker_phone"
4826
+ ];
4827
+ function fireVisibleSideEffects(field, isVisible) {
4828
+ if (isVisible) {
4829
+ handleCompanySet(field);
4830
+ handleServiceSet(field);
4831
+ handleResourceSet(field);
4832
+ handleStaffSet(field);
4833
+ handleAddDuration(field);
4834
+ handleBookerFields(field);
4835
+ handleCopyData(field);
4836
+ handleAppointmentTypeStore(field);
4837
+ } else {
4838
+ handleRemoveDuration(field);
4839
+ }
4840
+ }
4841
+ function handleCompanySet(field) {
4842
+ var _a;
4843
+ if (!field.company_set || !field.company_set.length) return;
4844
+ const formService = (_a = formServicesRef.current)[formId] ?? (_a[formId] = {});
4845
+ if (formService.company_id === field.company_set) return;
4846
+ formService.company_id = field.company_set;
4847
+ field.company_id = field.company_set;
4848
+ onCompanySet?.(field.company_set);
4849
+ }
4850
+ function handleServiceSet(field) {
4851
+ var _a;
4852
+ if (!field.service_set) return;
4853
+ const formService = (_a = formServicesRef.current)[formId] ?? (_a[formId] = {});
4854
+ if (formService.service_id === field.service_set) return;
4855
+ formService.service_id = field.service_set;
4856
+ field.service_id = field.service_set;
4857
+ onServiceSet?.(field.service_set);
4858
+ }
4859
+ function handleResourceSet(field) {
4860
+ var _a;
4861
+ if (!field.resource_set || !field.resource_set.length) return;
4862
+ const formService = (_a = formServicesRef.current)[formId] ?? (_a[formId] = {});
4863
+ if (formService.resource_id === field.resource_set) return;
4864
+ formService.resource_id = field.resource_set;
4865
+ field.resource_id = field.resource_set;
4866
+ onResourceSet?.(field.resource_set);
4867
+ }
4868
+ function handleStaffSet(field) {
4869
+ if (!field.staff_set || !field.staff_set.length) return;
4870
+ onStaffSet?.(field.staff_set);
4871
+ }
4872
+ function handleAddDuration(field) {
4873
+ if (!field.add_duration) return;
4874
+ if (field.duration_added) return;
4875
+ field.duration_added = true;
4876
+ onAddDuration?.(field.add_duration);
4877
+ }
4878
+ function handleRemoveDuration(field) {
4879
+ if (!field.add_duration) return;
4880
+ if (!field.duration_added) return;
4881
+ field.duration_added = false;
4882
+ onAddDuration?.(String(-Number(field.add_duration)));
4883
+ }
4884
+ function handleBookerFields(field) {
4885
+ for (const key of BOOKER_FIELD_KEYS) {
4886
+ const isMarked = field[key] === true || field[key] === "true";
4887
+ if (!isMarked) continue;
4888
+ const value = formValues[field.field];
4889
+ if (value) {
4890
+ onUpdateDatastore?.({ [key]: value });
4891
+ }
4892
+ }
4893
+ }
4894
+ function handleCopyData(field) {
4895
+ const copyData = field.copy_data;
4896
+ if (!copyData?.from || !copyData?.to) return;
4897
+ const currentValue = formValues[field.field] ?? "";
4898
+ let shouldCopy;
4899
+ if (copyData.answer !== void 0 && copyData.answer !== null) {
4900
+ shouldCopy = String(currentValue) === String(copyData.answer);
4901
+ } else {
4902
+ shouldCopy = currentValue !== "" && currentValue != null;
4903
+ }
4904
+ if (!shouldCopy) return;
4905
+ copyData.from.forEach((fromFieldName, index) => {
4906
+ const toFieldName = copyData.to[index];
4907
+ if (!toFieldName) return;
4908
+ const sourceValue = formValues[fromFieldName] ?? getStoredAnswer(formId, fromFieldName);
4909
+ if (sourceValue == null || sourceValue === "") return;
4910
+ if (toFieldName in formValues) {
4911
+ const existingValue = formValues[toFieldName];
4912
+ if (!existingValue) {
4913
+ setFormValues((prev) => ({ ...prev, [toFieldName]: sourceValue }));
4914
+ }
4915
+ }
4916
+ persistAnswer(formId, toFieldName, sourceValue);
4917
+ });
4918
+ }
4919
+ function handleAppointmentTypeStore(field) {
4920
+ if (!field.appointment_type) return;
4921
+ if (currentPage !== "services") return;
4922
+ const existing = sessionStorage.getItem("appointment_type");
4923
+ if (!existing) {
4924
+ sessionStorage.setItem("appointment_type", field.appointment_type);
4925
+ }
4926
+ }
4927
+ async function setExtraItems(field) {
4928
+ if (field.page !== currentPage) return;
4929
+ if (!field.visible && !field.is_visible) return;
4930
+ let extraItemId = field["extra-item"] ?? "";
4931
+ const serviceId = field["service-id"] ?? "";
4932
+ if (field.resource_ids) {
4933
+ const activeResourceId = formServicesRef.current[formId]?.resource_id;
4934
+ if (activeResourceId) {
4935
+ const resourceEntry = field.resource_ids[activeResourceId];
4936
+ if (resourceEntry?.["extra-item"]) {
4937
+ extraItemId = resourceEntry["extra-item"];
4938
+ }
4939
+ }
4940
+ }
4941
+ if (!extraItemId) return;
4942
+ const rawValue = field.type === "heading" ? "1" : formValues[field.field] ?? "0";
4943
+ const numericValue = Number(rawValue);
4944
+ let shouldBeActive;
4945
+ if (isNaN(numericValue)) {
4946
+ const boolResult = evaluateBooleanCondition(rawValue);
4947
+ if (boolResult !== void 0) {
4948
+ shouldBeActive = boolResult;
4949
+ } else {
4950
+ const firstShowKey = field.show ? Object.keys(field.show)[0] : null;
4951
+ shouldBeActive = firstShowKey != null ? String(field.show[firstShowKey]) === String(rawValue) : false;
4952
+ }
4953
+ } else {
4954
+ shouldBeActive = numericValue > 0;
4955
+ }
4956
+ const existingEntry = extraItemsRef.current.find(
4957
+ (item) => item.extraItemId === extraItemId
4958
+ );
4959
+ if (!existingEntry) {
4960
+ if (!shouldBeActive) return;
4961
+ const activeServiceId = formServicesRef.current[formId]?.service_id;
4962
+ if (!activeServiceId) {
4963
+ console.error(
4964
+ "[FormBuilder] Cannot fetch extra item \u2014 no service_id set for form:",
4965
+ formId
4966
+ );
4967
+ return;
4968
+ }
4969
+ if (pendingExtraItemFetchesRef.current.has(extraItemId)) {
4970
+ console.log("[FormBuilder] Skipping duplicate extra item fetch for:", extraItemId);
4971
+ return;
4972
+ }
4973
+ pendingExtraItemFetchesRef.current.add(extraItemId);
4974
+ onProcessing?.(true);
4975
+ const result = await getExtraItemProperties(
4976
+ extraItemId,
4977
+ companyId,
4978
+ activeServiceId,
4979
+ appConfig
4980
+ );
4981
+ pendingExtraItemFetchesRef.current.delete(extraItemId);
4982
+ if (isApiError(result)) {
4983
+ console.error("[FormBuilder] Failed to fetch extra item:", result.message);
4984
+ onProcessing?.(false);
4985
+ return;
4986
+ }
4987
+ const qty = field.type === "heading" ? 1 : numericValue;
4988
+ extraItemsRef.current.push({
4989
+ field: field.field,
4990
+ serviceId,
4991
+ extraItemId,
4992
+ qty
4993
+ });
4994
+ onExtraItemSet?.({
4995
+ item_id: extraItemId,
4996
+ item: { ...result, qty, field: field.field }
4997
+ });
4998
+ onProcessing?.(false);
4999
+ } else if (!shouldBeActive) {
5000
+ extraItemsRef.current = extraItemsRef.current.filter(
5001
+ (item) => item.extraItemId !== extraItemId
5002
+ );
5003
+ onExtraItemSet?.({ item_id: extraItemId, item: null });
5004
+ } else if (existingEntry.qty !== numericValue && field.type !== "heading") {
5005
+ extraItemsRef.current = extraItemsRef.current.filter(
5006
+ (item) => item.extraItemId !== extraItemId
5007
+ );
5008
+ const updatedEntry = {
5009
+ field: field.field,
5010
+ serviceId,
5011
+ extraItemId,
5012
+ qty: numericValue
5013
+ };
5014
+ extraItemsRef.current.push(updatedEntry);
5015
+ onExtraItemChanged?.({ item_id: extraItemId, item: updatedEntry });
5016
+ }
5017
+ }
5018
+ function evaluateBooleanCondition(value) {
5019
+ const normalised = value?.toLowerCase().trim();
5020
+ if (["true", "yes", "1"].includes(normalised)) return true;
5021
+ if (["false", "no", "0", ""].includes(normalised)) return false;
5022
+ return void 0;
5023
+ }
5024
+ const UK_POSTCODE_REGEX = /^([Gg][Ii][Rr] 0[Aa]{2}|((([A-Za-z][0-9]{1,2})|([A-Za-z][A-HJ-Ya-hj-y][0-9]{1,2})|([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-HJ-Ya-hj-y][0-9]?[A-Za-z]))\s?[0-9][A-Za-z]{2}))$/;
5025
+ function isValidUkPostcode(postcode) {
5026
+ return UK_POSTCODE_REGEX.test(postcode.trim());
5027
+ }
5028
+ function updateFieldState(fieldName, updates) {
5029
+ setFormFields(
5030
+ (prev) => prev.map((f) => f.field === fieldName ? { ...f, ...updates } : f)
5031
+ );
5032
+ }
5033
+ async function performAddressLookup(fieldName) {
5034
+ const field = formFields.find((f) => f.field === fieldName);
5035
+ if (!field) return;
5036
+ const postcodeKey = `${fieldName}_postcode`;
5037
+ const postcodeValue = (formValues[postcodeKey] ?? "").trim();
5038
+ updateFieldState(fieldName, { badPostcode: false, addresses: void 0 });
5039
+ if (!postcodeValue) {
5040
+ updateFieldState(fieldName, { badPostcode: true });
5041
+ return;
5042
+ }
5043
+ if (!isValidUkPostcode(postcodeValue)) {
5044
+ console.error(`[FormBuilder] Invalid postcode format for field "${fieldName}": ${postcodeValue}`);
5045
+ updateFieldState(fieldName, { badPostcode: true });
5046
+ return;
5047
+ }
5048
+ updateFieldState(fieldName, { addressLoading: true });
5049
+ onProcessing?.(true);
5050
+ const result = await getAddressLookup(postcodeValue, appConfig);
5051
+ if (isApiError(result)) {
5052
+ console.error("[FormBuilder] Address lookup failed:", result.message);
5053
+ updateFieldState(fieldName, { addressLoading: false, badPostcode: true });
5054
+ onProcessing?.(false);
5055
+ return;
5056
+ }
5057
+ const addresses = result.map((item) => ({
5058
+ address: item.DPA ?? item.LPI ?? { ADDRESS: "" }
5059
+ }));
5060
+ updateFieldState(fieldName, { addressLoading: false, addresses });
5061
+ onProcessing?.(false);
5062
+ }
5063
+ function handleAddressSelected(event, fieldName) {
5064
+ const selectedAddress = event.target.value;
5065
+ setFieldValue(fieldName, selectedAddress);
5066
+ updateFieldState(fieldName, { selected_address: selectedAddress });
5067
+ onAddressSet?.(selectedAddress);
5068
+ }
5069
+ async function performAwsLookup(fieldName) {
5070
+ const field = formFields.find((f) => f.field === fieldName);
5071
+ if (!field?.lookup?.aws_table) return;
5072
+ const lookup = field.lookup;
5073
+ const matchFields = lookup.match ?? [];
5074
+ updateFieldState(fieldName, {
5075
+ lookupError: false,
5076
+ lookupUsed: false,
5077
+ lookupLoading: true,
5078
+ lookupResponse: null,
5079
+ lookupNameMismatch: false
5080
+ });
5081
+ let primaryReference = "";
5082
+ let primaryDynamoField = "";
5083
+ let secondaryReference = "";
5084
+ let secondaryDynamoField = "";
5085
+ for (const match2 of matchFields) {
5086
+ const { form_field, dynamodb_field } = match2;
5087
+ const value = formValues[form_field] ?? getStoredAnswer(formId, form_field) ?? "";
5088
+ if (form_field === fieldName) {
5089
+ primaryReference = value;
5090
+ primaryDynamoField = dynamodb_field;
5091
+ } else if (!secondaryReference) {
5092
+ secondaryReference = value;
5093
+ secondaryDynamoField = dynamodb_field;
5094
+ }
5095
+ }
5096
+ if (!primaryReference) {
5097
+ console.error(`[FormBuilder] No reference value for field "${fieldName}"`);
5098
+ updateFieldState(fieldName, { lookupError: true, lookupLoading: false });
5099
+ return;
5100
+ }
5101
+ const result = await awsLookup(
5102
+ appConfig,
5103
+ lookup.aws_table,
5104
+ primaryDynamoField,
5105
+ primaryReference,
5106
+ secondaryReference || void 0,
5107
+ secondaryDynamoField || void 0
5108
+ );
5109
+ if (isApiError(result)) {
5110
+ console.error(`[FormBuilder] AWS lookup error for field "${fieldName}":`, result.message);
5111
+ updateFieldState(fieldName, { lookupError: true, lookupLoading: false });
5112
+ return;
5113
+ }
5114
+ updateFieldState(fieldName, { lookupLoading: false });
5115
+ if (result.custom_response_code !== 1) {
5116
+ updateFieldState(fieldName, { lookupError: true });
5117
+ return;
5118
+ }
5119
+ if (result.reference?.used === true) {
5120
+ updateFieldState(fieldName, { lookupUsed: true, lookupError: true });
5121
+ return;
5122
+ }
5123
+ if (secondaryReference && secondaryDynamoField === "name" && result.reference?.name) {
5124
+ const responseName = result.reference.name.toLowerCase().trim();
5125
+ const enteredName = secondaryReference.toLowerCase().trim();
5126
+ if (responseName !== enteredName) {
5127
+ updateFieldState(fieldName, { lookupNameMismatch: true, lookupError: true });
5128
+ return;
5129
+ }
5130
+ }
5131
+ const updatedFields = formFields.map((f) => {
5132
+ const isSecondaryMatch = matchFields.some(
5133
+ (m) => m.form_field === f.field && m.form_field !== fieldName
5134
+ );
5135
+ return isSecondaryMatch ? { ...f, lookupValidated: true } : f;
5136
+ });
5137
+ const storedFieldKey = lookup.store_response_field;
5138
+ let resolvedValue;
5139
+ if (storedFieldKey && result.reference?.[storedFieldKey]) {
5140
+ resolvedValue = String(result.reference[storedFieldKey]);
5141
+ } else if (result.reference?.home_office) {
5142
+ resolvedValue = result.reference.home_office;
5143
+ } else {
5144
+ resolvedValue = primaryReference;
5145
+ }
5146
+ setFormFields(
5147
+ updatedFields.map(
5148
+ (f) => f.field === fieldName ? {
5149
+ ...f,
5150
+ lookupSuccess: true,
5151
+ lookupError: false,
5152
+ lookupLoading: false,
5153
+ lookupResponse: result.reference ?? null
5154
+ } : f
5155
+ )
5156
+ );
5157
+ setFieldValue(fieldName, resolvedValue);
5158
+ onAwsLookupSet?.({
5159
+ field: fieldName,
5160
+ reference: result.reference ?? null,
5161
+ success: true
5162
+ });
5163
+ onUpdateDatastore?.({
5164
+ type: "lookupResponse",
5165
+ field: fieldName,
5166
+ lookupResponse: result.reference
5167
+ });
5168
+ refreshVisibility();
5169
+ }
5170
+ function clearAwsLookup(fieldName) {
5171
+ const field = formFields.find((f) => f.field === fieldName);
5172
+ if (!field) return;
5173
+ const matchFields = field.lookup?.match ?? [];
5174
+ const updatedFields = formFields.map((f) => {
5175
+ const isSecondaryMatch = matchFields.some(
5176
+ (m) => m.form_field === f.field && m.form_field !== fieldName
5177
+ );
5178
+ if (isSecondaryMatch) {
5179
+ return { ...f, lookupValidated: false };
5180
+ }
5181
+ if (f.field === fieldName) {
5182
+ return {
5183
+ ...f,
5184
+ lookupError: false,
5185
+ lookupUsed: false,
5186
+ lookupLoading: false,
5187
+ lookupResponse: null,
5188
+ lookupSuccess: false,
5189
+ lookupNameMismatch: false
5190
+ };
5191
+ }
5192
+ return f;
5193
+ });
5194
+ setFormFields(updatedFields);
5195
+ const secondaryMatchFieldNames = matchFields.filter((m) => m.form_field !== fieldName).map((m) => m.form_field);
5196
+ setFormValues((prev) => {
5197
+ const next = { ...prev };
5198
+ for (const name of secondaryMatchFieldNames) {
5199
+ next[name] = "";
5200
+ }
5201
+ return next;
5202
+ });
5203
+ setFieldValue(fieldName, "");
5204
+ onAwsLookupSet?.({ field: fieldName, reference: null, success: false });
5205
+ }
5206
+ const VENUE_SEARCH_DEBOUNCE_MS = 500;
5207
+ async function handleVenueSearchInput(event, field) {
5208
+ const IGNORED_KEYS = /* @__PURE__ */ new Set([
5209
+ "ArrowUp",
5210
+ "ArrowDown",
5211
+ "Enter",
5212
+ "Escape",
5213
+ "Tab",
5214
+ "Shift",
5215
+ "Control",
5216
+ "Alt",
5217
+ "Meta"
5218
+ ]);
5219
+ if (IGNORED_KEYS.has(event.key)) return;
5220
+ updateFieldState(field.field, {
5221
+ selected_resource: void 0,
5222
+ searching: true,
5223
+ noResults: false,
5224
+ answer: void 0
5225
+ });
5226
+ if (venueSearchTimerRef.current) {
5227
+ clearTimeout(venueSearchTimerRef.current);
5228
+ }
5229
+ venueSearchTimerRef.current = setTimeout(async () => {
5230
+ const query = event.target.value.trim();
5231
+ setSearchText(query);
5232
+ if (!query) {
5233
+ setSuggestions([]);
5234
+ updateFieldState(field.field, { searching: false });
5235
+ return;
5236
+ }
5237
+ try {
5238
+ const result = await searchVenue(companyId, query, appConfig);
5239
+ if (isApiError(result)) {
5240
+ console.error("[FormBuilder] Venue search failed:", result.message);
5241
+ updateFieldState(field.field, { searching: false, noResults: true });
5242
+ setSuggestions([]);
5243
+ return;
5244
+ }
5245
+ let venues = result;
5246
+ if (field.filter_by) {
5247
+ const filterValue = (formValues[field.filter_by] ?? "").toLowerCase().trim();
5248
+ if (filterValue) {
5249
+ venues = venues.filter(
5250
+ (v) => v.venue_type?.toLowerCase().trim() === filterValue
5251
+ );
5252
+ }
5253
+ }
5254
+ setSuggestions(venues);
5255
+ updateFieldState(field.field, {
5256
+ searching: false,
5257
+ noResults: venues.length === 0
5258
+ });
5259
+ } catch (err) {
5260
+ console.error("[FormBuilder] Venue search error:", err);
5261
+ setSuggestions([]);
5262
+ updateFieldState(field.field, { searching: false, noResults: true });
5263
+ }
5264
+ }, VENUE_SEARCH_DEBOUNCE_MS);
5265
+ }
5266
+ function selectVenueSuggestion(suggestion, field) {
5267
+ setSuggestions([]);
5268
+ const displayName = suggestion.pretty_name ?? suggestion.venue_name;
5269
+ setSearchText(displayName);
5270
+ updateFieldState(field.field, {
5271
+ selected_resource: suggestion,
5272
+ answer: displayName,
5273
+ searching: false,
5274
+ noResults: false
5275
+ });
5276
+ setFieldValue(field.field, displayName);
5277
+ onVenueSet?.({
5278
+ venue: suggestion,
5279
+ field: field.field,
5280
+ companyId: suggestion.company_id,
5281
+ resourceId: suggestion.resource_id
5282
+ });
5283
+ }
5284
+ function clearVenueSearch(field) {
5285
+ if (venueSearchTimerRef.current) {
5286
+ clearTimeout(venueSearchTimerRef.current);
5287
+ }
5288
+ setSearchText("");
5289
+ setSuggestions([]);
5290
+ updateFieldState(field.field, {
5291
+ selected_resource: void 0,
5292
+ searching: false,
5293
+ noResults: false,
5294
+ answer: void 0
5295
+ });
5296
+ setFieldValue(field.field, "");
5297
+ onVenueSet?.({ venue: null, field: field.field });
5298
+ }
5299
+ function handleFieldChange(fieldName, value) {
5300
+ setFormValues((prev) => ({ ...prev, [fieldName]: value }));
5301
+ persistAnswer(formId, fieldName, value);
5302
+ }
5303
+ const formErrors = {};
5304
+ for (const field of formFields) {
5305
+ if (field.page !== currentPage) continue;
5306
+ if (!field.visible && !field.is_visible) continue;
5307
+ const value = formValues[field.field] ?? "";
5308
+ const error = validateField(field, value);
5309
+ if (error) formErrors[field.field] = true;
5310
+ }
5311
+ function getFieldWrapperClassName(field) {
5312
+ const classes = ["govuk-form-group"];
5313
+ const isInvalid = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
5314
+ if (isInvalid) {
5315
+ classes.push("govuk-form-group--error");
5316
+ }
5317
+ const isHidden = field.hidden_field || field.rules_count > 0 && !field.is_visible || field.lookupValidated;
5318
+ if (isHidden) {
5319
+ classes.push("hidden-field");
5320
+ }
5321
+ return classes.join(" ");
5322
+ }
5323
+ function renderLabel(field) {
5324
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "govuk-label-wrapper", children: /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "govuk-label govuk-label--m", htmlFor: field.field, children: [
5325
+ field.rendered_title ?? field.title,
5326
+ field.required && " *"
5327
+ ] }) });
5328
+ }
5329
+ function renderHint(field) {
5330
+ if (!field.helptext) return null;
5331
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { id: `${field.field}-hint`, className: "govuk-hint", dangerouslySetInnerHTML: { __html: field.helptext } });
5332
+ }
5333
+ function renderErrors(field) {
5334
+ if (!shouldShowError(field.field)) return null;
5335
+ const error = validateField(field, formValues[field.field] ?? "");
5336
+ if (!error) return null;
5337
+ return /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "govuk-error-message", children: [
5338
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
5339
+ getErrorMessage(error)
5340
+ ] });
5341
+ }
5342
+ function renderField(field) {
5343
+ switch (field.type) {
5344
+ case "text":
5345
+ case "number":
5346
+ case "email":
5347
+ case "date":
5348
+ return renderTextualField(field);
5349
+ case "textarea":
5350
+ return renderTextarea(field);
5351
+ case "radio":
5352
+ return renderRadio(field);
5353
+ case "checkbox":
5354
+ return renderCheckbox(field);
5355
+ case "dropdown":
5356
+ return renderDropdown(field);
5357
+ case "heading":
5358
+ return renderHeading(field);
5359
+ case "submit":
5360
+ return renderSubmitField(field);
5361
+ default:
5362
+ return null;
5363
+ }
5364
+ }
5365
+ function renderTextualField(field) {
5366
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5367
+ renderLabel(field),
5368
+ renderHint(field),
5369
+ renderErrors(field),
5370
+ field.address_lookup ? renderAddressLookup(field) : field.lookup?.aws_table ? renderAwsLookup(field) : field.resource_lookup ? renderVenueSearch(field) : renderPlainInput(field)
5371
+ ] });
5372
+ }
5373
+ function renderPlainInput(field) {
5374
+ const isError = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
5375
+ const inputProps = {
5376
+ id: field.field,
5377
+ type: getInputType(field),
5378
+ "aria-required": field.required,
5379
+ value: formValues[field.field] ?? "",
5380
+ className: ["govuk-input", isError ? "govuk-input--error" : ""].join(" ").trim(),
5381
+ onChange: (e) => {
5382
+ handleFieldChange(field.field, e.target.value);
5383
+ markAsDirty(field.field);
5384
+ },
5385
+ onBlur: () => markAsTouched(field.field)
5386
+ };
5387
+ if (field.type === "date" && field.hide_dates_in_future) {
5388
+ inputProps.max = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
5389
+ }
5390
+ return /* @__PURE__ */ jsxRuntime.jsx("input", { ...inputProps });
5391
+ }
5392
+ function renderTextarea(field) {
5393
+ const isError = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
5394
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5395
+ renderLabel(field),
5396
+ renderHint(field),
5397
+ renderErrors(field),
5398
+ /* @__PURE__ */ jsxRuntime.jsx(
5399
+ "textarea",
5400
+ {
5401
+ id: field.field,
5402
+ className: ["govuk-textarea", isError ? "govuk-textarea--error" : ""].join(" ").trim(),
5403
+ rows: 5,
5404
+ "aria-required": field.required,
5405
+ value: formValues[field.field] ?? "",
5406
+ onChange: (e) => {
5407
+ handleFieldChange(field.field, e.target.value);
5408
+ markAsDirty(field.field);
5409
+ },
5410
+ onBlur: () => markAsTouched(field.field)
5411
+ }
5412
+ )
5413
+ ] });
5414
+ }
5415
+ function renderRadio(field) {
5416
+ const isError = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
5417
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "govuk-form-group", children: /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className: "govuk-fieldset", "aria-required": field.required, children: [
5418
+ /* @__PURE__ */ jsxRuntime.jsxs("legend", { className: "govuk-fieldset__legend govuk-fieldset__legend--m govuk-fieldset__legend--m-inverse", children: [
5419
+ field.rendered_title ?? field.title,
5420
+ field.required && " *"
5421
+ ] }),
5422
+ renderHint(field),
5423
+ isError && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "govuk-error-message", children: [
5424
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
5425
+ getErrorMessage(validateField(field, formValues[field.field] ?? ""))
5426
+ ] }),
5427
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "govuk-radios", children: (field.radio_options ?? []).map((option) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "govuk-radios__item", children: [
5428
+ /* @__PURE__ */ jsxRuntime.jsx(
5429
+ "input",
5430
+ {
5431
+ className: "govuk-radios__input",
5432
+ type: "radio",
5433
+ id: `${field.field}_${option.value}`,
5434
+ name: field.field,
5435
+ value: option.value,
5436
+ checked: formValues[field.field] === option.value,
5437
+ onChange: () => {
5438
+ handleFieldChange(field.field, option.value);
5439
+ markAsDirty(field.field);
5440
+ markAsTouched(field.field);
5441
+ }
5442
+ }
5443
+ ),
5444
+ /* @__PURE__ */ jsxRuntime.jsx("label", { className: "govuk-label govuk-radios__label", htmlFor: `${field.field}_${option.value}`, children: option.title })
5445
+ ] }, option.value)) })
5446
+ ] }) });
5447
+ }
5448
+ function renderCheckbox(field) {
5449
+ const isError = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
5450
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "govuk-form-group", children: [
5451
+ renderHint(field),
5452
+ isError && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "govuk-error-message", children: [
5453
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
5454
+ "This field is required."
5455
+ ] }),
5456
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "govuk-checkboxes", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "govuk-checkboxes__item", children: [
5457
+ /* @__PURE__ */ jsxRuntime.jsx(
5458
+ "input",
5459
+ {
5460
+ className: "govuk-checkboxes__input",
5461
+ id: field.field,
5462
+ type: "checkbox",
5463
+ checked: formValues[field.field] === "true",
5464
+ onChange: (e) => {
5465
+ handleFieldChange(field.field, String(e.target.checked));
5466
+ markAsDirty(field.field);
5467
+ markAsTouched(field.field);
5468
+ }
5469
+ }
5470
+ ),
5471
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "govuk-label govuk-checkboxes__label govuk-label--m--inverse", htmlFor: field.field, children: [
5472
+ field.rendered_title ?? field.title,
5473
+ field.required && " *"
5474
+ ] })
5475
+ ] }) })
5476
+ ] });
5477
+ }
5478
+ function renderDropdown(field) {
5479
+ const isError = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
5480
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5481
+ renderLabel(field),
5482
+ renderHint(field),
5483
+ renderErrors(field),
5484
+ /* @__PURE__ */ jsxRuntime.jsxs(
5485
+ "select",
5486
+ {
5487
+ id: field.field,
5488
+ className: ["govuk-select govuk-select--inverse", isError ? "govuk-select--error" : ""].join(" ").trim(),
5489
+ "aria-required": field.required ? "true" : void 0,
5490
+ value: formValues[field.field] ?? "",
5491
+ onChange: (e) => {
5492
+ handleFieldChange(field.field, e.target.value);
5493
+ markAsDirty(field.field);
5494
+ markAsTouched(field.field);
5495
+ },
5496
+ children: [
5497
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: "Please select" }),
5498
+ (field.options ?? []).filter((opt) => opt.visible).map((opt) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: opt.value, children: opt.title }, opt.value))
5499
+ ]
5500
+ }
5501
+ )
5502
+ ] });
5503
+ }
5504
+ function renderHeading(field) {
5505
+ const componentType = field.component_type;
5506
+ if (componentType === "govbook-warning_box") {
5507
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "warning-box", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "content", children: [
5508
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "warning-box__title", children: field.rendered_title ?? field.title }),
5509
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "warning-box__message", dangerouslySetInnerHTML: { __html: field.component_text ?? "" } })
5510
+ ] }) });
5511
+ }
5512
+ if (componentType === "govbook-information_box") {
5513
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "information-box", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "content", children: [
5514
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "information-box__title", children: field.rendered_title ?? field.title }),
5515
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "information-box__message", dangerouslySetInnerHTML: { __html: field.component_text ?? "" } })
5516
+ ] }) });
5517
+ }
5518
+ if (componentType === "body") {
5519
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "govuk-body govuk-body--inverse", dangerouslySetInnerHTML: { __html: field.component_text ?? "" } });
5520
+ }
5521
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5522
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "govuk-heading-m govuk-heading-m--inverse", children: field.rendered_title ?? field.title }),
5523
+ renderHint(field)
5524
+ ] });
5525
+ }
5526
+ function renderSubmitField(field) {
5527
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5528
+ renderHint(field),
5529
+ showSubmit && /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "nhsuk-button govuk-button", onClick: handleSubmit, children: field.rendered_title ?? field.title }) })
5530
+ ] });
5531
+ }
5532
+ function renderAddressLookup(field) {
5533
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "address-lookup", children: [
5534
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "govuk-input__wrapper", children: [
5535
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "govuk-form-group", children: /* @__PURE__ */ jsxRuntime.jsx(
5536
+ "input",
5537
+ {
5538
+ id: `${field.field}_postcode`,
5539
+ type: "text",
5540
+ value: formValues[`${field.field}_postcode`] ?? "",
5541
+ onChange: (e) => handleFieldChange(`${field.field}_postcode`, e.target.value),
5542
+ className: ["govuk-input", field.badPostcode ? "govuk-input--error" : ""].join(" ").trim()
5543
+ }
5544
+ ) }),
5545
+ /* @__PURE__ */ jsxRuntime.jsx(
5546
+ "button",
5547
+ {
5548
+ type: "button",
5549
+ className: "govuk-button govuk-button--secondary",
5550
+ disabled: field.addressLoading,
5551
+ onClick: () => performAddressLookup(field.field),
5552
+ children: field.addressLoading ? "Searching..." : "Find address"
5553
+ }
5554
+ )
5555
+ ] }),
5556
+ field.badPostcode && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "govuk-error-message", children: [
5557
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
5558
+ "Please enter a valid UK postcode."
5559
+ ] }),
5560
+ field.addresses && field.addresses.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "govuk-form-group", children: [
5561
+ /* @__PURE__ */ jsxRuntime.jsx("label", { className: "govuk-label", htmlFor: `${field.field}_select`, children: "Select address below" }),
5562
+ /* @__PURE__ */ jsxRuntime.jsxs(
5563
+ "select",
5564
+ {
5565
+ id: `${field.field}_select`,
5566
+ className: "govuk-select",
5567
+ onChange: (e) => handleAddressSelected(e, field.field),
5568
+ children: [
5569
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: "Select address" }),
5570
+ field.addresses.map((item, idx) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: item.address.ADDRESS, children: item.address.ADDRESS }, idx))
5571
+ ]
5572
+ }
5573
+ )
5574
+ ] })
5575
+ ] });
5576
+ }
5577
+ function renderAwsLookup(field) {
5578
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "aws-lookup", children: [
5579
+ !field.lookupSuccess && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5580
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "govuk-input__wrapper", children: /* @__PURE__ */ jsxRuntime.jsx(
5581
+ "input",
5582
+ {
5583
+ id: field.field,
5584
+ type: field.type,
5585
+ "aria-required": field.required,
5586
+ value: formValues[field.field] ?? "",
5587
+ onChange: (e) => handleFieldChange(field.field, e.target.value),
5588
+ className: ["govuk-input", field.lookupError || formErrors[field.field] ? "govuk-input--error" : ""].join(" ").trim()
5589
+ }
5590
+ ) }),
5591
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "govuk-button-group", children: /* @__PURE__ */ jsxRuntime.jsx(
5592
+ "button",
5593
+ {
5594
+ type: "button",
5595
+ className: "govuk-button govuk-button--secondary lookup-reference",
5596
+ disabled: field.lookupLoading,
5597
+ onClick: () => performAwsLookup(field.field),
5598
+ children: field.lookupLoading ? "Checking..." : "Check reference"
5599
+ }
5600
+ ) })
5601
+ ] }),
5602
+ field.lookupLoading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "govuk-hint", children: "Checking reference..." }),
5603
+ field.lookupError && !field.lookupUsed && !field.lookupNameMismatch && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "govuk-error-message", children: [
5604
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
5605
+ "Reference not found. Please check and try again."
5606
+ ] }),
5607
+ field.lookupUsed && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "govuk-error-message", children: [
5608
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
5609
+ "This reference has already been used."
5610
+ ] }),
5611
+ field.lookupNameMismatch && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "govuk-error-message", children: [
5612
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
5613
+ "The name does not match the reference. Please check and try again."
5614
+ ] }),
5615
+ field.lookupSuccess && field.lookupResponse && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "govuk-inset-text", children: [
5616
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "govuk-body", children: /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "Reference verified" }) }),
5617
+ field.lookupResponse.name && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "govuk-body", children: [
5618
+ "Name: ",
5619
+ field.lookupResponse.name
5620
+ ] }),
5621
+ field.lookupResponse.home_office && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "govuk-body", children: [
5622
+ "Reference: ",
5623
+ field.lookupResponse.home_office
5624
+ ] }),
5625
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "govuk-button govuk-button--secondary", onClick: () => clearAwsLookup(field.field), children: "Clear" })
5626
+ ] })
5627
+ ] });
5628
+ }
5629
+ function renderVenueSearch(field) {
5630
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "govuk-form-group resource-lookup", children: [
5631
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "govuk-input__wrapper", children: [
5632
+ /* @__PURE__ */ jsxRuntime.jsx(
5633
+ "input",
5634
+ {
5635
+ id: field.field,
5636
+ type: "text",
5637
+ className: "govuk-input govuk-input--with-clear",
5638
+ value: searchText,
5639
+ placeholder: "Start typing to search...",
5640
+ autoComplete: "off",
5641
+ onChange: () => {
5642
+ },
5643
+ onKeyDown: (e) => handleVenueSearchInput(e, field)
5644
+ }
5645
+ ),
5646
+ searchText && /* @__PURE__ */ jsxRuntime.jsx(
5647
+ "div",
5648
+ {
5649
+ role: "button",
5650
+ tabIndex: 0,
5651
+ className: "govuk-input__suffix",
5652
+ "aria-label": "Clear search",
5653
+ onClick: () => clearVenueSearch(field),
5654
+ onKeyDown: (e) => {
5655
+ if (e.key === "Enter" || e.key === " ") clearVenueSearch(field);
5656
+ },
5657
+ children: /* @__PURE__ */ jsxRuntime.jsx("b", { "aria-hidden": "true", children: "\xD7" })
5658
+ }
5659
+ )
5660
+ ] }),
5661
+ field.searching && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "govuk-hint", children: "Searching\u2026" }),
5662
+ field.noResults && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "govuk-hint", children: "No results found" }),
5663
+ suggestions.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "resource-suggestions", role: "listbox", children: suggestions.map((suggestion, idx) => /* @__PURE__ */ jsxRuntime.jsx(
5664
+ "li",
5665
+ {
5666
+ role: "option",
5667
+ tabIndex: 0,
5668
+ className: "resource-suggestion",
5669
+ onClick: () => selectVenueSuggestion(suggestion, field),
5670
+ onKeyDown: (e) => {
5671
+ if (e.key === "Enter") selectVenueSuggestion(suggestion, field);
5672
+ },
5673
+ children: suggestion.pretty_name ?? suggestion.venue_name
5674
+ },
5675
+ idx
5676
+ )) }),
5677
+ field.answer && field.selected_resource?.description && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "selected-venue-detail", children: [
5678
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "govuk-label govuk-fieldset__legend--m pt-3", children: "Description" }),
5679
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: field.selected_resource.description }),
5680
+ field.selected_resource.image && /* @__PURE__ */ jsxRuntime.jsx("img", { className: "selected-venue", src: field.selected_resource.image, alt: "" })
5681
+ ] })
5682
+ ] });
5683
+ }
5684
+ function handleSubmit() {
5685
+ const isFormValid = formFields.filter((f) => f.show_on_this_page && (f.visible || f.is_visible)).every((f) => validateField(f, formValues[f.field] ?? "") === null);
5686
+ if (!isFormValid) {
5687
+ markAllAsTouched();
5688
+ return;
5689
+ }
5690
+ onFormSubmit?.(formValues);
5691
+ onSchema?.(schema);
5692
+ }
5693
+ if (loading) {
5694
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "govuk-body", children: "Loading form..." });
5695
+ }
5696
+ if (!formFields.length) {
5697
+ return null;
5698
+ }
5699
+ return /* @__PURE__ */ jsxRuntime.jsxs("form", { className: "govuk-form", onSubmit: (e) => {
5700
+ e.preventDefault();
5701
+ handleSubmit();
5702
+ }, children: [
5703
+ formFields.filter((field) => field.show_on_this_page).map((field, index) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: getFieldWrapperClassName(field), children: (field.is_visible || !field.rules_count) && renderField(field) }, field.field || index)),
5704
+ showSubmit && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", className: "nhsuk-button govuk-button", children: "Continue" })
5705
+ ] });
5706
+ }
5707
+
1405
5708
  exports.BookingForm = BookingForm;
1406
5709
  exports.ContactDetailsForm = ContactDetailsForm;
1407
5710
  exports.RegistrationForm = RegistrationForm;
1408
5711
  exports.ResetPasswordForm = ResetPasswordForm;
5712
+ exports.SchemaFormBuilder = SchemaFormBuilder;
1409
5713
  exports.compose = compose;
1410
5714
  exports.email = email;
5715
+ exports.hydrateField = hydrateField;
1411
5716
  exports.minLen = minLen;
1412
5717
  exports.phone = phone;
1413
5718
  exports.required = required;