import '@das-fed/upf-ui/packages/components/special-range-picker-year/style.css';
import { withInstall as ge } from "@das-fed/upf-utils/with-install/index";
import { i18n as Y, setI18nRule as fe } from "@das-fed/upf-web/packages/i18n/index";
import { ref as k, computed as A, defineComponent as me, onMounted as be, openBlock as I, createElementBlock as S, normalizeStyle as N, unref as e, createElementVNode as v, normalizeClass as R, createVNode as _, withCtx as Q, toDisplayString as $, withDirectives as U, createTextVNode as T, Fragment as H, renderList as X, createBlock as he, Teleport as De, createCommentVNode as ee } from "vue";
import { ElPopover as ke, ClickOutside as Me } from "element-plus";
import "element-plus/es/components/popover/style/css";
import { vDasTooltip as ye } from "@das-fed/upf-ui/packages/components/text-tooltip/index";
import { DasIconEmpty as xe } from "@das-fed/upf-ui/packages/icons/empty/index";
import { DasIconDate as Ie } from "@das-fed/upf-ui/packages/icons/date/index";
import { DasIconLeft as $e } from "@das-fed/upf-ui/packages/icons/left/index";
import { DasIconEntry as we } from "@das-fed/upf-ui/packages/icons/entry/index";
import { useModelValue as ae } from "@das-fed/upf-utils/vue";
import "@das-fed/upf-ui/packages/global/theme";
const ne = () => ({ getDateTime: (n) => {
  const p = `2020/${n}`;
  return new Date(p).getTime();
}, formatDateStr: (n) => n >= 10 ? n : "0" + n }), Ce = (o, g, t, n, p, s, y) => {
  const u = k({ begin: "", end: "" }), w = k(""), { getDateTime: f, formatDateStr: c } = ne();
  return {
    popClickData: u,
    isInRange: (l, i) => {
      if (!u.value.begin || !u.value.end) return !1;
      const h = {
        left: o.value,
        right: g.value
      }, r = f(`${c(h[i])}/${c(l)}`), D = f(u.value.begin), x = f(u.value.end);
      return r <= x && r >= D;
    },
    isInHoverRange: (l, i) => {
      if (!t.value[0] || !t.value[1]) return !1;
      const h = {
        left: o.value,
        right: g.value
      }, r = f(`${c(h[i])}/${c(l)}`), D = f(t.value[0]), x = f(t.value[1]);
      return r <= x && r >= D;
    },
    isInNewRange: (l, i) => {
      if (!u.value.begin || !u.value.end || !w.value) return !1;
      const h = {
        left: o.value,
        right: g.value
      }, r = f(`${c(h[i])}/${c(l)}`), D = f(w.value);
      let x = f(u.value.begin), z = f(u.value.end);
      return n.value === "begin" ? (D > x && (x = D), r <= z && r >= x) : (D < z && (z = D), r <= z && r >= x);
    },
    outBeginDate: (l, i) => {
      if (!u.value.begin) return !1;
      const h = {
        left: o.value,
        right: g.value
      }, r = f(`${c(h[i])}/${c(l)}`), D = f(u.value.begin);
      return p.value === 1 && n.value === "end" && r < D;
    },
    outEndDate: (l, i) => {
      if (!u.value.end) return !1;
      const h = {
        left: o.value,
        right: g.value
      }, r = f(`${c(h[i])}/${c(l)}`), D = f(u.value.end);
      return p.value === 1 && n.value === "begin" && r > D;
    },
    clickData: (l, i) => {
      p.value++;
      const h = {
        left: o.value,
        right: g.value
      }, r = `${c(h[i])}/${c(l)}`;
      n.value === "begin" ? u.value.begin = r : u.value.end = r, p.value === 1 ? n.value = n.value === "begin" ? "end" : "begin" : y();
    },
    mouseEnter: (l, i) => {
      const h = {
        left: o.value,
        right: g.value
      }, r = `${c(h[i])}/${c(l)}`;
      w.value = r, n.value === "begin" ? t.value[0] = r : t.value[1] = r;
    },
    mouseLeave: () => {
      w.value = "", n.value === "begin" ? t.value[0] = s.value[0] : t.value[1] = s.value[1];
    }
  };
}, Se = (o) => {
  const g = k(), t = k(!1), n = k(0), p = k({
    x: 0,
    y: 0
  }), s = A(() => ({
    fontSize: "12px",
    // 错误浮层直接消费新主题根变量，保持悬浮提示与表单错误态一致。
    backgroundColor: "var(--upf-message-error-bg, var(--upf-bg-primary))",
    boxShadow: "var(--upf-box-shadow-elevated, 0px 4px 12px rgba(38, 38, 38, 0.12))",
    borderRadius: "var(--upf-border-radius, 4px)",
    padding: "2px 8px",
    boxSizing: "border-box",
    zIndex: o.errorModelZIndex
  })), y = A(() => ({
    ...s.value,
    width: n.value + "px",
    position: "fixed",
    visibility: "visible",
    top: p.value.y + "px",
    left: p.value.x + "px"
  })), u = k({
    display: "block",
    textAlign: "left",
    color: "var(--upf-message-error-text, var(--upf-color-error))",
    whiteSpace: "break-spaces"
    // 'word-break': 'break-all',
  }), w = () => {
    var E, P, B;
    n.value = (E = g.value) == null ? void 0 : E.clientWidth;
    const { top: m = 0, left: b = 0 } = ((P = g.value) == null ? void 0 : P.getBoundingClientRect()) ?? {}, M = (B = g.value) == null ? void 0 : B.clientHeight;
    p.value.x = b, p.value.y = m + M;
  };
  return {
    $dasSpecialRangeYearPicker: g,
    isHoverInInput: t,
    errorModalBaseSyle: s,
    errorModelStyle: y,
    errorLabelStyle: u,
    errorModalInputMouseEnter: () => {
      w(), t.value = !0;
    },
    errorModallInputMouseLeave: () => {
      t.value = !1;
    }
  };
}, Re = { class: "date-container" }, Ee = { class: "year-container" }, ze = { class: "month-container left-month-container" }, Le = { class: "header" }, Pe = ["onMouseenter", "onClick"], Be = { class: "item-text" }, Ne = { class: "month-container right-month-container" }, _e = { class: "header" }, Ve = ["onMouseenter", "onClick"], Ye = { class: "item-text" }, He = {
  key: 0,
  class: "das-special-range-picker-error-label-content"
}, Oe = "var(--das-ui-color-normal)", Te = "var(--das-ui-special-range-picker-close-btn)", te = "var(--das-ui-color-help)", Ae = /* @__PURE__ */ me({
  __name: "Index",
  props: {
    modelValue: {},
    borderType: { default: "underline" },
    width: { default: "230px" },
    disabled: { type: Boolean, default: !1 },
    isView: { type: Boolean, default: !1 },
    error: { type: Boolean, default: !1 },
    errorLabel: {},
    placeholder: {},
    size: { default: "large" },
    errorMode: { default: "default" },
    errorModelZIndex: { default: 2e3 }
  },
  emits: ["update:modelValue", "update:error", "change", "show-popover"],
  setup(o, { emit: g }) {
    const t = o, n = g, p = k(!1), s = ae(t, "modelValue"), y = k(["", ""]), u = ae(t, "error"), w = k(0), f = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], c = k({}), m = k(1), b = k(2), M = k(void 0);
    let E = !0;
    const P = k(0), B = A(() => !t.disabled && !t.isView && s.value[0] && s.value[1]), O = (C, d) => {
      if (!(t.disabled || t.isView)) {
        if (E = !1, p.value = !0, M.value = d, P.value = 0, y.value = [s.value[0], s.value[1]], C) {
          const a = Number(C.split("/")[0]);
          d === "begin" ? (m.value = a < 12 ? a : 11, b.value = m.value + 1) : (b.value = a > 1 ? a : 2, m.value = b.value - 1);
        } else
          m.value = w.value < 12 ? w.value : 11, b.value = m.value + 1;
        n("show-popover");
      }
    }, W = () => {
      M.value = void 0;
      const C = i.value;
      n("update:modelValue", [C.begin, C.end]), n("change", [C.begin, C.end]), n("update:error", !1), p.value = !1;
    }, { formatDateStr: l } = ne(), {
      popClickData: i,
      isInRange: h,
      isInHoverRange: r,
      isInNewRange: D,
      outBeginDate: x,
      outEndDate: z,
      clickData: Z,
      mouseEnter: F,
      mouseLeave: V
    } = Ce(m, b, y, M, P, s, W), {
      $dasSpecialRangeYearPicker: re,
      isHoverInInput: j,
      errorModalBaseSyle: oe,
      errorModelStyle: le,
      errorLabelStyle: q,
      errorModalInputMouseEnter: G,
      errorModallInputMouseLeave: J
    } = Se(t), se = re, ie = () => {
      m.value !== 1 && (m.value--, b.value--);
    }, ue = () => {
      b.value !== 12 && (b.value++, m.value++);
    }, ce = () => {
      setTimeout(() => {
        if (!E) {
          E = !0;
          return;
        }
        y.value = ["", ""], i.value = { begin: s.value[0], end: s.value[1] }, M.value = void 0, p.value = !1;
      }, 50);
    }, de = () => {
      n("update:modelValue", [null, null]), n("update:error", !1), n("change", [null, null]);
    }, ve = (C) => {
      const d = (L) => Array.from({ length: L }, (K, pe) => pe + 1), a = /* @__PURE__ */ new Date();
      w.value = a.getMonth() + 1, f.forEach((L, K) => {
        C[K + 1] = d(L);
      }), i.value = { begin: s.value[0], end: s.value[1] };
    };
    return be(() => {
      ve(c.value);
    }), (C, d) => (I(), S(
      "div",
      {
        ref_key: "specialRangeYearPickerRef",
        ref: se,
        style: N({ width: o.width, position: "relative" }),
        onMouseenter: d[4] || (d[4] = //@ts-ignore
        (...a) => e(G) && e(G)(...a)),
        onMouseleave: d[5] || (d[5] = //@ts-ignore
        (...a) => e(J) && e(J)(...a))
      },
      [
        v(
          "div",
          {
            class: R(["das-ui-special-range-picker-year-container", [
              o.borderType,
              t.disabled ? "disabled" : "",
              t.isView ? "readonly" : "",
              { active: M.value !== void 0 },
              e(u) ? "is-error" : "",
              o.size
            ]])
          },
          [
            _(e(ke), {
              visible: p.value,
              placement: "bottom-start",
              "popper-class": "das-special-range-picker-year-container",
              width: 481,
              trigger: "click"
            }, {
              reference: Q(() => [
                v("div", Re, [
                  v(
                    "div",
                    {
                      class: R(["left-date", {
                        placeholder: !e(s)[0] || M.value === "begin" && y.value[0],
                        active: M.value === "begin"
                      }]),
                      onClick: d[0] || (d[0] = (a) => O(e(s)[0], "begin"))
                    },
                    $(y.value[0] || e(s)[0] || e(Y)("das-special-range-picker-begin-date").value),
                    3
                    /* TEXT, CLASS */
                  ),
                  d[6] || (d[6] = v(
                    "div",
                    { class: "separator" },
                    "~",
                    -1
                    /* CACHED */
                  )),
                  v(
                    "div",
                    {
                      class: R(["right-date", {
                        placeholder: !e(s)[1] || M.value === "end" && y.value[1],
                        active: M.value === "end"
                      }]),
                      onClick: d[1] || (d[1] = (a) => O(e(s)[1], "end"))
                    },
                    $(y.value[1] || e(s)[1] || e(Y)("das-special-range-picker-end-date").value),
                    3
                    /* TEXT, CLASS */
                  ),
                  v(
                    "div",
                    {
                      class: R({ "is-view": t.isView }),
                      style: { width: "16px" }
                    },
                    [
                      _(e(Ie), {
                        class: R(["icon-date", { "has-data": B.value }]),
                        size: "medium",
                        "icon-color": Oe
                      }, null, 8, ["class"]),
                      _(e(xe), {
                        class: R(["icon-delete", { "has-data": B.value }]),
                        size: "medium",
                        "icon-color": Te,
                        onClick: de
                      }, null, 8, ["class"])
                    ],
                    2
                    /* CLASS */
                  )
                ])
              ]),
              default: Q(() => [
                U((I(), S("div", Ee, [
                  v("div", ze, [
                    v("div", Le, [
                      v(
                        "div",
                        {
                          class: R(["turn-btn turn-left", { disabled: m.value === 1 }])
                        },
                        [
                          _(e($e), {
                            class: "turn-icon",
                            size: "medium",
                            "icon-color": te,
                            onClick: ie
                          })
                        ],
                        2
                        /* CLASS */
                      ),
                      T(
                        " " + $(m.value) + $(e(Y)("das-special-range-picker-month").value),
                        1
                        /* TEXT */
                      )
                    ]),
                    v(
                      "div",
                      {
                        class: "date-container-popover left-date-container",
                        onMouseleave: d[2] || (d[2] = //@ts-ignore
                        (...a) => e(V) && e(V)(...a))
                      },
                      [
                        (I(!0), S(
                          H,
                          null,
                          X(c.value[m.value], (a) => (I(), S("div", {
                            class: R(["item", {
                              "in-range": e(h)(a, "left") || e(r)(a, "left"),
                              "new-range": e(D)(a, "left"),
                              "range-start": e(i).begin === `${e(l)(m.value)}/${e(l)(a)}`,
                              "range-end": e(i).end === `${e(l)(m.value)}/${e(l)(a)}`,
                              "out-range": e(x)(a, "left") || e(z)(a, "left")
                            }]),
                            onMouseenter: (L) => e(F)(a, "left"),
                            onClick: (L) => e(Z)(a, "left")
                          }, [
                            v(
                              "div",
                              Be,
                              $(a),
                              1
                              /* TEXT */
                            )
                          ], 42, Pe))),
                          256
                          /* UNKEYED_FRAGMENT */
                        ))
                      ],
                      32
                      /* NEED_HYDRATION */
                    )
                  ]),
                  v("div", Ne, [
                    v("div", _e, [
                      v(
                        "div",
                        {
                          class: R(["turn-btn turn-right", { disabled: b.value === 12 }])
                        },
                        [
                          _(e(we), {
                            class: "turn-icon",
                            size: "medium",
                            "icon-color": te,
                            onClick: ue
                          })
                        ],
                        2
                        /* CLASS */
                      ),
                      T(
                        " " + $(b.value) + $(e(Y)("das-special-range-picker-month").value),
                        1
                        /* TEXT */
                      )
                    ]),
                    v(
                      "div",
                      {
                        class: "date-container-popover right-date-container",
                        onMouseleave: d[3] || (d[3] = //@ts-ignore
                        (...a) => e(V) && e(V)(...a))
                      },
                      [
                        (I(!0), S(
                          H,
                          null,
                          X(c.value[b.value], (a) => (I(), S("div", {
                            class: R(["item", {
                              "in-range": e(h)(a, "right") || e(r)(a, "right"),
                              "new-range": e(D)(a, "right"),
                              "range-start": e(i).begin === `${e(l)(b.value)}/${e(l)(a)}`,
                              "range-end": e(i).end === `${e(l)(b.value)}/${e(l)(a)}`,
                              "out-range": e(x)(a, "right") || e(z)(a, "right")
                            }]),
                            onMouseenter: (L) => e(F)(a, "right"),
                            onClick: (L) => e(Z)(a, "right")
                          }, [
                            v(
                              "div",
                              Ye,
                              $(a),
                              1
                              /* TEXT */
                            )
                          ], 42, Ve))),
                          256
                          /* UNKEYED_FRAGMENT */
                        ))
                      ],
                      32
                      /* NEED_HYDRATION */
                    )
                  ])
                ])), [
                  [e(Me), ce]
                ])
              ]),
              _: 1
              /* STABLE */
            }, 8, ["visible"])
          ],
          2
          /* CLASS */
        ),
        e(u) && o.errorLabel ? (I(), S(
          H,
          { key: 0 },
          [
            o.errorMode === "default" ? U((I(), S("div", He, [
              T(
                $(o.errorLabel),
                1
                /* TEXT */
              )
            ])), [
              [e(ye)]
            ]) : e(j) ? (I(), S(
              H,
              { key: 1 },
              [
                e(j) ? (I(), he(De, {
                  key: 0,
                  to: "body"
                }, [
                  v(
                    "div",
                    {
                      style: N(e(le))
                    },
                    [
                      v(
                        "span",
                        {
                          style: N(e(q))
                        },
                        $(o.errorLabel),
                        5
                        /* TEXT, STYLE */
                      )
                    ],
                    4
                    /* STYLE */
                  )
                ])) : (I(), S(
                  "div",
                  {
                    key: 1,
                    style: N(e(oe)),
                    class: "das-special-range-picker-overlay-error-label-content"
                  },
                  [
                    v(
                      "span",
                      {
                        style: N(e(q))
                      },
                      $(o.errorLabel),
                      5
                      /* TEXT, STYLE */
                    )
                  ],
                  4
                  /* STYLE */
                ))
              ],
              64
              /* STABLE_FRAGMENT */
            )) : ee("v-if", !0)
          ],
          64
          /* STABLE_FRAGMENT */
        )) : ee("v-if", !0)
      ],
      36
      /* STYLE, NEED_HYDRATION */
    ));
  }
}), We = (o, g) => {
  const t = o.__vccOpts || o;
  for (const [n, p] of g)
    t[n] = p;
  return t;
}, Ze = /* @__PURE__ */ We(Ae, [["__scopeId", "data-v-97102556"]]), Fe = {
  "das-special-range-picker-begin-date": { "zh-CN": "开始日期", en: "Start Date", "zh-MO": "開始日期", _appCode: "framework" },
  "das-special-range-picker-end-date": { "zh-CN": "结束日期", en: "End Date", "zh-MO": "結束日期", _appCode: "framework" },
  "das-special-range-picker-month": { "zh-CN": "月", en: "Month", "zh-MO": "月", _appCode: "framework" }
}, ra = ge(Ze);
fe(Fe);
export {
  ra as DasSpecialRangePickerYear,
  ra as default
};
