import { jsxs as d, jsx as a } from "react/jsx-runtime";
import { useState as o, useMemo as U, useCallback as O, useEffect as X } from "react";
import { t as N } from "../global.module.js";
import { B as Z, a as ee, c as te } from "../tools/icons.js";
import { g as R, c as ae, s as se, a as re, u as ne, l as oe, b } from "../tools/tools.js";
import { f as T, s as ce, a as le, b as ie } from "../lite.js";
const Y = /* @__PURE__ */ new Date(), de = [/* @__PURE__ */ new Date(), /* @__PURE__ */ new Date()], p = (D) => D.toString().padStart(2, "0"), pe = function(j) {
  const {
    as: E = "div",
    className: f,
    dropOldClass: M,
    locale: u,
    onDateClick: m,
    selectedDate: c,
    style: S,
    variables: k,
    ...F
  } = j, r = c && c.length > 0 ? c : de, [l, K] = o(Y.getFullYear()), [i, L] = o(Y.getMonth()), [_, w] = o(
    R(l, i, [], 6, 1, void 0, c, u)
  ), [h, H] = o(r.map((e) => p(e.getHours()))), [g, I] = o(r.map((e) => p(e.getMinutes()))), [v, P] = o(r.map((e) => p(e.getSeconds()))), [C, B] = o(null), A = U(() => {
    const e = ae(!M && "card card-body border-0 p-0", f), s = se((t, n) => ({ tKey: re(n) }), k, S);
    return {
      className: e,
      style: s
    };
  }, [f, M, S, k]), $ = O(
    (e) => {
      const s = new Date(l, i + e);
      K(s.getFullYear()), L(s.getMonth());
    },
    [i, l]
  ), V = O(
    (e) => {
      const t = ((y, x) => {
        const G = parseInt(h[x], 10) || 0, J = parseInt(g[x], 10) || 0, Q = parseInt(v[x], 10) || 0;
        return ce(le(ie(y, G), J), Q);
      })(e.date, C ? 1 : 0), n = { ...e, active: !0, date: t };
      w((y) => ne(n, y)), C ? (m == null || m({ date: oe(C, n.date) }), B(null)) : B(n.date);
    },
    [h, g, m, v, C]
  ), W = (e, s) => {
    const t = [...h];
    t[s] = e.target.value.trim(), H(t);
  }, q = (e, s) => {
    const t = [...g];
    t[s] = e.target.value.trim(), I(t);
  }, z = (e, s) => {
    const t = [...v];
    t[s] = e.target.value.trim(), P(t);
  };
  return X(() => {
    w(R(l, i, [], 6, 1, void 0, c, u)), H(r.map((e) => p(e.getHours()))), I(r.map((e) => p(e.getMinutes()))), P(r.map((e) => p(e.getSeconds())));
  }, [i, l, r, u, c]), /* @__PURE__ */ d(E, { ...F, ...A, children: [
    /* @__PURE__ */ d("div", { className: "list-group border-0 row-gap-1 px-3", children: [
      /* @__PURE__ */ d("div", { className: "row align-items-center position-relative text-center mb-2", children: [
        /* @__PURE__ */ a("div", { className: "col px-1", onClick: () => $(-1), children: /* @__PURE__ */ a(
          "div",
          {
            className: b(
              null,
              "user-select-none list-group-item list-group-item-action border-0 px-0 py-1 rounded text-secondary",
              N.brlCursorPointer
            ),
            children: /* @__PURE__ */ a(Z, {})
          }
        ) }),
        /* @__PURE__ */ a("div", { className: "col px-1" }),
        /* @__PURE__ */ a("div", { className: "col px-1" }),
        /* @__PURE__ */ a("div", { className: "col px-1" }),
        /* @__PURE__ */ a("div", { className: "col px-1" }),
        /* @__PURE__ */ a("div", { className: "col px-1" }),
        /* @__PURE__ */ a("div", { className: "col px-1", onClick: () => $(1), children: /* @__PURE__ */ a(
          "div",
          {
            className: b(
              null,
              "user-select-none list-group-item list-group-item-action border-0 px-0 py-1 rounded text-secondary",
              N.brlCursorPointer
            ),
            children: /* @__PURE__ */ a(ee, {})
          }
        ) }),
        /* @__PURE__ */ a("div", { className: "position-absolute top-50 start-50 translate-middle w-auto text-nowrap", children: T(new Date(l, i), "MMMM yyyy", {
          locale: u
        }) })
      ] }),
      _.rows.map((e, s) => /* @__PURE__ */ a("div", { className: "row text-center", children: e.map((t, n) => s === 0 ? /* @__PURE__ */ a("div", { className: "col px-1", children: /* @__PURE__ */ a("div", { className: "list-group-item border-0 px-0 py-1 rounded text-body-secondary", children: t.value }) }, `${t.value}${n}`) : /* @__PURE__ */ a("div", { className: "col px-1", onClick: () => V(t), children: /* @__PURE__ */ a(
        "div",
        {
          className: b(
            null,
            "list-group-item list-group-item-action px-0 py-1 rounded",
            N.brlCursorPointer,
            !t.isCurrentMonth && !t.active && "text-body-tertiary",
            t.active && "active",
            t.isToday ? "border-secondary-subtle" : "border-0"
          ),
          children: T(t.date, "d", { locale: u })
        }
      ) }, t.date.toISOString())) }, s))
    ] }),
    /* @__PURE__ */ a("div", { className: "d-flex flex-column gap-2 mt-4 mb-1", children: ["Start", "End"].map((e, s) => /* @__PURE__ */ d("div", { className: "input-group", children: [
      /* @__PURE__ */ d("span", { className: "input-group-text text-primary-emphasis", children: [
        /* @__PURE__ */ a(te, {}),
        /* @__PURE__ */ d("span", { className: "ps-1", children: [
          e,
          "Time"
        ] })
      ] }),
      /* @__PURE__ */ a(
        "input",
        {
          className: "form-control",
          onChange: (t) => W(t, s),
          placeholder: "HH",
          type: "text",
          value: h[s]
        }
      ),
      /* @__PURE__ */ a("span", { className: "input-group-text text-secondary", children: ":" }),
      /* @__PURE__ */ a(
        "input",
        {
          className: "form-control",
          onChange: (t) => q(t, s),
          placeholder: "MM",
          type: "text",
          value: g[s]
        }
      ),
      /* @__PURE__ */ a("span", { className: "input-group-text text-secondary", children: ":" }),
      /* @__PURE__ */ a(
        "input",
        {
          className: "form-control",
          onChange: (t) => z(t, s),
          placeholder: "SS",
          type: "text",
          value: v[s]
        }
      )
    ] }, s)) })
  ] });
};
pe.displayName = "BRL.DateRangePickerDatetime";
export {
  pe as D
};
//# sourceMappingURL=date-range-picker-datetime.js.map
