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