"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Event = void 0; const dayjs_1 = __importDefault(require("dayjs")); class Event { constructor(obj) { this.id = obj.id; this.start = obj.start; this.end = obj.end; this.ressourceId = obj.ressourceId; this.title = (obj === null || obj === void 0 ? void 0 : obj.title) || this.id; this.isDisplayed = false; this.offset = 0; this.editable = (obj === null || obj === void 0 ? void 0 : obj.editable) === undefined ? null : obj.editable; this.ressourceEditable = (obj === null || obj === void 0 ? void 0 : obj.ressourceEditable) === undefined ? null : obj.ressourceEditable; this.moving = false; this.selected = false; this.bgColor = obj.bgColor; this.content = obj.content; } get startStr() { return this.start.toISOString(); } get endStr() { return this.end.toISOString(); } static toTimeSlot(obj) { if (obj instanceof Event) { return obj; } else { return new Event(obj); } } toJSON() { const output = { id: this.id, start: this.startStr, end: this.startStr, title: this.title, ressourceId: this.ressourceId, editable: this.editable, ressourceEditable: this.ressourceEditable, bgColor: this.bgColor, content: this.content }; if (this.bgColor) { output.bgColor = this.bgColor; } if (this.content) { output.content = this.content; } return output; } static fromJSON(input) { let obj; if (typeof input == "string") { obj = JSON.parse(input); } else { obj = input; } const start = dayjs_1.default(obj.start); const end = dayjs_1.default(obj.end); if (!start.isValid()) { throw new Error(`Error during the import of the Event '${obj.id}': Invalid starting date`); } else { if (!end.isValid()) { throw new Error(`Error during the import of the Event '${obj.id}': Invalid ending date`); } else { const iEvent = { id: obj.id, start: start.toDate(), end: end.toDate(), title: obj.title, ressourceId: obj.ressourceId, editable: obj.editable, ressourceEditable: obj.ressourceEditable, bgColor: obj.bgColor, content: obj.content }; if (obj.bgColor) { iEvent.bgColor = obj.bgColor; } if (obj.content) { iEvent.content = obj.content; } return new Event(iEvent); } } } } exports.Event = Event; exports.default = Event; //# sourceMappingURL=Event.js.map