import { defineComponent as Z, inject as ue, reactive as re, ref as G, openBlock as y, createElementBlock as x, createElementVNode as p, Fragment as U, renderList as X, createBlock as ge, withCtx as se, createTextVNode as oe, toDisplayString as j, createVNode as K, unref as z, onMounted as ce, nextTick as ie, normalizeClass as F, computed as ye, watch as we, provide as Me } from "vue";
import { C as l } from "../Shared/base-PQGakkrl.js";
import { _ as ne } from "../Shared/Index.vue_vue_type_script_setup_true_lang-inXYfqWx.js";
import { u as ae } from "../Shared/language-DxTlvFs2.js";
import { C as le } from "../Shared/index-BnerInzC.js";
import { D as xe } from "../Shared/drag-CzfhSB0g.js";
import "js-cookie";
import "decimal.js";
const Ie = { class: "weekhour-quick" }, _e = /* @__PURE__ */ Z({
  name: "ClWeekhourQuick",
  __name: "Quick",
  props: {
    isDisabled: {
      type: Boolean,
      default: !1
    },
    isOneDay: {
      type: Boolean,
      default: !1
    }
  },
  emits: ["onClick", "onHoverIn", "onHoverOut"],
  setup(I, { emit: A }) {
    const _ = I, k = A, { optPageLanguage: v, getPageLanguage: m } = ae();
    m("weekHour");
    const $ = ue("$WeekHourTop"), f = re({
      keyIndex: $.keyIndex
    }), W = G([]), c = (h) => {
      k("onClick", h);
    }, J = (h) => {
      k("onHoverIn", h);
    }, V = (h) => {
      k("onHoverOut", h);
    }, o = () => {
      let h = [
        { id: "dawn", name: v.value.dawn },
        { id: "morning", name: v.value.morning },
        { id: "noon", name: v.value.noon },
        { id: "afternoon", name: v.value.afternoon },
        { id: "evening", name: v.value.evening },
        { id: "night", name: v.value.night }
      ];
      _.isOneDay && (h = [
        { id: "weekday", name: v.value.weekday },
        { id: "weekend", name: v.value.weekend }
      ].concat(h)), W.value = h;
    };
    (() => {
      o();
    })();
    const N = (h) => {
      _.isDisabled || c(h.id);
    }, Q = (h) => {
      _.isDisabled || J(h.id);
    }, B = (h) => {
      _.isDisabled || V(h.id);
    }, S = () => {
      _.isDisabled || c("all");
    }, b = () => {
      _.isDisabled || c("clean");
    };
    return (h, T) => (y(), x("div", Ie, [
      p("div", null, [
        (y(!0), x(U, null, X(W.value, (C, P) => (y(), ge(ne, {
          key: `${f.keyIndex}-quick-${P}`,
          disabled: I.isDisabled,
          isLight: !0,
          isUnderline: !0,
          onOnClick: (i) => N(C),
          onOnHoverIn: (i) => Q(C),
          onOnHoverOut: (i) => B(C)
        }, {
          default: se(() => [
            oe(j(C.name), 1)
          ]),
          _: 2
        }, 1032, ["disabled", "onOnClick", "onOnHoverIn", "onOnHoverOut"]))), 128))
      ]),
      p("div", null, [
        K(ne, {
          disabled: I.isDisabled,
          isLight: !0,
          isUnderline: !0,
          onOnClick: S
        }, {
          default: se(() => [
            oe(j(z(v).common.checkboxAll), 1)
          ]),
          _: 1
        }, 8, ["disabled"]),
        K(ne, {
          disabled: I.isDisabled,
          isLight: !0,
          isUnderline: !0,
          onOnClick: b
        }, {
          default: se(() => [
            oe(j(z(v).common.clearEmpty), 1)
          ]),
          _: 1
        }, 8, ["disabled"])
      ])
    ]));
  }
}), Oe = { class: "weekhour-picker" }, be = {
  key: 0,
  class: "weekhour-interval"
}, Se = ["onMouseenter", "onClick", "data-hour"], Ce = ["onMouseenter", "onClick", "data-week"], Ee = {
  key: 0,
  class: "weekhour-interval"
}, He = ["onMouseenter", "onClick", "data-week", "data-hour"], De = /* @__PURE__ */ Z({
  name: "ClWeekhourPicker",
  __name: "Picker",
  props: {
    isDisabled: {
      type: Boolean,
      default: !1
    },
    isOneDay: {
      type: Boolean,
      default: !1
    }
  },
  emits: ["onChange"],
  setup(I, { expose: A, emit: _ }) {
    const k = I, v = _, { optPageLanguage: m, getPageLanguage: $ } = ae();
    $("weekHour");
    const f = ue("$WeekHourTop"), W = G(null), c = re({
      keyIndex: f.keyIndex,
      hoverHour: [],
      hoverWeek: [],
      hoverItem: [],
      hoverItemAssist: [],
      selectList: []
    }), J = G([]), V = G([
      "0",
      "1",
      "2",
      "3",
      "4",
      "5",
      "6",
      "7",
      "",
      "8",
      "9",
      "10",
      "11",
      "",
      "12",
      "13",
      "14",
      "",
      "15",
      "16",
      "17",
      "",
      "18",
      "19",
      "",
      "20",
      "21",
      "22",
      "23"
    ]), o = {
      week: [],
      hour: f.hour,
      prevValue: [],
      isMouseMoveStart: !1,
      isMouseMoveIng: !1,
      moveStart: {}
    };
    let L;
    const N = () => {
      L && (clearTimeout(L), L = null), L = setTimeout(() => {
        const { selectList: s } = c;
        l.isEqualArr(o.prevValue, s) || (o.prevValue = l.getArrClone(s), v("onChange", o.prevValue));
      }, 500);
    }, Q = () => {
      const s = k.isOneDay ? [{ id: "1", name: m.value.daily }] : [
        { id: "1", name: m.value.monday },
        { id: "2", name: m.value.tuesday },
        { id: "3", name: m.value.wednesday },
        { id: "4", name: m.value.thursday },
        { id: "5", name: m.value.friday },
        { id: "6", name: m.value.saturday },
        { id: "7", name: m.value.sunday }
      ], e = k.isOneDay ? s.map((t) => parseInt(t.id)) : f.week;
      o.week = e, J.value = s;
    }, B = (s) => {
      let e = [], t = [], r = [];
      return Object.keys(s).forEach((n) => {
        e.push(n.toString()), s[n].forEach((a) => {
          t.push(a.toString()), r.push(`${n}-${a}`);
        });
      }), e = l.getArrUnique(e), t = l.getArrUnique(t), r = l.getArrUnique(r), { week: e, hour: t, item: r };
    }, S = (s) => {
      const e = B(s);
      c.hoverWeek = e.week, c.hoverHour = e.hour, c.hoverItem = e.item;
    }, b = () => {
      c.hoverWeek = [], c.hoverHour = [], c.hoverItem = [], c.hoverItemAssist = [];
    }, h = (s) => {
      const e = B(s), t = [];
      e.week.forEach((r) => {
        o.hour.forEach((n) => {
          t.push(`${r}-${n}`);
        });
      }), e.hour.forEach((r) => {
        o.week.forEach((n) => {
          t.push(`${n}-${r}`);
        });
      }), c.hoverItemAssist = t;
    }, T = (s, e = !0) => {
      if (l.isEmpty(s))
        c.selectList = [];
      else {
        const { selectList: t } = c, n = B(s).item, a = [], d = [];
        n.forEach((M) => {
          l.isExistValue(t, M) ? d.push(M) : a.push(M);
        });
        const w = d.length === n.length && d.length > 0;
        c.selectList = w ? l.getArrRemoveById(t, n) : t.concat(a);
      }
      e && N();
    }, C = (s) => {
      const e = {
        isHour: !1,
        isWeek: !1,
        isItem: !1,
        isValidArea: !1,
        isValidMove: !1,
        isGroup: !1,
        hour: -1,
        week: -1,
        x: -1,
        width: -1
      };
      let t;
      s.target ? (t = s.target, e.x = s.pageX) : s.parentElement && (t = s);
      let r;
      if (W.value.contains(t)) {
        e.isValidArea = !0;
        const n = t.tagName.toLocaleLowerCase();
        r = n === "th" || n === "td" ? t : t.parentElement;
        const a = r.className.split(" ");
        if (e.isHour = a.indexOf("weekhour-hour") > -1, e.isWeek = a.indexOf("weekhour-week") > -1, e.isItem = a.indexOf("weekhour-item") > -1, e.isEmpty = a.indexOf("weekhour-empty") > -1, e.isInterval = a.indexOf("weekhour-interval") > -1, e.isInterval && (e.width = r.clientWidth), e.isHour && (e.type = "hour", e.isGroup = !0), e.isWeek && (e.type = "week", e.isGroup = !0), e.isItem && (e.type = "item", e.isGroup = !1), e.isHour || e.isWeek || e.isItem) {
          e.isValidMove = !0;
          const d = r.dataset;
          let w, M;
          e.isHour ? (w = parseInt(d.hour), M = -1) : e.isWeek ? (w = -1, M = parseInt(d.week)) : e.isItem && (w = parseInt(d.hour), M = parseInt(d.week)), e.hour = w, e.week = M;
        }
      }
      return e.el = r, e;
    }, P = (s) => {
      const e = C(s);
      if (e.isInterval) {
        const t = le.getPrev(e.el), r = le.getNext(e.el);
        e.prevInfo = C(t), e.nextInfo = C(r);
      }
      return e;
    }, i = (s, e) => {
      if (s.isEmpty && e.isEmpty) return null;
      s.isEmpty && (s.type = e.type), e.isEmpty && (e.type = s.type);
      const t = 23, r = o.week.length, n = { x: s.hour, y: s.week }, a = { x: e.hour, y: e.week };
      if (s.isGroup || e.isGroup) {
        if (s.type === "week")
          switch (e.type) {
            case "week":
              n.x = 0, a.x = t;
              break;
            case "item":
              n.x = 0;
              break;
            case "hour":
              n.x = 0, a.y = 1;
              break;
          }
        else if (s.type === "hour")
          switch (e.type) {
            case "hour":
              n.y = 1, a.y = r;
              break;
            case "item":
              n.y = 1;
              break;
            case "week":
              n.y = 1, a.x = 0;
              break;
          }
        else if (s.type === "item")
          switch (e.type) {
            case "hour":
              a.y = 1;
              break;
            case "week":
              a.x = 0;
              break;
          }
      }
      let d, w, M, R;
      a.x >= n.x ? (d = n.x, w = a.x) : (d = a.x, w = n.x), a.y >= n.y ? (M = n.y, R = a.y) : (M = a.y, R = n.y);
      let ee;
      (d > -1 || w > -1) && (d === -1 && (d = 0), ee = l.getArrByMinMax(d, w));
      let te;
      return (M > -1 || R > -1) && (M === -1 && (M = 1), te = l.getArrByMinMax(M, R)), !l.isUndefined(ee) && !l.isUndefined(te) ? { x: ee, y: te } : null;
    }, u = (s) => {
      let e = {}, t = {};
      const r = o.moveStart.isInterval, n = s.isInterval;
      if (r || n) {
        const a = o.moveStart.x, d = s.x;
        if (r && !n)
          t = s, a > d ? e = o.moveStart.prevInfo : d > a && (e = o.moveStart.nextInfo);
        else if (!r && n)
          e = o.moveStart, a > d ? t = s.nextInfo : d > a && (t = s.prevInfo);
        else if (r && n) {
          let w = 0;
          r ? w = o.moveStart.width : n && (w = s.width), Math.abs(a - d) > w && (a > d ? (e = o.moveStart.prevInfo, t = s.nextInfo) : d > a && (e = o.moveStart.nextInfo, t = s.prevInfo));
        }
      } else
        e = o.moveStart, t = s;
      return { startInfo: e, endInfo: t };
    }, g = (s) => {
      if (!o.isMouseMoveStart) {
        o.isMouseMoveStart = !0;
        const e = P(s);
        if (e.isValidArea && (b(), o.moveStart = e, e.isValidMove)) {
          const t = e.week === -1 ? o.week : [e.week], r = e.hour === -1 ? o.hour : [e.hour];
          S(f.getJsonConvertArr({ week: t, hour: r }));
        }
      }
    }, q = (s) => {
      if (o.isMouseMoveStart) {
        o.isMouseMoveIng = !0;
        const e = P(s);
        if (e.isValidArea) {
          b();
          const t = u(e);
          if (!l.isEmpty(t.startInfo) && !l.isEmpty(t.endInfo)) {
            const r = i(t.startInfo, t.endInfo);
            if (r) {
              const n = f.getJsonConvertArr({ week: r.y, hour: r.x });
              S(n);
            }
          }
        }
      }
    }, E = (s) => {
      if (o.isMouseMoveIng) {
        b();
        const e = P(s);
        if (e.isValidArea) {
          const t = u(e);
          if (!l.isEmpty(t.startInfo) && !l.isEmpty(t.endInfo)) {
            const r = i(t.startInfo, t.endInfo);
            if (r) {
              const n = f.getJsonConvertArr({ week: r.y, hour: r.x });
              T(n);
            }
          }
        }
      }
      o.isMouseMoveStart = !1, o.moveStart = {}, setTimeout(() => {
        o.isMouseMoveIng = !1;
      }, 50);
    }, O = () => {
      const s = {
        start(e) {
          let t = !1;
          return k.isDisabled || (t = !0, g(e)), t;
        },
        ing: (e) => {
          q(e);
        },
        end: (e) => {
          E(e);
        }
      };
      new xe(W.value, s);
    };
    (() => {
      Q();
    })(), ce(() => {
      ie(() => {
        O();
      });
    });
    const D = (s) => {
      if (!o.isMouseMoveStart && !k.isDisabled) {
        const e = f.getJsonConvertArr({ week: o.week, hour: [s] });
        S(e);
      }
    }, Y = () => {
      !o.isMouseMoveStart && !k.isDisabled && b();
    }, de = (s) => {
      if (!o.isMouseMoveStart && !o.isMouseMoveIng && !k.isDisabled) {
        const e = f.getJsonConvertArr({ week: o.week, hour: [s] });
        T(e);
      }
    }, ke = (s) => {
      if (!o.isMouseMoveStart && !k.isDisabled) {
        const e = {};
        e[s] = o.hour, S(e);
      }
    }, ve = () => {
      (!o.isMouseMoveStart || !k.isDisabled) && b();
    }, fe = (s) => {
      if (!o.isMouseMoveStart && !o.isMouseMoveIng && !k.isDisabled) {
        const e = {};
        e[s] = o.hour, T(e);
      }
    }, he = (s, e) => {
      if (!o.isMouseMoveStart && !k.isDisabled) {
        const t = {};
        t[s] = [e], S(t), h(t);
      }
    }, me = () => {
      !o.isMouseMoveStart && !k.isDisabled && b();
    }, pe = (s, e) => {
      if (!o.isMouseMoveStart && !o.isMouseMoveIng && !k.isDisabled) {
        const t = {};
        t[s] = [e], T(t);
      }
    };
    return A({
      getWeekArr: () => o.week,
      setSelected: (s, e = !1) => {
        o.isMouseMoveStart || T(s, e);
      },
      setHoverIn: (s) => {
        o.isMouseMoveStart || S(s);
      },
      setHoverOut: () => {
        o.isMouseMoveStart || b();
      }
    }), (s, e) => (y(), x("div", Oe, [
      p("table", {
        ref_key: "refElTable",
        ref: W
      }, [
        p("thead", null, [
          p("tr", null, [
            e[0] || (e[0] = p("th", { class: "weekhour-empty" }, null, -1)),
            (y(!0), x(U, null, X(V.value, (t, r) => (y(), x(U, {
              key: `${c.keyIndex}-hour-${r}`
            }, [
              t === "" ? (y(), x("th", be)) : (y(), x("th", {
                key: 1,
                class: F({ "weekhour-hour": !0, "weekhour-hour-hover": c.hoverHour.indexOf(t) > -1 }),
                onMouseenter: (n) => D(t),
                onMouseleave: Y,
                onClick: (n) => de(t),
                "data-hour": t
              }, j(t), 43, Se))
            ], 64))), 128))
          ])
        ]),
        p("tbody", null, [
          (y(!0), x(U, null, X(J.value, (t, r) => (y(), x("tr", {
            key: `${c.keyIndex}-week-${r}`
          }, [
            p("td", {
              class: F({ "weekhour-week": !0, "weekhour-week-hover": c.hoverWeek.indexOf(t.id) > -1 }),
              onMouseenter: (n) => ke(t.id),
              onMouseleave: ve,
              onClick: (n) => fe(t.id),
              "data-week": t.id
            }, j(t.name), 43, Ce),
            (y(!0), x(U, null, X(V.value, (n, a) => (y(), x(U, {
              key: `${c.keyIndex}-week-${r}-hour-${a}`
            }, [
              n === "" ? (y(), x("td", Ee)) : (y(), x("td", {
                key: 1,
                class: F({
                  "weekhour-item": !0,
                  "weekhour-item-hover": c.hoverItem.indexOf(`${t.id}-${n}`) > -1,
                  "weekhour-item-assist": c.hoverItemAssist.indexOf(`${t.id}-${n}`) > -1,
                  "weekhour-selected": c.selectList.indexOf(`${t.id}-${n}`) > -1
                }),
                onMouseenter: (d) => he(t.id, n),
                onMouseleave: me,
                onClick: (d) => pe(t.id, n),
                "data-week": t.id,
                "data-hour": n
              }, [...e[1] || (e[1] = [
                p("i", null, null, -1)
              ])], 42, He))
            ], 64))), 128))
          ]))), 128))
        ])
      ], 512)
    ]));
  }
}), Ae = { class: "weekhour-tips" }, $e = { class: "weekhour-tips-title" }, We = { class: "weekhour-tips-title" }, Ve = /* @__PURE__ */ Z({
  name: "ClWeekhourTip",
  __name: "Tips",
  setup(I) {
    const { optPageLanguage: A, getPageLanguage: _ } = ae();
    return _("weekHour"), (k, v) => (y(), x("div", Ae, [
      p("span", null, [
        v[0] || (v[0] = p("span", { class: "weekhour-item weekhour-selected" }, [
          p("i")
        ], -1)),
        p("span", $e, j(z(A).selected), 1)
      ]),
      p("span", null, [
        v[1] || (v[1] = p("span", { class: "weekhour-item" }, [
          p("i")
        ], -1)),
        p("span", We, j(z(A).selectedNot), 1)
      ])
    ]));
  }
}), Re = /* @__PURE__ */ Z({
  name: "ClWeekhour",
  __name: "Index",
  props: {
    value: String,
    className: String,
    disabled: {
      type: Boolean,
      default: !1
    },
    isOneDay: {
      type: Boolean,
      default: !1
    }
  },
  emits: ["update:value", "onChange", "onInit"],
  setup(I, { expose: A, emit: _ }) {
    const k = I, v = _, m = G(null), $ = re({
      keyIndex: `weekhour-${l.getRandom(8)}`,
      valueOut: ""
    }), f = {
      week: [1, 2, 3, 4, 5, 6, 7],
      hour: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
      quick: {
        weekday: {
          week: [1, 2, 3, 4, 5],
          hour: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
        },
        weekend: {
          week: [6, 7],
          hour: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
        },
        dawn: { week: [1, 2, 3, 4, 5, 6, 7], hour: [0, 1, 2, 3, 4, 5, 6, 7] },
        morning: { week: [1, 2, 3, 4, 5, 6, 7], hour: [8, 9, 10, 11] },
        noon: { week: [1, 2, 3, 4, 5, 6, 7], hour: [12, 13, 14] },
        afternoon: { week: [1, 2, 3, 4, 5, 6, 7], hour: [15, 16, 17] },
        evening: { week: [1, 2, 3, 4, 5, 6, 7], hour: [18, 19] },
        night: { week: [1, 2, 3, 4, 5, 6, 7], hour: [20, 21, 22, 23] },
        all: {
          week: [1, 2, 3, 4, 5, 6, 7],
          hour: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
        },
        clean: { week: [], hour: [] }
      }
    }, W = ye(() => {
      const i = {
        "panel-weekhour": !0,
        "weekhour-disabled": k.disabled
      }, { className: u } = k;
      return u && !l.isEmpty(u) && u.split(" ").forEach((g) => {
        l.isEmpty(g) || (i[g] = !0);
      }), i;
    }), c = (i) => {
      v("update:value", i), v("onChange", i);
    }, J = () => {
      ie(() => {
        v("onInit");
      });
    }, V = (i) => {
      let u = {};
      const g = Object.keys(i);
      if (!l.isEmpty(g))
        if (g.length === 2 && l.isExistValue(g, "week") && l.isExistValue(g, "hour")) {
          const q = L().join(",").split(",");
          i.week.forEach((E) => {
            l.isExistValue(q, E.toString()) && (u[E.toString()] = i.hour);
          });
        } else
          u = l.getJsonClone(i);
      return u;
    }, o = (i) => {
      const u = {};
      i && !l.isEmpty(i) && i.split(",").forEach((g, q) => {
        const E = parseInt(g).toString(2), O = [];
        l.getFillZero(E, 24).split("").reverse().forEach((H, D) => {
          parseInt(H) === 1 && O.push(D);
        }), u[(q + 1).toString()] = O;
      }), m.value && m.value.setSelected(u);
    }, L = () => {
      let i = f.week;
      return k.isOneDay && m.value && (i = m.value.getWeekArr()), i;
    }, N = (i) => {
      const u = {};
      i.forEach((O) => {
        const H = O.split("-"), D = H[0], Y = H[1];
        l.isExistJsonKey(u, D) || (u[D] = []), u[D].push(parseInt(Y));
      });
      const g = {};
      L().forEach((O) => {
        g[O.toString()] = f.hour.map(() => 0);
      });
      for (const [O, H] of Object.entries(u))
        l.getArrUnique(H).forEach((D) => {
          g[O][D] = 1;
        });
      const E = [];
      return Object.keys(g).forEach((O) => {
        const H = parseInt(l.getArrClone(g[O]).reverse().join(""), 2);
        E.push(H);
      }), E.join(",");
    }, Q = () => {
      o(k.value), J();
    };
    ce(() => {
      ie(() => {
        Q();
      });
    }), we(
      () => k.value,
      (i, u) => {
        i !== u && i !== $.valueOut && ($.valueOut = i || "", o(i));
      }
    );
    const B = (i) => {
      if (!k.disabled && l.isExistJsonKey(f.quick, i)) {
        const u = V(f.quick[i]);
        m.value.setSelected(u, !0);
      }
    }, S = (i) => {
      if (l.isExistJsonKey(f.quick, i)) {
        const u = V(f.quick[i]);
        m.value.setHoverIn(u);
      }
    }, b = (i) => {
      l.isExistJsonKey(f.quick, i) && m.value.setHoverOut();
    }, h = (i) => {
      const u = N(i);
      $.valueOut = u, c(u);
    };
    return Me("$WeekHourTop", {
      keyIndex: $.keyIndex,
      week: f.week,
      hour: f.hour,
      getJsonConvertArr: V
    }), A({
      getValue: () => {
      },
      getValueData: () => {
      },
      setValue: (i) => {
        o(i);
      }
    }), (i, u) => (y(), x("div", {
      class: F(W.value)
    }, [
      K(_e, {
        isDisabled: I.disabled,
        isOneDay: I.isOneDay,
        onOnClick: B,
        onOnHoverIn: S,
        onOnHoverOut: b
      }, null, 8, ["isDisabled", "isOneDay"]),
      K(De, {
        ref_key: "refElPicker",
        ref: m,
        isDisabled: I.disabled,
        isOneDay: I.isOneDay,
        onOnChange: h
      }, null, 8, ["isDisabled", "isOneDay"]),
      K(Ve)
    ], 2));
  }
});
export {
  Re as default
};
//# sourceMappingURL=ClWeekhour.js.map
