import { jsxs as i, jsx as e, Fragment as W } from "react/jsx-runtime";
import { useState as m, useMemo as q, useCallback as I, useEffect as z } from "react";
import { t as C } from "../global.module.js";
import { B as G, a as J } from "../tools/icons.js";
import { g as F, c as Q, s as U, u as X, b as v, a as Z } from "../tools/tools.js";
import { f as L } from "../lite.js";
const $ = /* @__PURE__ */ new Date(), ee = function(j) {
  const {
    as: B = "div",
    bottomContent: f,
    className: w,
    disabled: n,
    dropOldClass: S,
    events: h,
    forceRows: g,
    initialMonth: P,
    initialYear: R,
    locale: c,
    onDateClick: d,
    onMonthChange: u,
    readOnly: p,
    selectedDate: y,
    style: M,
    topContent: D,
    variables: O,
    weekDays: x,
    weekStartsOn: b,
    ...A
  } = j, [l, K] = m(R ?? $.getFullYear()), [o, _] = m(P ?? $.getMonth()), [s, T] = m(null), [E, k] = m(
    F(l, o, h, g, b, x, y, c)
  ), H = q(() => {
    const a = Q(!S && "card card-body px-0 py-2", w), r = U((t, N) => ({ tKey: Z(N) }), O, M);
    return {
      className: a,
      style: r
    };
  }, [w, S, M, O]), Y = I(
    (a) => {
      if (n)
        return;
      T(null);
      const r = new Date(l, o + a);
      K(r.getFullYear()), _(r.getMonth()), !p && (u == null || u(r.getFullYear(), r.getMonth()));
    },
    [o, l, n, u, p]
  ), V = I(
    (a) => {
      if (n)
        return;
      const r = { ...a, active: !0 };
      T(s && s.date.toISOString() === r.date.toISOString() ? null : r), k((t) => X(r, t)), !p && (d == null || d(r));
    },
    [s, n, d, p]
  );
  return z(() => {
    k(
      F(l, o, h, g, b, x, y, c)
    );
  }, [o, l, h, g, c, y, x, b]), /* @__PURE__ */ i(B, { ...A, ...H, children: [
    D && D,
    /* @__PURE__ */ i("div", { className: "list-group border-0 row-gap-1 px-3", children: [
      /* @__PURE__ */ i("div", { className: "row align-items-center position-relative text-center mb-2", children: [
        /* @__PURE__ */ e("div", { className: "col px-1", onClick: () => Y(-1), children: /* @__PURE__ */ e(
          "div",
          {
            className: v(
              null,
              "user-select-none list-group-item list-group-item-action border-0 px-0 py-1 rounded text-secondary",
              n ? "disabled" : C.brlCursorPointer
            ),
            children: /* @__PURE__ */ e(G, {})
          }
        ) }),
        /* @__PURE__ */ e("div", { className: "col px-1" }),
        /* @__PURE__ */ e("div", { className: "col px-1" }),
        /* @__PURE__ */ e("div", { className: "col px-1" }),
        /* @__PURE__ */ e("div", { className: "col px-1" }),
        /* @__PURE__ */ e("div", { className: "col px-1" }),
        /* @__PURE__ */ e("div", { className: "col px-1", onClick: () => Y(1), children: /* @__PURE__ */ e(
          "div",
          {
            className: v(
              null,
              "user-select-none list-group-item list-group-item-action border-0 px-0 py-1 rounded text-secondary",
              n ? "disabled" : C.brlCursorPointer
            ),
            children: /* @__PURE__ */ e(J, {})
          }
        ) }),
        /* @__PURE__ */ e("div", { className: "position-absolute top-50 start-50 translate-middle w-auto text-nowrap", children: L(new Date(l, o), "MMMM yyyy", {
          locale: c
        }) })
      ] }),
      E.rows.map((a, r) => /* @__PURE__ */ e("div", { className: "row text-center", children: a.map((t, N) => r === 0 ? /* @__PURE__ */ e("div", { className: "col px-1", children: /* @__PURE__ */ e("div", { className: "list-group-item border-0 px-0 py-1 rounded text-body-secondary", children: t.value }) }, `${t.value}${N}`) : /* @__PURE__ */ e("div", { className: "col px-1", onClick: () => V(t), children: /* @__PURE__ */ i(
        "div",
        {
          className: v(
            null,
            "list-group-item list-group-item-action px-0 py-1 rounded",
            n ? "disabled" : C.brlCursorPointer,
            !t.isCurrentMonth && !t.active && "text-body-tertiary",
            t.active && "active",
            t.isToday ? "border-secondary-subtle" : t.events && t.events.length > 0 ? t.active ? "border-primary" : "border-danger-subtle" : "border-0"
          ),
          children: [
            L(t.date, "d", { locale: c }),
            t.active && t.events && t.events.length > 0 && /* @__PURE__ */ e("span", { className: "text-danger", children: "•" })
          ]
        }
      ) }, t.date.toISOString())) }, r))
    ] }),
    /* @__PURE__ */ e("div", { className: "px-2", children: s && s.events && s.events.length > 0 && /* @__PURE__ */ e(
      "ul",
      {
        className: v(
          null,
          "list-group list-group-flush border-top-0 mt-3 overflow-y-auto",
          s.events.length > 1 && "list-group-numbered"
        ),
        style: { maxHeight: 120 },
        children: s.events.map((a, r) => /* @__PURE__ */ i(
          "li",
          {
            className: "list-group-item d-flex justify-content-between align-items-start border-bottom-0",
            children: [
              /* @__PURE__ */ i("div", { className: "ms-2 me-auto", children: [
                /* @__PURE__ */ e("div", { className: "fw-bold", children: a.title }),
                a.description && /* @__PURE__ */ e("div", { children: a.description }),
                a.endTime && /* @__PURE__ */ e("div", { className: "small text-body-secondary mt-2", children: new Date(a.endTime).toLocaleTimeString() })
              ] }),
              a.allDay ? /* @__PURE__ */ e("span", { className: "small text-primary-emphasis text-center", children: "All Day" }) : /* @__PURE__ */ e(W, { children: a.startTime && /* @__PURE__ */ e("span", { className: "small text-body-secondary", children: new Date(a.startTime).toLocaleTimeString() }) })
            ]
          },
          `${a.id ?? r}-${s.date.toISOString()}`
        ))
      }
    ) }),
    f && f
  ] });
};
ee.displayName = "BRL.Calendar";
export {
  ee as C
};
//# sourceMappingURL=calendar.js.map
