import { jsx as e, jsxs as d } from "react/jsx-runtime";
/* empty css              */
import { shift as Y, offset as q } from "@floating-ui/dom";
import { format as G, getYear as J } from "date-fns";
import { forwardRef as O, useState as Q } from "react";
import D from "react-datepicker";
import { createPortal as U } from "react-dom";
import X from "../../foundation/Icon/Generated/IconCaretLeft.es.js";
import Z from "../../foundation/Icon/Generated/IconCaretLeftDouble.es.js";
import _ from "../../foundation/Icon/Generated/IconCaretRight.es.js";
import $ from "../../foundation/Icon/Generated/IconCaretRightDouble.es.js";
import { IconSize as a } from "../../foundation/Icon/IconSize.es.js";
import { merge as ee } from "../../utilities/merge.es.js";
import { Validation as te } from "../../utilities/validation.es.js";
import { DatePickerTrigger as re } from "./DatePickerTrigger.es.js";
import { Button as i } from "../Button/Button.es.js";
import { ButtonEmphasis as o, ButtonSize as s, ButtonStyle as n } from "../Button/ButtonTypes.es.js";
const ae = D.default ?? D, ie = (m, r) => m === "single" ? r < /* @__PURE__ */ new Date() ? "past-date" : "future-date" : "range-day", oe = O(
  ({
    placeHolder: m = "Select a date",
    isClearable: r,
    shouldCloseOnSelect: k,
    onChange: p,
    onOpen: l,
    onClose: c,
    onBlur: g,
    onKeyDown: h,
    dateFormat: C = "MMM dd, yyyy",
    value: z,
    startDate: M,
    endDate: S,
    minDate: x,
    maxDate: P,
    validation: I = te.Default,
    customTrigger: N,
    customHeader: R,
    children: b,
    fixedHeight: W = !0,
    hasPopperArrow: v = !0,
    preventOpenOnFocus: B = !1,
    inline: f = !1,
    filterDate: j = () => !0,
    variant: u = "single",
    "data-test-id": L = "date-picker"
  }, A) => {
    const [w, y] = Q(!1), E = () => {
      y(!0), l == null || l();
    }, F = () => {
      y(!1), c == null || c();
    };
    return /* @__PURE__ */ e("div", { "data-test-id": L, children: /* @__PURE__ */ e(
      ae,
      {
        calendarClassName: ee([
          "react-datepicker-wrap tw-pointer-events-auto",
          f && "react-datepicker-inline"
        ]),
        inline: f,
        selected: z,
        startDate: M,
        endDate: S,
        minDate: x,
        maxDate: P,
        calendarStartDay: 1,
        onChange: p,
        onKeyDown: w ? void 0 : h,
        onBlur: g,
        selectsRange: u === "range",
        showPopperArrow: v,
        preventOpenOnFocus: B,
        filterDate: j,
        fixedHeight: W,
        customInput: N ?? /* @__PURE__ */ e(
          re,
          {
            isCalendarOpen: w,
            isClearable: r,
            placeHolder: m,
            validation: I,
            onDateChanged: p
          }
        ),
        ref: A,
        formatWeekDay: (t) => t.slice(0, 1),
        isClearable: r,
        dateFormat: C,
        onCalendarClose: F,
        onCalendarOpen: E,
        shouldCloseOnSelect: k,
        dayClassName: (t) => ie(u, t),
        popperProps: {
          strategy: "fixed"
        },
        popperContainer: ({ children: t }) => U(t, document.body),
        popperModifiers: [Y({ padding: 8 }), q(8)],
        renderCustomHeader: ({ date: t, decreaseMonth: H, increaseMonth: K, increaseYear: T, decreaseYear: V }) => /* @__PURE__ */ d("div", { className: "tw-flex tw-flex-col tw-gap-3", children: [
          R,
          /* @__PURE__ */ d("div", { className: "tw-flex tw-justify-between tw-pb-4 tw-px-0", children: [
            /* @__PURE__ */ e(
              i,
              {
                style: n.Default,
                size: s.Medium,
                onClick: V,
                emphasis: o.Weak,
                icon: /* @__PURE__ */ e(Z, { size: a.Size20 })
              }
            ),
            /* @__PURE__ */ e(
              i,
              {
                style: n.Default,
                size: s.Medium,
                onClick: H,
                emphasis: o.Weak,
                icon: /* @__PURE__ */ e(X, { size: a.Size20 })
              }
            ),
            /* @__PURE__ */ d("p", { className: "tw-font-sans tw-font-semibold tw-grow tw-self-center", children: [
              G(t, "MMMM"),
              " ",
              J(t)
            ] }),
            /* @__PURE__ */ e(
              i,
              {
                style: n.Default,
                size: s.Medium,
                onClick: K,
                emphasis: o.Weak,
                icon: /* @__PURE__ */ e(_, { size: a.Size20 })
              }
            ),
            /* @__PURE__ */ e(
              i,
              {
                style: n.Default,
                size: s.Medium,
                onClick: T,
                emphasis: o.Weak,
                icon: /* @__PURE__ */ e($, { size: a.Size20 })
              }
            )
          ] })
        ] }),
        children: b
      }
    ) });
  }
);
oe.displayName = "FondueDatePicker";
export {
  oe as DatePicker
};
//# sourceMappingURL=DatePicker.es.js.map
