import { useMemo } from 'react';
function isEventTargetDescendantOf(event, refs) {
  return event.target instanceof Node && refs.some(function (ref) {
    var _ref$current;
    return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.contains(event.target);
  });
}
export function useFocusTrapOptions(close, clickAllowedElementRefs) {
  return useMemo(function () {
    return {
      allowOutsideClick: function allowOutsideClick(event) {
        return isEventTargetDescendantOf(event, clickAllowedElementRefs);
      },
      clickOutsideDeactivates: function clickOutsideDeactivates(event) {
        return !isEventTargetDescendantOf(event, clickAllowedElementRefs);
      },
      // Temporary workaround until we update to react-day-picker v8, which has a way
      // to set the initial focus to the selected date (or today if no date selected)
      initialFocus: '[role="button"]',
      onDeactivate: close
    };
  }, [clickAllowedElementRefs, close]);
}