import '@das-fed/upf-ui/packages/components/special-range-picker-month/style.css';
import { withInstall as ae } from "@das-fed/upf-utils/with-install/index";
import { t as N, setI18nRule as te } from "@das-fed/upf-web/packages/i18n/index";
import { ref as m, computed as V, defineComponent as ne, onMounted as oe, openBlock as k, createElementBlock as y, normalizeStyle as L, unref as e, createElementVNode as f, normalizeClass as I, createVNode as B, withCtx as Y, toDisplayString as x, withDirectives as Z, Fragment as P, renderList as re, createTextVNode as le, createBlock as se, Teleport as ie, createCommentVNode as _ } from "vue";
import { ElPopover as ue, ClickOutside as de } from "element-plus";
import { vDasTooltip as ce } from "@das-fed/upf-ui/packages/components/text-tooltip/index";
import { DasIconDate as ve } from "@das-fed/upf-ui/packages/icons/date/index";
import { DasIconEmpty as pe } from "@das-fed/upf-ui/packages/icons/empty/index";
import { useModelValue as F } from "@das-fed/upf-utils/vue";
import "@das-fed/upf-ui/packages/global/theme";
const j = () => ({ getDateTime: (r) => {
  const l = `2020/03/${r}`;
  return new Date(l).getTime();
}, formatDateStr: (r) => {
  const l = Number(r);
  return l >= 10 ? l : "0" + l;
} }), ge = (t, i, n, r, l) => {
  const a = m({ begin: "", end: "" }), d = m(""), { getDateTime: s, formatDateStr: g } = j();
  return {
    popClickData: a,
    isInRange: (v) => {
      if (!a.value.begin || !a.value.end) return !1;
      const o = s(`${g(v)}`), p = s(a.value.begin), D = s(a.value.end);
      return o <= D && o >= p;
    },
    isInHoverRange: (v) => {
      if (!t.value[0] || !t.value[1]) return !1;
      const o = s(`${g(v)}`), p = s(`${t.value[0]}`), D = s(`${t.value[1]}`);
      return o <= D && o >= p;
    },
    isInNewRange: (v) => {
      if (!a.value.begin || !a.value.end || !d.value) return !1;
      const o = s(`${g(v)}`), p = s(d.value);
      let D = s(a.value.begin), C = s(a.value.end);
      return i.value === "begin" ? (p > D && (D = p), o <= C && o >= D) : (p < C && (C = p), o <= C && o >= D);
    },
    outBeginDate: (v) => {
      if (!a.value.begin) return !1;
      const o = s(`${g(v)}`), p = s(a.value.begin);
      return n.value === 1 && i.value === "end" && o < p;
    },
    outEndDate: (v) => {
      if (!a.value.end) return !1;
      const o = s(`${g(v)}`), p = s(a.value.end);
      return n.value === 1 && i.value === "begin" && o > p;
    },
    clickData: (v) => {
      n.value++;
      const o = `${g(v)}`;
      i.value === "begin" ? a.value.begin = o : a.value.end = o, n.value === 1 ? i.value = i.value === "begin" ? "end" : "begin" : l();
    },
    mouseEnter: (v) => {
      const o = `${g(v)}`;
      d.value = o, i.value === "begin" ? t.value[0] = o : t.value[1] = o;
    },
    mouseLeave: () => {
      d.value = "", i.value === "begin" ? t.value[0] = `${r.value[0]}` : t.value[1] = `${r.value[1]}`;
    }
  };
}, fe = (t) => {
  const i = m(), n = m(!1), r = m(0), l = m({
    x: 0,
    y: 0
  }), a = V(() => ({
    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: t.errorModelZIndex
  })), d = V(() => ({
    ...a.value,
    width: r.value + "px",
    position: "fixed",
    visibility: "visible",
    top: l.value.y + "px",
    left: l.value.x + "px"
  })), s = m({
    display: "block",
    textAlign: "left",
    color: "var(--upf-message-error-text, var(--upf-color-error))",
    whiteSpace: "break-spaces"
    // 'word-break': 'break-all',
  }), g = () => {
    var R, M, h;
    r.value = (R = i.value) == null ? void 0 : R.clientWidth;
    const { top: $ = 0, left: z = 0 } = ((M = i.value) == null ? void 0 : M.getBoundingClientRect()) ?? {}, E = (h = i.value) == null ? void 0 : h.clientHeight;
    l.value.x = z, l.value.y = $ + E;
  };
  return {
    $dasSpecialRangeMonthPicker: i,
    isHoverInInput: n,
    errorModalBaseSyle: a,
    errorModelStyle: d,
    errorLabelStyle: s,
    errorModalInputMouseEnter: () => {
      g(), n.value = !0;
    },
    errorModallInputMouseLeave: () => {
      n.value = !1;
    }
  };
}, me = { class: "date-container" }, be = { class: "month-container" }, De = { class: "month-container left-month-container" }, he = ["onMouseenter", "onClick"], ke = { class: "item-text" }, Me = {
  key: 0,
  class: "das-special-range-picker-error-label-content"
}, ye = "var(--das-ui-color-normal)", xe = "var(--das-ui-special-range-picker-close-btn)", we = /* @__PURE__ */ ne({
  __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", "change", "update:error", "show-popover"],
  setup(t, { emit: i }) {
    const n = t, r = i, l = m(!1), a = F(n, "modelValue"), d = m(["", ""]), s = F(n, "error"), g = m([]), b = m(void 0);
    let S = !0;
    const $ = m(0), z = V(() => !n.disabled && !n.isView && a.value[0] && a.value[1]), E = (w, c) => {
      n.disabled || n.isView || (S = !1, l.value = !0, b.value = c, $.value = 0, d.value = [a.value[0], a.value[1]], r("show-popover"));
    }, R = () => {
      b.value = void 0;
      const w = h.value;
      r("update:modelValue", [w.begin, w.end]), r("change", [w.begin, w.end]), r("update:error", !1), l.value = !1;
    }, { formatDateStr: M } = j(), {
      popClickData: h,
      isInRange: v,
      isInHoverRange: o,
      isInNewRange: p,
      outBeginDate: D,
      outEndDate: C,
      clickData: q,
      mouseEnter: G,
      mouseLeave: O
    } = ge(d, b, $, a, R), {
      $dasSpecialRangeMonthPicker: J,
      isHoverInInput: H,
      errorModalBaseSyle: K,
      errorModelStyle: Q,
      errorLabelStyle: T,
      errorModalInputMouseEnter: A,
      errorModallInputMouseLeave: W
    } = fe(n), U = () => {
      setTimeout(() => {
        if (!S) {
          S = !0;
          return;
        }
        d.value = ["", ""], h.value = { begin: a.value[0], end: a.value[1] }, b.value = void 0, l.value = !1;
      }, 50);
    }, X = () => {
      r("update:modelValue", [null, null]), r("update:error", !1), r("change", [null, null]);
    };
    return oe(() => {
      g.value = Array.from({ length: 31 }, (w, c) => c + 1), h.value = { begin: a.value[0], end: a.value[1] };
    }), (w, c) => (k(), y(
      "div",
      {
        ref_key: "$dasSpecialRangeMonthPicker",
        ref: J,
        style: L({ width: t.width, position: "relative" }),
        onMouseenter: c[3] || (c[3] = //@ts-ignore
        (...u) => e(A) && e(A)(...u)),
        onMouseleave: c[4] || (c[4] = //@ts-ignore
        (...u) => e(W) && e(W)(...u))
      },
      [
        f(
          "div",
          {
            class: I(["das-ui-special-range-picker-month-container", [
              t.borderType,
              n.disabled ? "disabled" : "",
              n.isView ? "readonly" : "",
              { active: b.value !== void 0 },
              e(s) ? "is-error" : "",
              t.size
            ]])
          },
          [
            B(e(ue), {
              visible: l.value,
              placement: "bottom-start",
              "popper-class": "das-special-range-picker-month-container",
              width: 280,
              trigger: "click"
            }, {
              reference: Y(() => [
                f("div", me, [
                  f(
                    "div",
                    {
                      class: I(["left-date", {
                        placeholder: !e(a)[0] || b.value === "begin" && d.value[0],
                        active: b.value === "begin"
                      }]),
                      onClick: c[0] || (c[0] = (u) => E(e(a)[0], "begin"))
                    },
                    x(d.value[0] || e(a)[0] || e(N)("das-special-range-picker-begin-date")) + x(d.value[0] || e(a)[0] ? e(N)("das-special-range-picker-date") : ""),
                    3
                    /* TEXT, CLASS */
                  ),
                  c[5] || (c[5] = f(
                    "div",
                    { class: "separator" },
                    "~",
                    -1
                    /* CACHED */
                  )),
                  f(
                    "div",
                    {
                      class: I(["right-date", {
                        placeholder: !e(a)[1] || b.value === "end" && d.value[1],
                        active: b.value === "end"
                      }]),
                      onClick: c[1] || (c[1] = (u) => E(e(a)[1], "end"))
                    },
                    x(d.value[1] || e(a)[1] || e(N)("das-special-range-picker-end-date")) + x(d.value[1] || e(a)[1] ? e(N)("das-special-range-picker-date") : ""),
                    3
                    /* TEXT, CLASS */
                  ),
                  f(
                    "div",
                    {
                      class: I({ "is-view": n.isView }),
                      style: { width: "16px" }
                    },
                    [
                      B(e(ve), {
                        class: I(["icon-date", { "has-data": z.value }]),
                        size: "medium",
                        "icon-color": ye
                      }, null, 8, ["class"]),
                      B(e(pe), {
                        class: I(["icon-delete", { "has-data": z.value }]),
                        size: "medium",
                        "icon-color": xe,
                        onClick: X
                      }, null, 8, ["class"])
                    ],
                    2
                    /* CLASS */
                  )
                ])
              ]),
              default: Y(() => [
                Z((k(), y("div", be, [
                  f("div", De, [
                    f(
                      "div",
                      {
                        class: "date-container-popover left-date-container",
                        onMouseleave: c[2] || (c[2] = //@ts-ignore
                        (...u) => e(O) && e(O)(...u))
                      },
                      [
                        (k(!0), y(
                          P,
                          null,
                          re(g.value, (u) => (k(), y("div", {
                            class: I(["item", {
                              "in-range": e(v)(u) || e(o)(u),
                              "new-range": e(p)(u),
                              "range-start": e(M)(e(h).begin) === e(M)(u),
                              "range-end": e(M)(e(h).end) === e(M)(u),
                              "out-range": e(D)(u) || e(C)(u)
                            }]),
                            onMouseenter: (ee) => e(G)(u),
                            onClick: (ee) => e(q)(u)
                          }, [
                            f(
                              "div",
                              ke,
                              x(u),
                              1
                              /* TEXT */
                            )
                          ], 42, he))),
                          256
                          /* UNKEYED_FRAGMENT */
                        ))
                      ],
                      32
                      /* NEED_HYDRATION */
                    )
                  ])
                ])), [
                  [e(de), U]
                ])
              ]),
              _: 1
              /* STABLE */
            }, 8, ["visible"])
          ],
          2
          /* CLASS */
        ),
        e(s) && t.errorLabel ? (k(), y(
          P,
          { key: 0 },
          [
            t.errorMode === "default" ? Z((k(), y("div", Me, [
              le(
                x(t.errorLabel),
                1
                /* TEXT */
              )
            ])), [
              [e(ce)]
            ]) : e(H) ? (k(), y(
              P,
              { key: 1 },
              [
                e(H) ? (k(), se(ie, {
                  key: 0,
                  to: "body"
                }, [
                  f(
                    "div",
                    {
                      style: L(e(Q))
                    },
                    [
                      f(
                        "span",
                        {
                          style: L(e(T))
                        },
                        x(t.errorLabel),
                        5
                        /* TEXT, STYLE */
                      )
                    ],
                    4
                    /* STYLE */
                  )
                ])) : (k(), y(
                  "div",
                  {
                    key: 1,
                    style: L(e(K)),
                    class: "das-special-range-picker-overlay-error-label-content"
                  },
                  [
                    f(
                      "span",
                      {
                        style: L(e(T))
                      },
                      x(t.errorLabel),
                      5
                      /* TEXT, STYLE */
                    )
                  ],
                  4
                  /* STYLE */
                ))
              ],
              64
              /* STABLE_FRAGMENT */
            )) : _("v-if", !0)
          ],
          64
          /* STABLE_FRAGMENT */
        )) : _("v-if", !0)
      ],
      36
      /* STYLE, NEED_HYDRATION */
    ));
  }
}), Ie = (t, i) => {
  const n = t.__vccOpts || t;
  for (const [r, l] of i)
    n[r] = l;
  return n;
}, Ce = /* @__PURE__ */ Ie(we, [["__scopeId", "data-v-2a5f3408"]]), Se = {
  "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" },
  "das-special-range-picker-date": { "zh-CN": "日", en: "Day", "zh-MO": "日", _appCode: "framework" }
}, He = ae(Ce);
te(Se);
export {
  He as DasSpecialRangePickerMonth,
  He as default
};
