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