import { defineComponent as $, ref as o, computed as D, onMounted as z, openBlock as d, createElementBlock as r, createElementVNode as i, withModifiers as w, toDisplayString as f, unref as m, Fragment as x, renderList as C, normalizeClass as I, normalizeStyle as U, withDirectives as A, vModelText as O, createCommentVNode as j } from "vue";
import { R as q, L as G } from "./index-89cd84f1.mjs";
import "pinia";
import "dayjs";
const J = {
  class: "cds-datepicker",
  ref: "drop"
}, K = { class: "cds-datepicker__header" }, P = ["onClick", "innerHTML"], Q = { class: "cds-datepicker__header-body" }, W = ["onClick", "innerHTML"], X = { class: "cds-datepicker__week-days" }, Z = { class: "cds-datepicker__days cds-datepicker__days--week" }, ee = { class: "cds-datepicker__day" }, te = { class: "cds-datepicker__days" }, ae = ["onClick"], ne = {
  key: 0,
  class: "cds-datepicker__time"
}, le = ["onClick"], re = /* @__PURE__ */ $({
  __name: "index",
  props: {
    date: { default: null },
    format: { default: null },
    range: { type: Boolean, default: !1 },
    showTime: { type: Boolean, default: !1 },
    maxStart: { default: null },
    maxEnd: { default: null }
  },
  emits: ["select", "close"],
  setup(g, { emit: M }) {
    const T = g, b = { Right: q, Left: G }, u = /* @__PURE__ */ new Date(), t = o(u.getMonth()), l = o(u.getFullYear()), S = "1";
    let L = ["Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"], F = [
      "Январь",
      "Февраль",
      "Март",
      "Апрель",
      "Май",
      "Июнь",
      "Июль",
      "Август",
      "Сентябрь",
      "Октябрь",
      "Ноябрь",
      "Декабрь"
    ];
    const H = D(() => {
      L = ["Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"];
    });
    u.getDate();
    const p = o("00:00"), s = o();
    o(null);
    const k = o(0), _ = o(0), h = o(0), y = D(() => {
      const e = { month: 0, year: 0, day: 0 };
      if (!s.value)
        return e;
      const n = new Date(s.value);
      return {
        month: n.getMonth(),
        year: n.getFullYear(),
        day: n.getDate()
      };
    }), B = D(() => {
      const e = [];
      let n = 0;
      e[n] = [];
      let v = new Date(l.value, t.value + 1, 0).getDate();
      for (let a = 1; a <= v; a++)
        if (Number(new Date(l.value, t.value, a).getDay()) !== Number(S)) {
          const c = { index: a };
          e[n].push(c), a === u.getDate() && l.value === u.getFullYear() && t.value === u.getMonth() && (c.current = !0), (new Date(l.value, t.value, a).getDay() === 6 || new Date(l.value, t.value, a).getDay() === 0) && (c.weekend = "var(--cds-color-danger)");
        } else {
          n++, e[n] = [];
          const c = { index: a };
          e[n].push(c), a === u.getDate() && l.value === u.getFullYear() && t.value === u.getMonth() && (c.current = !0), (new Date(l.value, t.value, a).getDay() === 6 || new Date(l.value, t.value, a).getDay() === 0) && (c.weekend = "var(--cds-color-danger)");
        }
      if (e[0].length > 0)
        for (let a = e[0].length; a < 7; a++)
          e[0].unshift("");
      return H.value, e;
    }), N = () => {
      t.value--, t.value < 0 && (t.value = 12, t.value--, l.value--);
    }, Y = () => {
      t.value++, t.value > 11 && (t.value = -1, t.value++, l.value++);
    }, E = () => {
      if (!p.value)
        return;
      const e = p.value.split(":");
      _.value = +e[0], h.value = +e[1];
    }, R = (e) => {
      if (!e)
        return;
      k.value = e;
      const n = new Date(l.value, t.value, k.value, 0, 0);
      s.value = n.toUTCString(), T.showTime || M("select", s.value);
    }, V = () => {
      const e = new Date(l.value, t.value, k.value, _.value, h.value);
      s.value = e.toISOString(), M("select", s.value);
    };
    return z(() => {
      s.value = new Date(T.date || ""), _.value = s.value.getHours(), h.value = s.value.getMinutes();
      const e = _.value > 9 ? _.value : "0" + _.value, n = h.value > 9 ? h.value : "0" + h.value;
      p.value = `${e}:${n}`;
    }), (e, n) => (d(), r("div", J, [
      i("div", K, [
        i("button", {
          class: "cds-datepicker__header-nav",
          onClick: w(N, ["prevent"]),
          innerHTML: b.Left
        }, null, 8, P),
        i("div", Q, f(m(F)[t.value]) + " " + f(l.value), 1),
        i("button", {
          class: "cds-datepicker__header-nav",
          onClick: w(Y, ["prevent"]),
          innerHTML: b.Right
        }, null, 8, W)
      ]),
      i("div", X, [
        i("div", Z, [
          (d(!0), r(x, null, C(m(L), (v) => (d(), r("div", ee, f(v), 1))), 256))
        ]),
        (d(!0), r(x, null, C(m(B), (v) => (d(), r("div", te, [
          (d(!0), r(x, null, C(v, (a, c) => (d(), r("div", {
            class: I(["cds-datepicker__day", {
              "cds-datepicker__day--selected": m(y).day === a.index && m(y).month === t.value && m(y).year === l.value,
              "cds-datepicker__day--current": a.current
            }]),
            onClick: (se) => R(a.index),
            style: U({ color: a.weekend })
          }, f(a.index), 15, ae))), 256))
        ]))), 256)),
        s.value && !g.range && g.showTime ? (d(), r("div", ne, [
          A(i("input", {
            type: "time",
            onInput: E,
            class: "cds-input",
            "onUpdate:modelValue": n[0] || (n[0] = (v) => p.value = v)
          }, null, 544), [
            [O, p.value]
          ]),
          i("button", {
            onClick: w(V, ["prevent"]),
            class: "cds-btn cds-btn--success cds-btn--fill"
          }, "Выбрать ", 8, le)
        ])) : j("", !0)
      ])
    ], 512));
  }
});
export {
  re as default
};
//# sourceMappingURL=index-359fc8c2.mjs.map
