/******/ (() => { // webpackBootstrap
/******/ 	var __webpack_modules__ = ({

/***/ 231
(module) {

const processLayout = function (input, maxHeight, maxWidth) {
  const tree = [{
    id: 'root',
    start: 0,
    end: maxHeight,
    depth: -1,
    children: []
  }];

  // Siblings container wrapper, for more performant BFT
  const siblingIndex = {
    index: {},
    clear() {
      this.index = {};
    },
    add(node) {
      const level = this.index[node.depth] || (this.index[node.depth] = []);
      level.push(node);
    },
    get(depth) {
      return this.index[depth] || [];
    }
  };

  // Add a new node to the tree, while maintaining siblings index
  function append(node, item, depth) {
    item.depth = depth + 1;
    siblingIndex.add(item);
    node.children.push(item);
    item.parent = node;
    tree.push(item);
  }

  // Predicate for checking if two events overlap
  function overlaps(node, item) {
    /*eslint-disable */
    return item.start >= node.start && item.start < node.end || node.start == item.start || node.end == item.end;
    /*eslint-enable */
  }

  // returns true on successful tree placement
  function traverse(node, item, depth) {
    if (!overlaps(node, item)) {
      return false;
    }

    // Run BFT on siblings to check if there are any overlaps
    const list = siblingIndex.get(depth + 1);
    for (const key in list) {
      if (traverse(list[key], item, depth + 1)) {
        return true;
      }
    }

    // If there's an overlap, append the item under the current node
    append(node, item, depth);
    return true;
  }

  // Find max depth for each tree branch
  function setMaxDepth() {
    // Visit and set maxDepth on all of node's children
    const setChildren = function (node, depth) {
      node.maxDepth = depth;
      node.children.forEach(function (child) {
        setChildren(child, depth);
      });
    };

    // Only need the leaves from the lookup table
    const leaves = tree.filter(function (node) {
      return node.children.length === 0;
    });

    // Visit every leaf, find maxDepth, reach root and update the roots (root index)
    const roots = {};
    let currentRoot;
    leaves.forEach(function (leaf) {
      let node = leaf,
        maxDepth = 0;
      while (1) {
        maxDepth = Math.max(maxDepth, node.depth);
        if (node.parent && node.parent.depth >= 0) {
          node = node.parent;
        } else {
          currentRoot = roots[node.id] || (roots[node.id] = node);
          currentRoot.maxDepth = Math.max(currentRoot.maxDepth, maxDepth);
          break;
        }
      }
    });

    // Traverse children (DFT)
    for (const rootId in roots) {
      setChildren(roots[rootId], roots[rootId].maxDepth);
    }
    tree.forEach(function (leaf) {
      let nextDepth = leaf.maxDepth + 1;
      let siblings = siblingIndex.get(nextDepth);
      while (siblings.length > 0) {
        for (const index in siblings) {
          if (overlaps(siblings[index], leaf)) {
            leaf.maxDepth = Math.max(leaf.maxDepth, siblings[index].maxDepth);
            return;
          }
        }
        siblings = siblingIndex.get(++nextDepth);
      }
    });
  }

  // Set widths for each node
  function setWidths() {
    // Calculate max depth first.
    setMaxDepth();

    // Then calculate and set width for each node
    tree.forEach(function (node) {
      node.width = maxWidth / (node.maxDepth + 1);
    });
  }

  // Format lookup table for result
  // eslint-disable-next-line
  function format(tree) {
    // eslint-disable-next-line
    return tree.map(function (node) {
      return {
        id: node.id,
        top: node.start,
        left: node.width * node.depth,
        width: node.width,
        height: node.height
      };
    });
  }
  siblingIndex.clear();

  // Fill in helpers.
  input = input.map(function (node) {
    // Make sure height is at least 15 pixels. Otherwise, adjust `end`
    // for proper calculations to account for it.
    if (node.end - node.start < 22) {
      node.end = node.start + 22;
    }
    return {
      id: node.id,
      start: node.start,
      end: node.end,
      height: node.end - node.start,
      width: 0,
      children: [],
      depth: 0,
      maxDepth: 0
    };
  }).sort(function (a, b) {
    // Sort by start time, then length
    return a.start === b.start ? b.end - a.end : a.start - b.start;
  });
  const root = tree[0];
  input.forEach(function (item) {
    traverse(root, item, -1);
  });
  setWidths();
  tree.shift();
  return tree.map(function (node) {
    return {
      id: node.id,
      top: node.start,
      left: node.width * node.depth,
      width: node.width,
      height: node.height
    };
  });
};
module.exports.q = processLayout;

/***/ },

/***/ 415
(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {

"use strict";

;// external "jQuery"
const external_jQuery_namespaceObject = window["jQuery"];
var external_jQuery_default = /*#__PURE__*/__webpack_require__.n(external_jQuery_namespaceObject);
// EXTERNAL MODULE: ./src/js/admin-calendar-layout.js
var admin_calendar_layout = __webpack_require__(231);
;// ./src/js/admin-calendar.js
/**
 * External dependencies
 */


/**
 * Internal dependencies
 */


/**
 * Popper implementation
 */
external_jQuery_default()(function ($) {
  /**
   * Scrolls to first booking on day view.
   *
   * @since 1.13.0
   */
  function scrollToFirstBooking() {
    // Day view and atleast one booking.
    if ($('.calendar_days').length && $('.daily_view_booking').length) {
      let previousStartValue, smallestStartValueIndex;

      // Gather all start values.
      $('.daily_view_booking').each(function (index) {
        const currentStartValue = parseInt($(this).data('bookingStart'), 10);
        if (typeof previousStartValue === 'undefined') {
          previousStartValue = currentStartValue;
        }
        if (currentStartValue <= previousStartValue) {
          smallestStartValueIndex = index;
        }
        previousStartValue = currentStartValue;
      });

      /*
       * Keep running at interval until first booking
       * offset is found to prevent race condition.
       */
      const findFirstBooking = setInterval(function () {
        const firstBookingTopOffset = parseInt($('.daily_view_booking').eq(smallestStartValueIndex).offset().top, 10);
        if (firstBookingTopOffset > 0) {
          $('html, body').animate({
            scrollTop: firstBookingTopOffset - 110
          }, 600);
          clearInterval(findFirstBooking);
        }
      }, 100);

      /*
       * Fallback timeout after 5 seconds to
       * clear the interval so it doesn't continue
       * running indefinitely.
       */
      setTimeout(function () {
        clearInterval(findFirstBooking);
      }, 5000);
    }
  }

  /*
   * Add select class on mouseenter and mouseleave events for each event with the same
   * event( Bookings booking or Google Calendar event ) ID
   */
  $('.calendar_month_event').on('mouseenter', function () {
    const id = this.dataset.id;
    const idClass = '.calendar_event_id_' + id;
    $(idClass).find('a.wc-bookings-event-link').addClass('calendar_month_event_selected');
  }).on('mouseleave', function () {
    const id = this.dataset.id;
    const idClass = '.calendar_event_id_' + id;
    $(idClass).find('a.wc-bookings-event-link').removeClass('calendar_month_event_selected');
  });
  const input = $.map($('.daily_view_booking'), function (el) {
    return {
      id: $(el).data('bookingId'),
      start: $(el).data('bookingStart'),
      end: $(el).data('bookingEnd')
    };
  });
  const totalCalendarHeight = 1968; // definded by design
  const calendarHeightInMinutes = 1440; // 60 minutes * 24 hours
  const scale = totalCalendarHeight / calendarHeightInMinutes;
  (0,admin_calendar_layout/* processLayout */.q)(input, 1968, 100).forEach(function (node) {
    const $el = $('*[data-booking-id="' + node.id + '"]');
    $el.css({
      top: 'calc(' + node.top * scale + 'px + 2px )'
    });
    $el.css({
      height: 'calc(' + node.height * scale + 'px - 3px )'
    });
    $el.css('left', node.left + '%');
    // 12px come from the popper padding
    $el.css({
      width: 'calc(' + node.width + '% - 13px )'
    });
    $el.show();
  }, scrollToFirstBooking());
  const globalAvailability = $.map($('.daily_view_global_availabiltiy'), function (el) {
    return {
      start: $(el).data('start'),
      end: $(el).data('end'),
      id: $(el).data('globalAvailabilityId')
    };
  });
  globalAvailability.forEach(function (range) {
    const $el = $('*[data-global-availability-id="' + range.id + '"]');
    $el.css({
      top: 'calc(' + range.start * scale + 'px )'
    });
    $el.css({
      height: 'calc(' + (range.end - range.start) * scale + 'px )'
    });
    $el.css('left', '-43px');
    $el.css({
      width: 'calc(' + '100' + '% + 50px )'
    });
    $el.show();
  });
  $('.daily_view_booking').each(function (index, el) {
    const $el = $(el);

    // Account for the padding in the CSS
    $el.height($el.height() - 12);
  });

  // Scroll to today on schedule view.
  $(document).ready(function () {
    const $todayEl = $('.wc-bookings-schedule-date.wc-booking-schedule-today');
    if ($todayEl.length) {
      const todayOffset = parseInt($todayEl.offset().top, 10);
      $('html, body').animate({
        scrollTop: todayOffset - 101 // today field/row height offset + floating header height
      }, 600);
    }
  });
});

/***/ }

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	const __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		const cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		const module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/compat get default export */
/******/ 	(() => {
/******/ 		// getDefaultExport function for compatibility with non-harmony modules
/******/ 		__webpack_require__.n = (module) => {
/******/ 			const getter = module && module.__esModule ?
/******/ 				() => (module['default']) :
/******/ 				() => (module);
/******/ 			__webpack_require__.d(getter, { a: getter });
/******/ 			return getter;
/******/ 		};
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/define property getters */
/******/ 	(() => {
/******/ 		// define getter/value functions for harmony exports
/******/ 		__webpack_require__.d = (exports, definition) => {
/******/ 			if(Array.isArray(definition)) {
/******/ 				var i = 0;
/******/ 				while(i < definition.length) {
/******/ 					var key = definition[i++];
/******/ 					var binding = definition[i++];
/******/ 					if(!__webpack_require__.o(exports, key)) {
/******/ 						if(binding === 0) {
/******/ 							Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] });
/******/ 						} else {
/******/ 							Object.defineProperty(exports, key, { enumerable: true, get: binding });
/******/ 						}
/******/ 					} else if(binding === 0) { i++; }
/******/ 				}
/******/ 			} else {
/******/ 				for(var key in definition) {
/******/ 					if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ 						Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ 					}
/******/ 				}
/******/ 			}
/******/ 		};
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
/******/ 	(() => {
/******/ 		__webpack_require__.o = (obj, prop) => (Object.hasOwn(obj, prop))
/******/ 	})();
/******/ 	
/************************************************************************/
/******/ 	
/******/ 	// startup
/******/ 	// Load entry module and return exports
/******/ 	__webpack_require__(415);
/******/ 	// This entry module is referenced by other modules so it can't be inlined
/******/ 	let __webpack_exports__ = __webpack_require__(231);
/******/ 	
/******/ })()
;
//# sourceMappingURL=admin-calendar.js.map