@orderingstack/front-hooks 2.2.0 → 2.3.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.es.js CHANGED
@@ -767,6 +767,27 @@ const filterTimeAvailabilityOfProducts = (products, timeZone = void 0, dueTime =
767
767
  }
768
768
  return filteredProducts;
769
769
  };
770
+ function isChannelOpen(channel) {
771
+ const week = channel == null ? void 0 : channel.week;
772
+ if (!channel || !channel.active || !week) {
773
+ return false;
774
+ }
775
+ const date = dayjs();
776
+ const dayNumber = date.day();
777
+ const todayEntry = week[dayMap[dayNumber]];
778
+ if (!todayEntry)
779
+ return false;
780
+ return todayEntry.some((entry) => isOpen(date, entry));
781
+ }
782
+ function isOpen(date, entry) {
783
+ const hour = date.hour();
784
+ const minutes = date.minute();
785
+ const start = getHourAndMinutes(entry.from);
786
+ const stop = getHourAndMinutes(entry.to);
787
+ if (hour < start.hour || hour === start.hour && minutes < start.minutes)
788
+ return false;
789
+ return !(hour > stop.hour || hour === stop.hour && minutes > stop.minutes);
790
+ }
770
791
  function listCacheClear$1() {
771
792
  this.__data__ = [];
772
793
  this.size = 0;
@@ -3123,5 +3144,26 @@ function useOnClickOutside(ref, handler) {
3123
3144
  };
3124
3145
  }, [ref, handler]);
3125
3146
  }
3126
- export { getGroupedBucketLines, groupOrderLines, useAvailability, useCms, useDisplayPrice, useGroupOrderLines, useInterval, useLocalizedVenueMedia, useOnClickOutside, useVenueCms };
3147
+ function useKioskChannelsAvailability(channelConstrainst) {
3148
+ const [dineInOpen, setDineInOpen] = useState(isChannelOpen(channelConstrainst == null ? void 0 : channelConstrainst.DINE_IN));
3149
+ const [takeAwayOpen, setTakeAwayOpen] = useState(isChannelOpen(channelConstrainst == null ? void 0 : channelConstrainst.TAKE_AWAY));
3150
+ function checkOpen() {
3151
+ const dineIn = isChannelOpen(channelConstrainst == null ? void 0 : channelConstrainst.DINE_IN);
3152
+ const takeAway = isChannelOpen(channelConstrainst == null ? void 0 : channelConstrainst.TAKE_AWAY);
3153
+ if (dineIn !== dineInOpen) {
3154
+ console.log("dine in open changed", dineInOpen, "=>", dineIn);
3155
+ setDineInOpen(dineIn);
3156
+ }
3157
+ if (takeAway !== takeAwayOpen) {
3158
+ console.log("take away open changed", takeAwayOpen, "=>", takeAway);
3159
+ setTakeAwayOpen(takeAway);
3160
+ }
3161
+ }
3162
+ useEffect(() => {
3163
+ checkOpen();
3164
+ }, [channelConstrainst]);
3165
+ useInterval(checkOpen, 6e4);
3166
+ return { dineInOpen, takeAwayOpen };
3167
+ }
3168
+ export { getGroupedBucketLines, groupOrderLines, useAvailability, useCms, useDisplayPrice, useGroupOrderLines, useInterval, useKioskChannelsAvailability, useLocalizedVenueMedia, useOnClickOutside, useVenueCms };
3127
3169
  //# sourceMappingURL=index.es.js.map