import { jsx as i, jsxs as c, Fragment as f } from "react/jsx-runtime";
import { r as h, s as m, $ as y, t as d, u as g, v as n, w as k } from "./index-MLgFWWYi.js";
function w({
  className: s,
  dates: t,
  minDate: a,
  maxDate: u,
  onDatesChange: e,
  disabled: b,
  withoutPopover: p,
  "data-testid": v,
  strictlyBottom: o,
  allowPastDates: l = !1
}) {
  function $(r) {
    if (l)
      if (t != null && t.endDate)
        e({ startDate: r, endDate: void 0 });
      else {
        const x = t.startDate ? r < t.startDate ? r : t.startDate : r, L = t.startDate ? r < t.startDate ? t.startDate : r : void 0;
        e({ startDate: x, endDate: L });
      }
    else
      t.startDate ? t.endDate ? r.getTime() === t.startDate.getTime() || r.getTime() === t.endDate.getTime() ? e({ startDate: r, endDate: void 0 }) : r < t.startDate ? e({ startDate: r, endDate: void 0 }) : e({ startDate: t.startDate, endDate: r }) : r < t.startDate ? e({ startDate: r, endDate: t.startDate }) : e({ startDate: t.startDate, endDate: r }) : e({ startDate: r, endDate: void 0 });
  }
  const D = /* @__PURE__ */ i(
    h,
    {
      initialFocus: !0,
      fromDate: l && a === null ? void 0 : a ?? /* @__PURE__ */ new Date(),
      toDate: u,
      mode: "range",
      defaultMonth: t == null ? void 0 : t.startDate,
      selected: { from: t == null ? void 0 : t.startDate, to: t == null ? void 0 : t.endDate },
      onDayClick: (r) => $(r),
      numberOfMonths: 1,
      disabled: b,
      "data-testid": v
    }
  );
  return p ? D : /* @__PURE__ */ i("div", { className: m("grid gap-2", s), children: /* @__PURE__ */ c(y, { children: [
    /* @__PURE__ */ i(d, { asChild: !0, children: /* @__PURE__ */ i(
      g,
      {
        "data-testid": "date-range",
        color: "secondary",
        EndIcon: "calendar",
        className: m("justify-between text-left font-normal", !t && "text-subtle"),
        children: t != null && t.startDate ? t != null && t.endDate ? /* @__PURE__ */ c(f, { children: [
          n(t.startDate, "LLL dd, y"),
          " - ",
          n(t.endDate, "LLL dd, y")
        ] }) : /* @__PURE__ */ c(f, { children: [
          n(t.startDate, "LLL dd, y"),
          " - End"
        ] }) : /* @__PURE__ */ i("span", { children: "Pick a date" })
      }
    ) }),
    /* @__PURE__ */ i(
      k,
      {
        className: "bg-default text-emphasis z-50 w-auto rounded-md border p-0 outline-none",
        align: "start",
        sideOffset: 4,
        side: o ? "bottom" : void 0,
        avoidCollisions: !o,
        children: D
      }
    )
  ] }) });
}
export {
  w as DatePickerWithRange
};
