@codebards/ik-embeddable-form 0.0.2736450101-qa → 0.0.2736696173-qa

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/embed.js CHANGED
@@ -1574,41 +1574,143 @@ var IKEmbeddableFormBundle = function(exports) {
1574
1574
  "December"
1575
1575
  ];
1576
1576
  const WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
1577
- function createFutureStaticSlots(count = 3) {
1578
- const pad = (n2) => String(n2).padStart(2, "0");
1579
- const slots = [];
1577
+ const FALLBACK_SCHEDULES = {
1578
+ IND: {
1579
+ skipDay: null,
1580
+ timeSlots: {
1581
+ 0: "12:00:00",
1582
+ 1: "18:00:00",
1583
+ 2: "18:00:00",
1584
+ 3: "18:00:00",
1585
+ 4: "18:00:00",
1586
+ 5: "18:00:00",
1587
+ 6: "12:00:00"
1588
+ },
1589
+ timeZone: "Asia/Kolkata",
1590
+ utcOffsetHours: 5.5
1591
+ },
1592
+ USA: {
1593
+ skipDay: 6,
1594
+ timeSlots: {
1595
+ 0: "20:30:00",
1596
+ 1: "19:30:00",
1597
+ 2: "20:30:00",
1598
+ 3: "19:30:00",
1599
+ 4: "20:30:00",
1600
+ 5: "19:30:00",
1601
+ 6: null
1602
+ },
1603
+ timeZone: "America/New_York",
1604
+ utcOffsetHours: -5
1605
+ }
1606
+ };
1607
+ function pad2(n2) {
1608
+ return String(n2).padStart(2, "0");
1609
+ }
1610
+ function formatUtcOffset(offsetHours) {
1611
+ const sign = offsetHours >= 0 ? "+" : "-";
1612
+ const abs = Math.abs(offsetHours);
1613
+ const hours = Math.floor(abs);
1614
+ const minutes = Math.round((abs - hours) * 60);
1615
+ return `${sign}${pad2(hours)}:${pad2(minutes)}`;
1616
+ }
1617
+ function todayInTimeZone(timeZone) {
1618
+ const parts = new Intl.DateTimeFormat("en-US", {
1619
+ timeZone,
1620
+ year: "numeric",
1621
+ month: "2-digit",
1622
+ day: "2-digit"
1623
+ }).formatToParts(/* @__PURE__ */ new Date());
1624
+ const get2 = (type) => {
1625
+ var _a;
1626
+ return Number((_a = parts.find((p2) => p2.type === type)) == null ? void 0 : _a.value);
1627
+ };
1628
+ return { year: get2("year"), month: get2("month"), day: get2("day") };
1629
+ }
1630
+ function wallClockParts(date, timeZone) {
1631
+ const parts = new Intl.DateTimeFormat("en-US", {
1632
+ timeZone,
1633
+ year: "numeric",
1634
+ month: "2-digit",
1635
+ day: "2-digit",
1636
+ hour: "2-digit",
1637
+ minute: "2-digit",
1638
+ second: "2-digit",
1639
+ hourCycle: "h23"
1640
+ }).formatToParts(date);
1641
+ const get2 = (type) => {
1642
+ var _a;
1643
+ return Number((_a = parts.find((p2) => p2.type === type)) == null ? void 0 : _a.value);
1644
+ };
1645
+ return {
1646
+ year: get2("year"),
1647
+ month: get2("month"),
1648
+ day: get2("day"),
1649
+ hour: get2("hour"),
1650
+ minute: get2("minute"),
1651
+ second: get2("second")
1652
+ };
1653
+ }
1654
+ function timeZoneOffsetString(timeZone, at) {
1655
+ var _a;
1656
+ try {
1657
+ const raw = ((_a = new Intl.DateTimeFormat("en-US", { timeZone, timeZoneName: "longOffset" }).formatToParts(at).find((p2) => p2.type === "timeZoneName")) == null ? void 0 : _a.value) ?? "GMT+00:00";
1658
+ let offset = raw.replace("GMT", "") || "+00:00";
1659
+ if (/^[+-]\d:/.test(offset)) offset = offset.replace(/^([+-])(\d):/, "$10$2:");
1660
+ return offset || "+00:00";
1661
+ } catch {
1662
+ return "+00:00";
1663
+ }
1664
+ }
1665
+ function generateFallbackSlots(country, targetTimezone, webinarType, count = 13) {
1666
+ const schedule = FALLBACK_SCHEDULES[country === "IND" ? "IND" : "USA"];
1667
+ const scheduleOffset = formatUtcOffset(schedule.utcOffsetHours);
1668
+ const today = todayInTimeZone(schedule.timeZone);
1580
1669
  const now = /* @__PURE__ */ new Date();
1670
+ const slots = [];
1581
1671
  for (let i2 = 0; i2 < count; i2++) {
1582
- const start = new Date(now);
1583
- start.setDate(start.getDate() + 7 * (i2 + 1));
1584
- start.setHours(19, 30, 0, 0);
1585
- const end = new Date(start);
1586
- end.setHours(20, 30, 0, 0);
1587
- const hour12 = start.getHours() % 12 || 12;
1588
- const ampm = start.getHours() >= 12 ? "PM" : "AM";
1589
- const offsetMin = -start.getTimezoneOffset();
1590
- const sign = offsetMin >= 0 ? "+" : "-";
1591
- const tzOffset = `${sign}${pad(Math.floor(Math.abs(offsetMin) / 60))}:${pad(Math.abs(offsetMin) % 60)}`;
1592
- const toIso = (d2) => `${d2.getFullYear()}-${pad(d2.getMonth() + 1)}-${pad(d2.getDate())}T${pad(d2.getHours())}:${pad(d2.getMinutes())}:00${tzOffset}`;
1593
- const weekday = WEEKDAYS[start.getDay()] ?? "Tuesday";
1594
- const monthLabel = MONTHS[start.getMonth()] ?? "June";
1595
- const day = pad(start.getDate());
1596
- const year = String(start.getFullYear());
1597
- const minute = pad(start.getMinutes());
1598
- const endHour12 = end.getHours() % 12 || 12;
1599
- const endAmpm = end.getHours() >= 12 ? "PM" : "AM";
1672
+ const candidate = new Date(today.year, today.month - 1, today.day);
1673
+ candidate.setDate(candidate.getDate() + i2);
1674
+ const weekday = candidate.getDay();
1675
+ if (weekday === schedule.skipDay) continue;
1676
+ const time = schedule.timeSlots[weekday];
1677
+ if (!time) continue;
1678
+ const [hour, minute, second] = time.split(":").map(Number);
1679
+ candidate.setHours(hour, minute, second, 0);
1680
+ const isoInSchedule = `${candidate.getFullYear()}-${pad2(candidate.getMonth() + 1)}-${pad2(candidate.getDate())}T${pad2(candidate.getHours())}:${pad2(candidate.getMinutes())}:${pad2(candidate.getSeconds())}${scheduleOffset}`;
1681
+ const instant = new Date(isoInSchedule);
1682
+ if (Number.isNaN(instant.getTime()) || instant < now) continue;
1683
+ const end = new Date(instant.getTime() + 60 * 60 * 1e3);
1684
+ const startWall = wallClockParts(instant, targetTimezone);
1685
+ const endWall = wallClockParts(end, targetTimezone);
1686
+ const targetOffset = timeZoneOffsetString(targetTimezone, instant);
1687
+ const toIso = (w2) => `${w2.year}-${pad2(w2.month)}-${pad2(w2.day)}T${pad2(w2.hour)}:${pad2(w2.minute)}:${pad2(w2.second)}${targetOffset}`;
1688
+ const formatClock = (hour24, min) => {
1689
+ const hour12 = hour24 % 12 || 12;
1690
+ const ampm = hour24 >= 12 ? "PM" : "AM";
1691
+ return { label: `${hour12}:${pad2(min)}${ampm}`, hour12, ampm };
1692
+ };
1693
+ const weekdayLabel = WEEKDAYS[new Date(startWall.year, startWall.month - 1, startWall.day).getDay()] ?? "Tuesday";
1694
+ const monthLabel = MONTHS[startWall.month - 1] ?? "June";
1695
+ const dateLabel = `${weekdayLabel}, ${monthLabel} ${pad2(startWall.day)}, ${startWall.year}`;
1696
+ const start = formatClock(startWall.hour, startWall.minute);
1697
+ const slotEnd = formatClock(endWall.hour, endWall.minute);
1600
1698
  slots.push({
1601
- start_time: toIso(start),
1602
- end_time: toIso(end),
1603
- day,
1604
- month: pad(start.getMonth() + 1),
1605
- year,
1606
- hour: String(hour12),
1607
- minute,
1608
- am_or_pm: ampm,
1609
- weekday,
1610
- invitee_start_time: `${hour12}:${minute}${ampm} - ${weekday}, ${monthLabel} ${day}, ${year}`,
1611
- invitee_end_time: `${endHour12}:${pad(end.getMinutes())}${endAmpm} - ${weekday}, ${monthLabel} ${day}, ${year}`
1699
+ start_time: toIso(startWall),
1700
+ end_time: toIso(endWall),
1701
+ utc_start_time: instant.toISOString(),
1702
+ utc_end_time: end.toISOString(),
1703
+ day: pad2(startWall.day),
1704
+ month: pad2(startWall.month),
1705
+ year: String(startWall.year),
1706
+ hour: String(start.hour12),
1707
+ minute: pad2(startWall.minute),
1708
+ second: pad2(startWall.second),
1709
+ am_or_pm: start.ampm,
1710
+ weekday: weekdayLabel,
1711
+ invitee_start_time: `${start.label} - ${dateLabel}`,
1712
+ invitee_end_time: `${slotEnd.label} - ${dateLabel}`,
1713
+ webinar_lead_type: webinarType
1612
1714
  });
1613
1715
  }
1614
1716
  return slots;
@@ -1675,12 +1777,12 @@ var IKEmbeddableFormBundle = function(exports) {
1675
1777
  const slots = Array.isArray(data) ? data : [];
1676
1778
  return slots;
1677
1779
  }
1678
- function getStaticSlots(openConfig) {
1780
+ function getStaticSlots(openConfig, country, timezone, webinarType) {
1679
1781
  const custom = openConfig == null ? void 0 : openConfig.staticSlots;
1680
1782
  if (custom && custom.length > 0) {
1681
1783
  return custom;
1682
1784
  }
1683
- return createFutureStaticSlots();
1785
+ return generateFallbackSlots(country, timezone, webinarType);
1684
1786
  }
1685
1787
  function resolveSlotApiCountry(openConfig, slotApiConfig) {
1686
1788
  if (openConfig == null ? void 0 : openConfig.slotApiCountry) {
@@ -1723,20 +1825,18 @@ var IKEmbeddableFormBundle = function(exports) {
1723
1825
  return {
1724
1826
  slots: l2.map(apiSlotToWebinarSlot),
1725
1827
  rawSlots: l2,
1726
- assignedWebinarType: "REGULAR",
1828
+ assignedWebinarType: l2Type,
1727
1829
  source: "api-l2"
1728
1830
  };
1729
1831
  }
1730
1832
  } catch {
1731
1833
  }
1732
- const staticSlots = filterFutureSlots(getStaticSlots(openConfig));
1733
- const fallback = limitDisplaySlots(
1734
- staticSlots.length > 0 ? staticSlots : filterFutureSlots(createFutureStaticSlots())
1735
- );
1834
+ const staticSlots = filterFutureSlots(getStaticSlots(openConfig, country, timezone, l2Type));
1835
+ const fallback = limitDisplaySlots(staticSlots);
1736
1836
  return {
1737
1837
  slots: fallback.map(apiSlotToWebinarSlot),
1738
1838
  rawSlots: fallback,
1739
- assignedWebinarType: webinarType,
1839
+ assignedWebinarType: l2Type,
1740
1840
  source: "static"
1741
1841
  };
1742
1842
  }