import { i, x } from "./lit-DKg0et_P.mjs"; import { n as n$1, t } from "./property-C8WJQOrH.mjs"; import { e, n } from "./ref-BivNNNRN.mjs"; import { S as SVG_ICON_CALENDAR, a as SVG_ICON_INTERNET, e as escapeXml } from "./index-fgowJCc1.mjs"; import { g as getTimezones } from "./timezones-B0vBBzCP.mjs"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __decorateClass = (decorators, target, key, kind) => { var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target; for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--) if (decorator = decorators[i2]) result = (kind ? decorator(target, key, result) : decorator(result)) || result; if (kind && result) __defProp(target, key, result); return result; }; let CreateCalendarForm = class extends i { constructor() { super(); this.user = ""; this.dialog = e(); this.form = e(); this.timezones = []; this.resetForm(); this.fetchTimezones(); } resetForm() { this.form.value?.reset(); this.principal = this.user; this.cal_id = self.crypto.randomUUID(); this.displayname = ""; this.description = ""; this.timezone_id = ""; this.color = ""; this.isSubscription = false; this.subscriptionUrl = null; this.components = /* @__PURE__ */ new Set(["VEVENT", "VTODO"]); } async fetchTimezones() { this.timezones = await getTimezones(); } createRenderRoot() { return this; } render() { return x` this.dialog.value.showModal()}>Create calendar this.resetForm()}> Create calendar principal (for group calendars) this.principal = e2.target.value}> ${this.user} ${window.rusticalUser.memberships.map((membership) => x` ${membership} `)} id this.cal_id = e2.target.value} /> Displayname this.displayname = e2.target.value} /> Timezone (optional) this.timezone_id = e2.target.value}> No timezone ${this.timezones.map((timezone) => x` ${timezone} `)} Description this.description = e2.target.value} /> Color this.color = e2.target.value} /> Type this.isSubscription = false}> ${SVG_ICON_CALENDAR} Calendar this.isSubscription = true}> ${SVG_ICON_INTERNET} webCal Subscription ${this.isSubscription ? x` Subscription URL this.subscriptionUrl = e2.target.value} /> ` : x``} Components ${["VEVENT", "VTODO", "VJOURNAL"].map((comp) => x` Support ${comp} e2.target.checked ? this.components.add(e2.target.value) : this.components.delete(e2.target.value)} .checked=${this.components.has(comp)} /> `)} Create { event.preventDefault(); this.dialog.value.close(); }} class="cancel">Cancel `; } async submit(e2) { e2.preventDefault(); if (!this.cal_id) { alert("Empty id"); return; } if (!this.displayname) { alert("Empty displayname"); return; } if (!this.components.size) { alert("No calendar components selected"); return; } if (this.isSubscription && !this.subscriptionUrl) { alert("Invalid subscription url"); return; } let response = await fetch(`/caldav/principal/${this.principal || this.user}/${this.cal_id}`, { method: "MKCOL", headers: { "Content-Type": "application/xml" }, body: ` ${escapeXml(this.displayname)} ${this.timezone_id ? `${escapeXml(this.timezone_id)}` : ""} ${this.description ? `${escapeXml(this.description)}` : ""} ${this.color ? `${escapeXml(this.color)}` : ""} ${this.isSubscription && this.subscriptionUrl ? `${escapeXml(this.subscriptionUrl)}` : ""} ${Array.from(this.components.keys()).map((comp) => ``).join("\n")} ` }); if (response.status >= 400) { alert(`Error ${response.status}: ${await response.text()}`); return null; } window.location.reload(); return null; } }; __decorateClass([ n$1() ], CreateCalendarForm.prototype, "user", 2); __decorateClass([ n$1() ], CreateCalendarForm.prototype, "principal", 2); __decorateClass([ n$1() ], CreateCalendarForm.prototype, "cal_id", 2); __decorateClass([ n$1() ], CreateCalendarForm.prototype, "displayname", 2); __decorateClass([ n$1() ], CreateCalendarForm.prototype, "description", 2); __decorateClass([ n$1() ], CreateCalendarForm.prototype, "timezone_id", 2); __decorateClass([ n$1() ], CreateCalendarForm.prototype, "color", 2); __decorateClass([ n$1() ], CreateCalendarForm.prototype, "isSubscription", 2); __decorateClass([ n$1() ], CreateCalendarForm.prototype, "subscriptionUrl", 2); __decorateClass([ n$1() ], CreateCalendarForm.prototype, "components", 2); __decorateClass([ n$1() ], CreateCalendarForm.prototype, "timezones", 2); CreateCalendarForm = __decorateClass([ t("create-calendar-form") ], CreateCalendarForm); export { CreateCalendarForm };