text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports["default"] = void 0;
  
  var _moment = _interopRequireDefault(require("moment"));
  
  var _rrule = require("rrule");
  
  var _config = _interopRequireDefault(require("./config"));
  
  var _behaviors = _interopRequireDefault(require("./behaviors"));
  
  var _index = require("./index");
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
  
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  
  var SchedulerData = /*#__PURE__*/function () {
    function SchedulerData() {
      var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _moment["default"])().format(_index.DATE_FORMAT);
      var viewType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _index.ViewTypes.Week;
      var showAgenda = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
      var isEventPerspective = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
      var newConfig = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
      var newBehaviors = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : undefined;
      var localeMoment = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : undefined;
  
      _classCallCheck(this, SchedulerData);
  
      this.resources = [];
      this.events = [];
      this.eventGroups = [];
      this.eventGroupsAutoGenerated = true;
      this.viewType = viewType;
      this.cellUnit = viewType === _index.ViewTypes.Day ? _index.CellUnits.Hour : _index.CellUnits.Day;
      this.showAgenda = showAgenda;
      this.isEventPerspective = isEventPerspective;
      this.resizing = false;
      this.scrollToSpecialMoment = false;
      this.documentWidth = 0;
      this.localeMoment = _moment["default"];
      if (!!localeMoment) this.localeMoment = localeMoment;
      this.config = newConfig == undefined ? _config["default"] : _objectSpread(_objectSpread({}, _config["default"]), newConfig);
  
      this._validateMinuteStep(this.config.minuteStep);
  
      this.behaviors = newBehaviors == undefined ? _behaviors["default"] : _objectSpread(_objectSpread({}, _behaviors["default"]), newBehaviors);
  
      this._resolveDate(0, date);
  
      this._createHeaders();
  
      this._createRenderData();
    }
  
    _createClass(SchedulerData, [{
      key: "setLocaleMoment",
      value: function setLocaleMoment(localeMoment) {
        if (!!localeMoment) {
          this.localeMoment = localeMoment;
  
          this._createHeaders();
  
          this._createRenderData();
        }
      }
    }, {
      key: "setResources",
      value: function setResources(resources) {
        this._validateResource(resources);
  
        this.resources = Array.from(new Set(resources));
  
        this._createRenderData();
  
        this.setScrollToSpecialMoment(true);
      }
    }, {
      key: "setEventGroupsAutoGenerated",
      value: function setEventGroupsAutoGenerated(autoGenerated) {
        this.eventGroupsAutoGenerated = autoGenerated;
      } //optional
  
    }, {
      key: "setEventGroups",
      value: function setEventGroups(eventGroups) {
        this._validateEventGroups(eventGroups);
  
        this.eventGroups = Array.from(new Set(eventGroups));
        this.eventGroupsAutoGenerated = false;
  
        this._createRenderData();
  
        this.setScrollToSpecialMoment(true);
      }
    }, {
      key: "setMinuteStep",
      value: function setMinuteStep(minuteStep) {
        if (this.config.minuteStep !== minuteStep) {
          this._validateMinuteStep(minuteStep);
  
          this.config.minuteStep = minuteStep;
  
          this._createHeaders();
  
          this._createRenderData();
        }
      }
    }, {
      key: "setBesidesWidth",
      value: function setBesidesWidth(besidesWidth) {
        if (besidesWidth >= 0) {
          this.config.besidesWidth = besidesWidth;
        }
      }
    }, {
      key: "getMinuteStepsInHour",
      value: function getMinuteStepsInHour() {
        return 60 / this.config.minuteStep;
      }
    }, {
      key: "addResource",
      value: function addResource(resource) {
        var existedResources = this.resources.filter(function (x) {
          return x.id === resource.id;
        });
  
        if (existedResources.length === 0) {
          this.resources.push(resource);
  
          this._createRenderData();
        }
      }
    }, {
      key: "addEventGroup",
      value: function addEventGroup(eventGroup) {
        var existedEventGroups = this.eventGroups.filter(function (x) {
          return x.id === eventGroup.id;
        });
  
        if (existedEventGroups.length === 0) {
          this.eventGroups.push(eventGroup);
  
          this._createRenderData();
        }
      }
    }, {
      key: "removeEventGroupById",
      value: function removeEventGroupById(eventGroupId) {
        var index = -1;
        this.eventGroups.forEach(function (item, idx) {
          if (item.id === eventGroupId) index = idx;
        });
        if (index !== -1) this.eventGroups.splice(index, 1);
      }
    }, {
      key: "containsEventGroupId",
      value: function containsEventGroupId(eventGroupId) {
        var index = -1;
        this.eventGroups.forEach(function (item, idx) {
          if (item.id === eventGroupId) index = idx;
        });
        return index !== -1;
      }
    }, {
      key: "setEvents",
      value: function setEvents(events) {
        this._validateEvents(events);
  
        this.events = Array.from(events);
        if (this.eventGroupsAutoGenerated) this._generateEventGroups();
        if (this.config.recurringEventsEnabled) this._handleRecurringEvents();
  
        this._createRenderData();
      }
    }, {
      key: "setScrollToSpecialMoment",
      value: function setScrollToSpecialMoment(scrollToSpecialMoment) {
        if (this.config.scrollToSpecialMomentEnabled) this.scrollToSpecialMoment = scrollToSpecialMoment;
      }
    }, {
      key: "prev",
      value: function prev() {
        this._resolveDate(-1);
  
        this.events = [];
  
        this._createHeaders();
  
        this._createRenderData();
      }
    }, {
      key: "next",
      value: function next() {
        this._resolveDate(1);
  
        this.events = [];
  
        this._createHeaders();
  
        this._createRenderData();
      }
    }, {
      key: "setDate",
      value: function setDate() {
        var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _moment["default"])().format(_index.DATE_FORMAT);
  
        this._resolveDate(0, date);
  
        this.events = [];
  
        this._createHeaders();
  
        this._createRenderData();
      }
    }, {
      key: "setViewType",
      value: function setViewType() {
        var viewType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _index.ViewTypes.Week;
        var showAgenda = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
        var isEventPerspective = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
        this.showAgenda = showAgenda;
        this.isEventPerspective = isEventPerspective;
        this.cellUnit = _index.CellUnits.Day;
  
        if (this.viewType !== viewType) {
          var date = this.startDate;
  
          if (viewType === _index.ViewTypes.Custom || viewType === _index.ViewTypes.Custom1 || viewType === _index.ViewTypes.Custom2) {
            this.viewType = viewType;
  
            this._resolveDate(0, date);
          } else {
            if (this.viewType < viewType) {
              if (viewType === _index.ViewTypes.Week) {
                this.startDate = this.localeMoment(date).startOf('week').format(_index.DATE_FORMAT);
                this.endDate = this.localeMoment(this.startDate).endOf('week').format(_index.DATE_FORMAT);
              } else if (viewType === _index.ViewTypes.Month) {
                this.startDate = this.localeMoment(date).startOf('month').format(_index.DATE_FORMAT);
                this.endDate = this.localeMoment(this.startDate).endOf('month').format(_index.DATE_FORMAT);
              } else if (viewType === _index.ViewTypes.Quarter) {
                this.startDate = this.localeMoment(date).startOf('quarter').format(_index.DATE_FORMAT);
                this.endDate = this.localeMoment(this.startDate).endOf('quarter').format(_index.DATE_FORMAT);
              } else if (viewType === _index.ViewTypes.Year) {
                this.startDate = this.localeMoment(date).startOf('year').format(_index.DATE_FORMAT);
                this.endDate = this.localeMoment(this.startDate).endOf('year').format(_index.DATE_FORMAT);
              }
            } else {
              var start = this.localeMoment(this.startDate);
              var end = this.localeMoment(this.endDate).add(1, 'days');
  
              if (this.selectDate !== undefined) {
                var selectDate = this.localeMoment(this.selectDate);
  
                if (selectDate >= start && selectDate < end) {
                  date = this.selectDate;
                }
              }
  
              var now = this.localeMoment();
  
              if (now >= start && now < end) {
                date = now.format(_index.DATE_FORMAT);
              }
  
              if (viewType === _index.ViewTypes.Day) {
                this.startDate = date;
                this.endDate = this.startDate;
                this.cellUnit = _index.CellUnits.Hour;
              } else if (viewType === _index.ViewTypes.Week) {
                this.startDate = this.localeMoment(date).startOf('week').format(_index.DATE_FORMAT);
                this.endDate = this.localeMoment(this.startDate).endOf('week').format(_index.DATE_FORMAT);
              } else if (viewType === _index.ViewTypes.Month) {
                this.startDate = this.localeMoment(date).startOf('month').format(_index.DATE_FORMAT);
                this.endDate = this.localeMoment(this.startDate).endOf('month').format(_index.DATE_FORMAT);
              } else if (viewType === _index.ViewTypes.Quarter) {
                this.startDate = this.localeMoment(date).startOf('quarter').format(_index.DATE_FORMAT);
                this.endDate = this.localeMoment(this.startDate).endOf('quarter').format(_index.DATE_FORMAT);
              }
            }
  
            this.viewType = viewType;
          }
  
          this.events = [];
  
          this._createHeaders();
  
          this._createRenderData();
  
          this.setScrollToSpecialMoment(true);
        }
      }
    }, {
      key: "setSchedulerMaxHeight",
      value: function setSchedulerMaxHeight(newSchedulerMaxHeight) {
        this.config.schedulerMaxHeight = newSchedulerMaxHeight;
      }
    }, {
      key: "isSchedulerResponsive",
      value: function isSchedulerResponsive() {
        return !!this.config.schedulerWidth.endsWith && this.config.schedulerWidth.endsWith("%");
      }
    }, {
      key: "toggleExpandStatus",
      value: function toggleExpandStatus(slotId) {
        var slotEntered = false;
        var slotIndent = -1;
        var isExpanded = false;
        var expandedMap = new Map();
        this.renderData.forEach(function (item) {
          if (slotEntered === false) {
            if (item.slotId === slotId && item.hasChildren) {
              slotEntered = true;
              isExpanded = !item.expanded;
              item.expanded = isExpanded;
              slotIndent = item.indent;
              expandedMap.set(item.indent, {
                expanded: item.expanded,
                render: item.render
              });
            }
          } else {
            if (item.indent > slotIndent) {
              var expandStatus = expandedMap.get(item.indent - 1);
              item.render = expandStatus.expanded && expandStatus.render;
  
              if (item.hasChildren) {
                expandedMap.set(item.indent, {
                  expanded: item.expanded,
                  render: item.render
                });
              }
            } else {
              slotEntered = false;
            }
          }
        });
      }
    }, {
      key: "isResourceViewResponsive",
      value: function isResourceViewResponsive() {
        var resourceTableWidth = this.getResourceTableConfigWidth();
        return !!resourceTableWidth.endsWith && resourceTableWidth.endsWith("%");
      }
    }, {
      key: "isContentViewResponsive",
      value: function isContentViewResponsive() {
        var contentCellWidth = this.getContentCellConfigWidth();
        return !!contentCellWidth.endsWith && contentCellWidth.endsWith("%");
      }
    }, {
      key: "getSchedulerWidth",
      value: function getSchedulerWidth() {
        var baseWidth = this.documentWidth - this.config.besidesWidth > 0 ? this.documentWidth - this.config.besidesWidth : 0;
        return this.isSchedulerResponsive() ? parseInt(baseWidth * Number(this.config.schedulerWidth.slice(0, -1)) / 100) : this.config.schedulerWidth;
      }
    }, {
      key: "getResourceTableWidth",
      value: function getResourceTableWidth() {
        var resourceTableConfigWidth = this.getResourceTableConfigWidth();
        var schedulerWidth = this.getSchedulerWidth();
        var resourceTableWidth = this.isResourceViewResponsive() ? parseInt(schedulerWidth * Number(resourceTableConfigWidth.slice(0, -1)) / 100) : resourceTableConfigWidth;
        if (this.isSchedulerResponsive() && this.getContentTableWidth() + resourceTableWidth < schedulerWidth) resourceTableWidth = schedulerWidth - this.getContentTableWidth();
        return resourceTableWidth;
      }
    }, {
      key: "getContentCellWidth",
      value: function getContentCellWidth() {
        var contentCellConfigWidth = this.getContentCellConfigWidth();
        var schedulerWidth = this.getSchedulerWidth();
        return this.isContentViewResponsive() ? parseInt(schedulerWidth * Number(contentCellConfigWidth.slice(0, -1)) / 100) : contentCellConfigWidth;
      }
    }, {
      key: "getContentTableWidth",
      value: function getContentTableWidth() {
        return this.headers.length * this.getContentCellWidth();
      }
    }, {
      key: "getScrollToSpecialMoment",
      value: function getScrollToSpecialMoment() {
        if (this.config.scrollToSpecialMomentEnabled) return this.scrollToSpecialMoment;
        return false;
      }
    }, {
      key: "getSlots",
      value: function getSlots() {
        return this.isEventPerspective ? this.eventGroups : this.resources;
      }
    }, {
      key: "getSlotById",
      value: function getSlotById(slotId) {
        var slots = this.getSlots();
        var slot = undefined;
        slots.forEach(function (item) {
          if (item.id === slotId) slot = item;
        });
        return slot;
      }
    }, {
      key: "getResourceById",
      value: function getResourceById(resourceId) {
        var resource = undefined;
        this.resources.forEach(function (item) {
          if (item.id === resourceId) resource = item;
        });
        return resource;
      }
    }, {
      key: "getTableHeaderHeight",
      value: function getTableHeaderHeight() {
        return this.config.tableHeaderHeight;
      }
    }, {
      key: "getSchedulerContentDesiredHeight",
      value: function getSchedulerContentDesiredHeight() {
        var height = 0;
        this.renderData.forEach(function (item) {
          if (item.render) height += item.rowHeight;
        });
        return height;
      }
    }, {
      key: "getCellMaxEvents",
      value: function getCellMaxEvents() {
        return this.viewType === _index.ViewTypes.Week ? this.config.weekMaxEvents : this.viewType === _index.ViewTypes.Day ? this.config.dayMaxEvents : this.viewType === _index.ViewTypes.Month ? this.config.monthMaxEvents : this.viewType === _index.ViewTypes.Year ? this.config.yearMaxEvents : this.viewType === _index.ViewTypes.Quarter ? this.config.quarterMaxEvents : this.config.customMaxEvents;
      }
    }, {
      key: "getDateLabel",
      value: function getDateLabel() {
        var start = this.localeMoment(this.startDate);
        var end = this.localeMoment(this.endDate);
        var dateLabel = start.format('LL');
        if (start != end) dateLabel = "".concat(start.format('LL'), "-").concat(end.format('LL'));
        if (!!this.behaviors.getDateLabelFunc) dateLabel = this.behaviors.getDateLabelFunc(this, this.viewType, this.startDate, this.endDate);
        return dateLabel;
      }
    }, {
      key: "addEvent",
      value: function addEvent(newEvent) {
        this._attachEvent(newEvent);
  
        if (this.eventGroupsAutoGenerated) this._generateEventGroups();
  
        this._createRenderData();
      }
    }, {
      key: "updateEventStart",
      value: function updateEventStart(event, newStart) {
        this._detachEvent(event);
  
        event.start = newStart;
  
        this._attachEvent(event);
  
        this._createRenderData();
      }
    }, {
      key: "updateEventEnd",
      value: function updateEventEnd(event, newEnd) {
        event.end = newEnd;
  
        this._createRenderData();
      }
    }, {
      key: "moveEvent",
      value: function moveEvent(event, newSlotId, newSlotName, newStart, newEnd) {
        this._detachEvent(event);
  
        if (this.isEventPerspective) {
          event.groupId = newSlotId;
          event.groupName = newSlotName;
        } else event.resourceId = newSlotId;
  
        event.end = newEnd;
        event.start = newStart;
  
        this._attachEvent(event);
  
        this._createRenderData();
      }
    }, {
      key: "isEventInTimeWindow",
      value: function isEventInTimeWindow(eventStart, eventEnd, windowStart, windowEnd) {
        return eventStart < windowEnd && eventEnd > windowStart;
      }
    }, {
      key: "removeEvent",
      value: function removeEvent(event) {
        var index = this.events.indexOf(event);
  
        if (index !== -1) {
          this.events.splice(index, 1);
  
          this._createRenderData();
        }
      }
    }, {
      key: "removeEventById",
      value: function removeEventById(eventId) {
        var index = -1;
        this.events.forEach(function (item, idx) {
          if (item.id === eventId) index = idx;
        });
  
        if (index !== -1) {
          this.events.splice(index, 1);
  
          this._createRenderData();
        }
      }
    }, {
      key: "getResourceTableConfigWidth",
      value: function getResourceTableConfigWidth() {
        if (this.showAgenda) return this.config.agendaResourceTableWidth;
        return this.viewType === _index.ViewTypes.Week ? this.config.weekResourceTableWidth : this.viewType === _index.ViewTypes.Day ? this.config.dayResourceTableWidth : this.viewType === _index.ViewTypes.Month ? this.config.monthResourceTableWidth : this.viewType === _index.ViewTypes.Year ? this.config.yearResourceTableWidth : this.viewType === _index.ViewTypes.Quarter ? this.config.quarterResourceTableWidth : this.config.customResourceTableWidth;
      }
    }, {
      key: "getContentCellConfigWidth",
      value: function getContentCellConfigWidth() {
        return this.viewType === _index.ViewTypes.Week ? this.config.weekCellWidth : this.viewType === _index.ViewTypes.Day ? this.config.dayCellWidth : this.viewType === _index.ViewTypes.Month ? this.config.monthCellWidth : this.viewType === _index.ViewTypes.Year ? this.config.yearCellWidth : this.viewType === _index.ViewTypes.Quarter ? this.config.quarterCellWidth : this.config.customCellWidth;
      }
    }, {
      key: "_setDocumentWidth",
      value: function _setDocumentWidth(documentWidth) {
        if (documentWidth >= 0) {
          this.documentWidth = documentWidth;
        }
      }
    }, {
      key: "_detachEvent",
      value: function _detachEvent(event) {
        var index = this.events.indexOf(event);
        if (index !== -1) this.events.splice(index, 1);
      }
    }, {
      key: "_attachEvent",
      value: function _attachEvent(event) {
        var _this = this;
  
        var pos = 0;
        var eventStart = this.localeMoment(event.start);
        this.events.forEach(function (item, index) {
          var start = _this.localeMoment(item.start);
  
          if (eventStart >= start) pos = index + 1;
        });
        this.events.splice(pos, 0, event);
      }
    }, {
      key: "_handleRecurringEvents",
      value: function _handleRecurringEvents() {
        var _this2 = this;
  
        var recurringEvents = this.events.filter(function (x) {
          return !!x.rrule;
        });
        recurringEvents.forEach(function (item) {
          _this2._detachEvent(item);
        });
        recurringEvents.forEach(function (item) {
          var windowStart = _this2.localeMoment(_this2.startDate),
              windowEnd = _this2.localeMoment(_this2.endDate).add(1, 'days'),
              oldStart = _this2.localeMoment(item.start),
              oldEnd = _this2.localeMoment(item.end),
              rule = (0, _rrule.rrulestr)(item.rrule),
              oldDtstart = undefined,
              oldUntil = rule.origOptions.until || windowEnd.toDate();
  
          if (!!rule.origOptions.dtstart) {
            oldDtstart = _this2.localeMoment(rule.origOptions.dtstart);
          } //rule.origOptions.dtstart = oldStart.toDate();
  
  
          if (windowEnd < oldUntil) {
            rule.origOptions.until = windowEnd.toDate();
          } //reload
  
  
          rule = (0, _rrule.rrulestr)(rule.toString());
  
          if (item.exdates || item.exrule) {
            var rruleSet = new _rrule.RRuleSet();
            rruleSet.rrule(rule);
  
            if (item.exrule) {
              rruleSet.exrule((0, _rrule.rrulestr)(item.exrule));
            }
  
            if (item.exdates) {
              item.exdates.forEach(function (exdate) {
                rruleSet.exdate(_this2.localeMoment(exdate).toDate());
              });
            }
  
            rule = rruleSet;
          }
  
          var all = rule.all();
          var newEvents = all.map(function (time, index) {
            return _objectSpread(_objectSpread({}, item), {}, {
              recurringEventId: item.id,
              recurringEventStart: item.start,
              recurringEventEnd: item.end,
              id: "".concat(item.id, "-").concat(index),
              start: rule.origOptions.tzid ? _this2.localeMoment.utc(time).utcOffset(_this2.localeMoment().utcOffset(), true).format(_index.DATETIME_FORMAT) : _this2.localeMoment(time).format(_index.DATETIME_FORMAT),
              end: rule.origOptions.tzid ? _this2.localeMoment.utc(time).utcOffset(_this2.localeMoment().utcOffset(), true).add(oldEnd.diff(oldStart), 'ms').add(_this2.localeMoment(oldUntil).utcOffset() - _this2.localeMoment(item.start).utcOffset(), "m").format(_index.DATETIME_FORMAT) : _this2.localeMoment(time).add(oldEnd.diff(oldStart), 'ms').format(_index.DATETIME_FORMAT)
            });
          });
          newEvents.forEach(function (newEvent) {
            var eventStart = _this2.localeMoment(newEvent.start),
                eventEnd = _this2.localeMoment(newEvent.end);
  
            if (_this2.isEventInTimeWindow(eventStart, eventEnd, windowStart, windowEnd) && (!oldDtstart || eventStart >= oldDtstart)) {
              _this2._attachEvent(newEvent);
            }
          });
        });
      }
    }, {
      key: "_resolveDate",
      value: function _resolveDate(num) {
        var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
        if (date != undefined) this.selectDate = this.localeMoment(date).format(_index.DATE_FORMAT);
  
        if (this.viewType === _index.ViewTypes.Week) {
          this.startDate = date != undefined ? this.localeMoment(date).startOf('week').format(_index.DATE_FORMAT) : this.localeMoment(this.startDate).add(num, 'weeks').format(_index.DATE_FORMAT);
          this.endDate = this.localeMoment(this.startDate).endOf('week').format(_index.DATE_FORMAT);
        } else if (this.viewType === _index.ViewTypes.Day) {
          this.startDate = date != undefined ? this.selectDate : this.localeMoment(this.startDate).add(num, 'days').format(_index.DATE_FORMAT);
          this.endDate = this.startDate;
        } else if (this.viewType === _index.ViewTypes.Month) {
          this.startDate = date != undefined ? this.localeMoment(date).startOf('month').format(_index.DATE_FORMAT) : this.localeMoment(this.startDate).add(num, 'months').format(_index.DATE_FORMAT);
          this.endDate = this.localeMoment(this.startDate).endOf('month').format(_index.DATE_FORMAT);
        } else if (this.viewType === _index.ViewTypes.Quarter) {
          this.startDate = date != undefined ? this.localeMoment(date).startOf('quarter').format(_index.DATE_FORMAT) : this.localeMoment(this.startDate).add(num, 'quarters').format(_index.DATE_FORMAT);
          this.endDate = this.localeMoment(this.startDate).endOf('quarter').format(_index.DATE_FORMAT);
        } else if (this.viewType === _index.ViewTypes.Year) {
          this.startDate = date != undefined ? this.localeMoment(date).startOf('year').format(_index.DATE_FORMAT) : this.localeMoment(this.startDate).add(num, 'years').format(_index.DATE_FORMAT);
          this.endDate = this.localeMoment(this.startDate).endOf('year').format(_index.DATE_FORMAT);
        } else if (this.viewType === _index.ViewTypes.Custom || this.viewType === _index.ViewTypes.Custom1 || this.viewType === _index.ViewTypes.Custom2) {
          if (this.behaviors.getCustomDateFunc != undefined) {
            var customDate = this.behaviors.getCustomDateFunc(this, num, date);
            this.startDate = customDate.startDate;
            this.endDate = customDate.endDate;
            if (!!customDate.cellUnit) this.cellUnit = customDate.cellUnit;
          } else {
            throw new Error('This is custom view type, set behaviors.getCustomDateFunc func to resolve the time window(startDate and endDate) yourself');
          }
        }
      }
    }, {
      key: "_createHeaders",
      value: function _createHeaders() {
        var headers = [],
            start = this.localeMoment(this.startDate),
            end = this.localeMoment(this.endDate),
            header = start;
  
        if (this.showAgenda) {
          headers.push({
            time: header.format(_index.DATETIME_FORMAT),
            nonWorkingTime: false
          });
        } else {
          if (this.cellUnit === _index.CellUnits.Hour) {
            start = start.add(this.config.dayStartFrom, 'hours');
            end = end.add(this.config.dayStopTo, 'hours');
            header = start;
  
            while (header >= start && header <= end) {
              var minuteSteps = this.getMinuteStepsInHour();
  
              for (var i = 0; i < minuteSteps; i++) {
                var hour = header.hour();
  
                if (hour >= this.config.dayStartFrom && hour <= this.config.dayStopTo) {
                  var time = header.format(_index.DATETIME_FORMAT);
                  var nonWorkingTime = this.behaviors.isNonWorkingTimeFunc(this, time);
                  headers.push({
                    time: time,
                    nonWorkingTime: nonWorkingTime
                  });
                }
  
                header = header.add(this.config.minuteStep, 'minutes');
              }
            }
          } else {
            while (header >= start && header <= end) {
              var _time = header.format(_index.DATETIME_FORMAT);
  
              var dayOfWeek = header.weekday();
  
              if (this.config.displayWeekend || dayOfWeek !== 0 && dayOfWeek !== 6) {
                var _nonWorkingTime = this.behaviors.isNonWorkingTimeFunc(this, _time);
  
                headers.push({
                  time: _time,
                  nonWorkingTime: _nonWorkingTime
                });
              }
  
              header = header.add(1, 'days');
            }
          }
        }
  
        this.headers = headers;
      }
    }, {
      key: "_createInitHeaderEvents",
      value: function _createInitHeaderEvents(header) {
        var start = this.localeMoment(header.time),
            startValue = start.format(_index.DATETIME_FORMAT);
        var endValue = this.showAgenda ? this.viewType === _index.ViewTypes.Week ? start.add(1, 'weeks').format(_index.DATETIME_FORMAT) : this.viewType === _index.ViewTypes.Day ? start.add(1, 'days').format(_index.DATETIME_FORMAT) : this.viewType === _index.ViewTypes.Month ? start.add(1, 'months').format(_index.DATETIME_FORMAT) : this.viewType === _index.ViewTypes.Year ? start.add(1, 'years').format(_index.DATETIME_FORMAT) : this.viewType === _index.ViewTypes.Quarter ? start.add(1, 'quarters').format(_index.DATETIME_FORMAT) : this.localeMoment(this.endDate).add(1, 'days').format(_index.DATETIME_FORMAT) : this.cellUnit === _index.CellUnits.Hour ? start.add(this.config.minuteStep, 'minutes').format(_index.DATETIME_FORMAT) : start.add(1, 'days').format(_index.DATETIME_FORMAT);
        return {
          time: header.time,
          nonWorkingTime: header.nonWorkingTime,
          start: startValue,
          end: endValue,
          count: 0,
          addMore: 0,
          addMoreIndex: 0,
          events: [,,,]
        };
      }
    }, {
      key: "_createHeaderEvent",
      value: function _createHeaderEvent(render, span, eventItem) {
        return {
          render: render,
          span: span,
          eventItem: eventItem
        };
      }
    }, {
      key: "_getEventSlotId",
      value: function _getEventSlotId(event) {
        return this.isEventPerspective ? this._getEventGroupId(event) : event.resourceId;
      }
    }, {
      key: "_getEventGroupId",
      value: function _getEventGroupId(event) {
        return !!event.groupId ? event.groupId.toString() : event.id.toString();
      }
    }, {
      key: "_getEventGroupName",
      value: function _getEventGroupName(event) {
        return !!event.groupName ? event.groupName : event.title;
      }
    }, {
      key: "_generateEventGroups",
      value: function _generateEventGroups() {
        var _this3 = this;
  
        var eventGroups = [];
        var set = new Set();
        this.events.forEach(function (item) {
          var groupId = _this3._getEventGroupId(item);
  
          var groupName = _this3._getEventGroupName(item);
  
          if (!set.has(groupId)) {
            eventGroups.push({
              id: groupId,
              name: groupName,
              state: item
            });
            set.add(groupId);
          }
        });
        this.eventGroups = eventGroups;
      }
    }, {
      key: "_createInitRenderData",
      value: function _createInitRenderData(isEventPerspective, eventGroups, resources, headers) {
        var _this4 = this;
  
        var slots = isEventPerspective ? eventGroups : resources;
        var slotTree = [],
            slotMap = new Map();
        slots.forEach(function (slot) {
          var headerEvents = headers.map(function (header) {
            return _this4._createInitHeaderEvents(header);
          });
          var slotRenderData = {
            slotId: slot.id,
            slotName: slot.name,
            parentId: slot.parentId,
            groupOnly: slot.groupOnly,
            hasSummary: false,
            rowMaxCount: 0,
            rowHeight: _this4.config.nonAgendaSlotMinHeight !== 0 ? _this4.config.nonAgendaSlotMinHeight : _this4.config.eventItemLineHeight + 2,
            headerItems: headerEvents,
            indent: 0,
            hasChildren: false,
            expanded: true,
            render: true
          };
          var id = slot.id;
          var value = undefined;
  
          if (slotMap.has(id)) {
            value = slotMap.get(id);
            value.data = slotRenderData;
          } else {
            value = {
              data: slotRenderData,
              children: []
            };
            slotMap.set(id, value);
          }
  
          var parentId = slot.parentId;
  
          if (!parentId || parentId === id) {
            slotTree.push(value);
          } else {
            var parentValue = undefined;
  
            if (slotMap.has(parentId)) {
              parentValue = slotMap.get(parentId);
            } else {
              parentValue = {
                data: undefined,
                children: []
              };
              slotMap.set(parentId, parentValue);
            }
  
            parentValue.children.push(value);
          }
        });
        var slotStack = [];
        var i;
  
        for (i = slotTree.length - 1; i >= 0; i--) {
          slotStack.push(slotTree[i]);
        }
  
        var initRenderData = [];
        var currentNode = undefined;
  
        while (slotStack.length > 0) {
          currentNode = slotStack.pop();
  
          if (currentNode.data.indent > 0) {
            currentNode.data.render = this.config.defaultExpanded;
          }
  
          if (currentNode.children.length > 0) {
            currentNode.data.hasChildren = true;
            currentNode.data.expanded = this.config.defaultExpanded;
          }
  
          initRenderData.push(currentNode.data);
  
          for (i = currentNode.children.length - 1; i >= 0; i--) {
            currentNode.children[i].data.indent = currentNode.data.indent + 1;
            slotStack.push(currentNode.children[i]);
          }
        }
  
        return initRenderData;
      }
    }, {
      key: "_getSpan",
      value: function _getSpan(startTime, endTime, headers) {
        if (this.showAgenda) return 1;
        var start = this.localeMoment(startTime),
            end = this.localeMoment(endTime),
            span = 0;
  
        var _iterator = _createForOfIteratorHelper(headers),
            _step;
  
        try {
          for (_iterator.s(); !(_step = _iterator.n()).done;) {
            var header = _step.value;
            var spanStart = this.localeMoment(header.time),
                spanEnd = this.cellUnit === _index.CellUnits.Hour ? this.localeMoment(header.time).add(this.config.minuteStep, 'minutes') : this.localeMoment(header.time).add(1, 'days');
  
            if (spanStart < end && spanEnd > start) {
              span++;
            }
          }
        } catch (err) {
          _iterator.e(err);
        } finally {
          _iterator.f();
        }
  
        return span;
      }
    }, {
      key: "_validateResource",
      value: function _validateResource(resources) {
        if (Object.prototype.toString.call(resources) !== "[object Array]") {
          throw new Error('Resources should be Array object');
        }
  
        resources.forEach(function (item, index) {
          if (item == undefined) {
            console.error("Resource undefined: ".concat(index));
            throw new Error("Resource undefined: ".concat(index));
          }
  
          if (item.id == undefined || item.name == undefined) {
            console.error('Resource property missed', index, item);
            throw new Error("Resource property undefined: ".concat(index));
          }
        });
      }
    }, {
      key: "_validateEventGroups",
      value: function _validateEventGroups(eventGroups) {
        if (Object.prototype.toString.call(eventGroups) !== "[object Array]") {
          throw new Error('Event groups should be Array object');
        }
  
        eventGroups.forEach(function (item, index) {
          if (item == undefined) {
            console.error("Event group undefined: ".concat(index));
            throw new Error("Event group undefined: ".concat(index));
          }
  
          if (item.id == undefined || item.name == undefined) {
            console.error('Event group property missed', index, item);
            throw new Error("Event group property undefined: ".concat(index));
          }
        });
      }
    }, {
      key: "_validateEvents",
      value: function _validateEvents(events) {
        if (Object.prototype.toString.call(events) !== "[object Array]") {
          throw new Error('Events should be Array object');
        }
  
        events.forEach(function (e, index) {
          if (e == undefined) {
            console.error("Event undefined: ".concat(index));
            throw new Error("Event undefined: ".concat(index));
          }
  
          if (e.id == undefined || e.resourceId == undefined || e.title == undefined || e.start == undefined || e.end == undefined) {
            console.error('Event property missed', index, e);
            throw new Error("Event property undefined: ".concat(index));
          }
        });
      }
    }, {
      key: "_validateMinuteStep",
      value: function _validateMinuteStep(minuteStep) {
        if (60 % minuteStep !== 0) {
          console.error('Minute step is not set properly - 60 minutes must be divisible without remainder by this number');
          throw new Error('Minute step is not set properly - 60 minutes must be divisible without remainder by this number');
        }
      }
    }, {
      key: "_compare",
      value: function _compare(event1, event2) {
        var start1 = this.localeMoment(event1.start),
            start2 = this.localeMoment(event2.start);
        if (start1 !== start2) return start1 < start2 ? -1 : 1;
        var end1 = this.localeMoment(event1.end),
            end2 = this.localeMoment(event2.end);
        if (end1 !== end2) return end1 < end2 ? -1 : 1;
        return event1.id < event2.id ? -1 : 1;
      }
    }, {
      key: "_createRenderData",
      value: function _createRenderData() {
        var _this5 = this;
  
        var initRenderData = this._createInitRenderData(this.isEventPerspective, this.eventGroups, this.resources, this.headers); //this.events.sort(this._compare);
  
  
        var cellMaxEventsCount = this.getCellMaxEvents();
        var cellMaxEventsCountValue = 30;
        this.events.forEach(function (item) {
          var resourceEventsList = initRenderData.filter(function (x) {
            return x.slotId === _this5._getEventSlotId(item);
          });
  
          if (resourceEventsList.length > 0) {
            var resourceEvents = resourceEventsList[0];
  
            var span = _this5._getSpan(item.start, item.end, _this5.headers);
  
            var eventStart = _this5.localeMoment(item.start),
                eventEnd = _this5.localeMoment(item.end);
  
            var pos = -1;
            resourceEvents.headerItems.forEach(function (header, index) {
              var headerStart = _this5.localeMoment(header.start),
                  headerEnd = _this5.localeMoment(header.end);
  
              if (headerEnd > eventStart && headerStart < eventEnd) {
                header.count = header.count + 1;
  
                if (header.count > resourceEvents.rowMaxCount) {
                  resourceEvents.rowMaxCount = header.count;
                  var rowsCount = cellMaxEventsCount <= cellMaxEventsCountValue && resourceEvents.rowMaxCount > cellMaxEventsCount ? cellMaxEventsCount : resourceEvents.rowMaxCount;
                  var newRowHeight = rowsCount * _this5.config.eventItemLineHeight + (_this5.config.creatable && _this5.config.checkConflict === false ? 20 : 2);
                  if (newRowHeight > resourceEvents.rowHeight) resourceEvents.rowHeight = newRowHeight;
                }
  
                if (pos === -1) {
                  var tmp = 0;
  
                  while (header.events[tmp] !== undefined) {
                    tmp++;
                  }
  
                  pos = tmp;
                }
  
                var render = headerStart <= eventStart || index === 0;
  
                if (render === false) {
                  var previousHeader = resourceEvents.headerItems[index - 1];
  
                  var previousHeaderStart = _this5.localeMoment(previousHeader.start),
                      previousHeaderEnd = _this5.localeMoment(previousHeader.end);
  
                  if (previousHeaderEnd <= eventStart || previousHeaderStart >= eventEnd) render = true;
                }
  
                header.events[pos] = _this5._createHeaderEvent(render, span, item);
              }
            });
          }
        });
  
        if (cellMaxEventsCount <= cellMaxEventsCountValue || this.behaviors.getSummaryFunc !== undefined) {
          initRenderData.forEach(function (resourceEvents) {
            var hasSummary = false;
            resourceEvents.headerItems.forEach(function (headerItem) {
              if (cellMaxEventsCount <= cellMaxEventsCountValue) {
                var renderItemsCount = 0,
                    addMoreIndex = 0,
                    index = 0;
  
                while (index < cellMaxEventsCount - 1) {
                  if (headerItem.events[index] !== undefined) {
                    renderItemsCount++;
                    addMoreIndex = index + 1;
                  }
  
                  index++;
                }
  
                if (headerItem.events[index] !== undefined) {
                  if (renderItemsCount + 1 < headerItem.count) {
                    headerItem.addMore = headerItem.count - renderItemsCount;
                    headerItem.addMoreIndex = addMoreIndex;
                  }
                } else {
                  if (renderItemsCount < headerItem.count) {
                    headerItem.addMore = headerItem.count - renderItemsCount;
                    headerItem.addMoreIndex = addMoreIndex;
                  }
                }
              }
  
              if (_this5.behaviors.getSummaryFunc !== undefined) {
                var events = [];
                headerItem.events.forEach(function (e) {
                  if (!!e && !!e.eventItem) events.push(e.eventItem);
                });
                headerItem.summary = _this5.behaviors.getSummaryFunc(_this5, events, resourceEvents.slotId, resourceEvents.slotName, headerItem.start, headerItem.end);
                if (!!headerItem.summary && headerItem.summary.text != undefined) hasSummary = true;
              }
            });
            resourceEvents.hasSummary = hasSummary;
  
            if (hasSummary) {
              var rowsCount = cellMaxEventsCount <= cellMaxEventsCountValue && resourceEvents.rowMaxCount > cellMaxEventsCount ? cellMaxEventsCount : resourceEvents.rowMaxCount;
              var newRowHeight = (rowsCount + 1) * _this5.config.eventItemLineHeight + (_this5.config.creatable && _this5.config.checkConflict === false ? 20 : 2);
              if (newRowHeight > resourceEvents.rowHeight) resourceEvents.rowHeight = newRowHeight;
            }
          });
        }
  
        this.renderData = initRenderData;
      }
    }, {
      key: "_startResizing",
      value: function _startResizing() {
        this.resizing = true;
      }
    }, {
      key: "_stopResizing",
      value: function _stopResizing() {
        this.resizing = false;
      }
    }, {
      key: "_isResizing",
      value: function _isResizing() {
        return this.resizing;
      }
    }]);
  
    return SchedulerData;
  }();
  
  exports["default"] = SchedulerData;