import { x as E, be as H, z as D, a5 as v, cd as R, ct as N, C as b, bv as T, bR as A, bS as k, ch as M, af as O, o as L, q as G, t as S, cw as U, B as I, a_ as j, b0 as C, aZ as F, cn as z, bU as P, az as V, bQ as p } from "../core/internal-common.mjs";
import { createElement as n, Fragment as w } from "../../preact/dist/preact.module.mjs";
class _ extends I {
  constructor() {
    super(...arguments), this.state = {
      textId: v()
    };
  }
  render() {
    let { theme: e, dateEnv: t, options: s, viewApi: r } = this.context, { cellId: i, dayDate: c, todayRange: o } = this.props, { textId: l } = this.state, d = j(c, o), f = s.listDayFormat ? t.format(c, s.listDayFormat) : "", h = s.listDaySideFormat ? t.format(c, s.listDaySideFormat) : "", u = Object.assign({
      date: t.toDate(c),
      view: r,
      textId: l,
      text: f,
      sideText: h,
      navLinkAttrs: C(this.context, c),
      sideNavLinkAttrs: C(this.context, c, "day", !1)
    }, d);
    return n(b, { elTag: "tr", elClasses: [
      "fc-list-day",
      ...F(d, e)
    ], elAttrs: {
      "data-date": T(c)
    }, renderProps: u, generatorName: "dayHeaderContent", customGenerator: s.dayHeaderContent, defaultGenerator: B, classNameGenerator: s.dayHeaderClassNames, didMount: s.dayHeaderDidMount, willUnmount: s.dayHeaderWillUnmount }, (g) => (
      // TODO: force-hide top border based on :first-child
      n(
        "th",
        { scope: "colgroup", colSpan: 3, id: i, "aria-labelledby": l },
        n(g, { elTag: "div", elClasses: [
          "fc-list-day-cushion",
          e.getClass("tableCellShaded")
        ] })
      )
    ));
  }
}
function B(a) {
  return n(
    w,
    null,
    a.text && n("a", Object.assign({ id: a.textId, className: "fc-list-day-text" }, a.navLinkAttrs), a.text),
    a.sideText && /* not keyboard tabbable */
    n("a", Object.assign({ "aria-hidden": !0, className: "fc-list-day-side-text" }, a.sideNavLinkAttrs), a.sideText)
  );
}
const $ = E({
  hour: "numeric",
  minute: "2-digit",
  meridiem: "short"
});
class q extends I {
  render() {
    let { props: e, context: t } = this, { options: s } = t, { seg: r, timeHeaderId: i, eventHeaderId: c, dateHeaderId: o } = e, l = s.eventTimeFormat || $;
    return n(z, Object.assign({}, e, { elTag: "tr", elClasses: [
      "fc-list-event",
      r.eventRange.def.url && "fc-event-forced-url"
    ], defaultGenerator: () => W(r, t), seg: r, timeText: "", disableDragging: !0, disableResizing: !0 }), (d, f) => n(
      w,
      null,
      Q(r, l, t, i, o),
      n(
        "td",
        { "aria-hidden": !0, className: "fc-list-event-graphic" },
        n("span", { className: "fc-list-event-dot", style: {
          borderColor: f.borderColor || f.backgroundColor
        } })
      ),
      n(d, { elTag: "td", elClasses: ["fc-list-event-title"], elAttrs: { headers: `${c} ${o}` } })
    ));
  }
}
function W(a, e) {
  let t = P(a, e);
  return n("a", Object.assign({}, t), a.eventRange.def.title);
}
function Q(a, e, t, s, r) {
  let { options: i } = t;
  if (i.displayEventTime !== !1) {
    let c = a.eventRange.def, o = a.eventRange.instance, l = !1, d;
    if (c.allDay ? l = !0 : V(a.eventRange.range) ? a.isStart ? d = p(a, e, t, null, null, o.range.start, a.end) : a.isEnd ? d = p(a, e, t, null, null, a.start, o.range.end) : l = !0 : d = p(a, e, t), l) {
      let f = {
        text: t.options.allDayText,
        view: t.viewApi
      };
      return n(b, { elTag: "td", elClasses: ["fc-list-event-time"], elAttrs: {
        headers: `${s} ${r}`
      }, renderProps: f, generatorName: "allDayContent", customGenerator: i.allDayContent, defaultGenerator: X, classNameGenerator: i.allDayClassNames, didMount: i.allDayDidMount, willUnmount: i.allDayWillUnmount });
    }
    return n("td", { className: "fc-list-event-time" }, d);
  }
  return null;
}
function X(a) {
  return a.text;
}
class ae extends H {
  constructor() {
    super(...arguments), this.computeDateVars = D(Z), this.eventStoreToSegs = D(this._eventStoreToSegs), this.state = {
      timeHeaderId: v(),
      eventHeaderId: v(),
      dateHeaderIdRoot: v()
    }, this.setRootEl = (e) => {
      e ? this.context.registerInteractiveComponent(this, {
        el: e
      }) : this.context.unregisterInteractiveComponent(this);
    };
  }
  render() {
    let { props: e, context: t } = this, { dayDates: s, dayRanges: r } = this.computeDateVars(e.dateProfile), i = this.eventStoreToSegs(e.eventStore, e.eventUiBases, r);
    return n(
      N,
      { elRef: this.setRootEl, elClasses: [
        "fc-list",
        t.theme.getClass("table"),
        t.options.stickyHeaderDates !== !1 ? "fc-list-sticky" : ""
      ], viewSpec: t.viewSpec },
      n(R, { liquid: !e.isHeightAuto, overflowX: e.isHeightAuto ? "visible" : "hidden", overflowY: e.isHeightAuto ? "visible" : "auto" }, i.length > 0 ? this.renderSegList(i, s) : this.renderEmptyMessage())
    );
  }
  renderEmptyMessage() {
    let { options: e, viewApi: t } = this.context, s = {
      text: e.noEventsText,
      view: t
    };
    return n(b, { elTag: "div", elClasses: ["fc-list-empty"], renderProps: s, generatorName: "noEventsContent", customGenerator: e.noEventsContent, defaultGenerator: Y, classNameGenerator: e.noEventsClassNames, didMount: e.noEventsDidMount, willUnmount: e.noEventsWillUnmount }, (r) => n(r, { elTag: "div", elClasses: ["fc-list-empty-cushion"] }));
  }
  renderSegList(e, t) {
    let { theme: s, options: r } = this.context, { timeHeaderId: i, eventHeaderId: c, dateHeaderIdRoot: o } = this.state, l = J(e);
    return n(M, { unit: "day" }, (d, f) => {
      let h = [];
      for (let u = 0; u < l.length; u += 1) {
        let g = l[u];
        if (g) {
          let m = T(t[u]), x = o + "-" + m;
          h.push(n(_, { key: m, cellId: x, dayDate: t[u], todayRange: f })), g = A(g, r.eventOrder);
          for (let y of g)
            h.push(n(q, Object.assign({ key: m + ":" + y.eventRange.instance.instanceId, seg: y, isDragging: !1, isResizing: !1, isDateSelecting: !1, isSelected: !1, timeHeaderId: i, eventHeaderId: c, dateHeaderId: x }, k(y, f, d))));
        }
      }
      return n(
        "table",
        { className: "fc-list-table " + s.getClass("table") },
        n(
          "thead",
          null,
          n(
            "tr",
            null,
            n("th", { scope: "col", id: i }, r.timeHint),
            n("th", { scope: "col", "aria-hidden": !0 }),
            n("th", { scope: "col", id: c }, r.eventHint)
          )
        ),
        n("tbody", null, h)
      );
    });
  }
  _eventStoreToSegs(e, t, s) {
    return this.eventRangesToSegs(O(e, t, this.props.dateProfile.activeRange, this.context.options.nextDayThreshold).fg, s);
  }
  eventRangesToSegs(e, t) {
    let s = [];
    for (let r of e)
      s.push(...this.eventRangeToSegs(r, t));
    return s;
  }
  eventRangeToSegs(e, t) {
    let { dateEnv: s } = this.context, { nextDayThreshold: r } = this.context.options, i = e.range, c = e.def.allDay, o, l, d, f = [];
    for (o = 0; o < t.length; o += 1)
      if (l = L(i, t[o]), l && (d = {
        component: this,
        eventRange: e,
        start: l.start,
        end: l.end,
        isStart: e.isStart && l.start.valueOf() === i.start.valueOf(),
        isEnd: e.isEnd && l.end.valueOf() === i.end.valueOf(),
        dayIndex: o
      }, f.push(d), !d.isEnd && !c && o + 1 < t.length && i.end < s.add(t[o + 1].start, r))) {
        d.end = i.end, d.isEnd = !0;
        break;
      }
    return f;
  }
}
function Y(a) {
  return a.text;
}
function Z(a) {
  let e = G(a.renderRange.start), t = a.renderRange.end, s = [], r = [];
  for (; e < t; )
    s.push(e), r.push({
      start: e,
      end: S(e, 1)
    }), e = S(e, 1);
  return { dayDates: s, dayRanges: r };
}
function J(a) {
  let e = [], t, s;
  for (t = 0; t < a.length; t += 1)
    s = a[t], (e[s.dayIndex] || (e[s.dayIndex] = [])).push(s);
  return e;
}
var K = ':root{--fc-list-event-dot-width:10px;--fc-list-event-hover-bg-color:#f5f5f5}.fc-theme-standard .fc-list{border:1px solid var(--fc-border-color)}.fc .fc-list-empty{align-items:center;background-color:var(--fc-neutral-bg-color);display:flex;height:100%;justify-content:center}.fc .fc-list-empty-cushion{margin:5em 0}.fc .fc-list-table{border-style:hidden;width:100%}.fc .fc-list-table tr>*{border-left:0;border-right:0}.fc .fc-list-sticky .fc-list-day>*{background:var(--fc-page-bg-color);position:sticky;top:0}.fc .fc-list-table thead{left:-10000px;position:absolute}.fc .fc-list-table tbody>tr:first-child th{border-top:0}.fc .fc-list-table th{padding:0}.fc .fc-list-day-cushion,.fc .fc-list-table td{padding:8px 14px}.fc .fc-list-day-cushion:after{clear:both;content:"";display:table}.fc-theme-standard .fc-list-day-cushion{background-color:var(--fc-neutral-bg-color)}.fc-direction-ltr .fc-list-day-text,.fc-direction-rtl .fc-list-day-side-text{float:left}.fc-direction-ltr .fc-list-day-side-text,.fc-direction-rtl .fc-list-day-text{float:right}.fc-direction-ltr .fc-list-table .fc-list-event-graphic{padding-right:0}.fc-direction-rtl .fc-list-table .fc-list-event-graphic{padding-left:0}.fc .fc-list-event.fc-event-forced-url{cursor:pointer}.fc .fc-list-event:hover td{background-color:var(--fc-list-event-hover-bg-color)}.fc .fc-list-event-graphic,.fc .fc-list-event-time{white-space:nowrap;width:1px}.fc .fc-list-event-dot{border:calc(var(--fc-list-event-dot-width)/2) solid var(--fc-event-border-color);border-radius:calc(var(--fc-list-event-dot-width)/2);box-sizing:content-box;display:inline-block;height:0;width:0}.fc .fc-list-event-title a{color:inherit;text-decoration:none}.fc .fc-list-event.fc-event-forced-url:hover a{text-decoration:underline}';
U(K);
export {
  ae as ListView
};
