import { resolveComponent as h, openBlock as p, createElementBlock as c, createVNode as k, defineComponent as f, computed as D, createBlock as m, unref as w, isRef as C, normalizeClass as V, normalizeProps as g, mergeProps as I } from "vue";
import { D as S, c as y, a as s, d as l, s as P, _ as M } from "./constants-bafaca2a.js";
import { at as E, a7 as u, a6 as Z, as as T, a9 as _ } from "./index-1e3e8095.js";
import { isString as v } from "lodash-es";
import "@vueuse/core";
import "axios";
import "vue-i18n";
const z = `.kapix-calendar{width:100%;height:100%;min-width:0;min-height:0}
`, O = `.kapix-calendar-container{width:100%;height:100%;min-width:0;min-height:0;display:flex;align-items:center;justify-content:center}.kapix-calendar-container .vdatetime-popup{max-width:350px}
`;
u("KapixCalendar", O);
const b = {
  components: {
    DatetimePopup: S
  },
  // inheritAttrs: false,
  props: y,
  emits: ["update:modelValue"],
  data() {
    return {
      datetime: null
    };
  },
  computed: {
    inputValue({ datetime: e, format: a, type: r, zone: n }) {
      if (!a)
        switch (r) {
          case "date":
            a = s.DATE_MED;
            break;
          case "time":
            a = s.TIME_24_SIMPLE;
            break;
          case "datetime":
          case "default":
            a = s.DATETIME_MED;
            break;
        }
      return v(a) ? e ? s.fromISO(e).setZone(n).toFormat(a) : "" : e ? e.setZone(n).toLocaleString(a) : "";
    },
    popupDate({ datetime: e }) {
      return e ? e.setZone(this.zone) : null;
    },
    popupMinDatetime({ minDatetime: e }) {
      return e ? s.fromISO(e).setZone(this.zone) : null;
    },
    popupMaxDatetime({ maxDatetime: e }) {
      return e ? s.fromISO(e).setZone(this.zone) : null;
    }
  },
  watch: {
    modelValue: {
      immediate: !0,
      handler(e) {
        this.datetime = l(e, this.zone);
      }
    }
  },
  methods: {
    emitInput() {
      let e = this.datetime ? this.datetime.setZone(this.valueZone) : null;
      e && this.type === "date" && (e = P(e)), this.$emit("update:modelValue", e ? e.toJSDate() : null);
    },
    confirm(e) {
      this.datetime = e.toUTC(), this.emitInput();
    },
    // newPopupDatetime () {
    //   let datetime = DateTime.utc().setZone(this.zone).set({ seconds: 0, milliseconds: 0 })
    //   if (this.popupMinDatetime && datetime < this.popupMinDatetime) {
    //     datetime = this.popupMinDatetime.set({ seconds: 0, milliseconds: 0 })
    //   }
    //   if (this.popupMaxDatetime && datetime > this.popupMaxDatetime) {
    //     datetime = this.popupMaxDatetime.set({ seconds: 0, milliseconds: 0 })
    //   }
    //   if (this.minuteStep === 1) {
    //     return datetime
    //   }
    //   const roundedMinute = Math.round(datetime.minute / this.minuteStep) * this.minuteStep
    //   if (roundedMinute === 60) {
    //     return datetime.plus({ hours: 1 }).set({ minute: 0 })
    //   }
    //   return datetime.set({ minute: roundedMinute })
    // },
    setValue(e) {
      this.datetime = l(e.target.value), this.emitInput();
    }
  }
}, K = { class: "kapix-calendar-container" };
function $(e, a, r, n, i, t) {
  const o = h("DatetimePopup");
  return p(), c("div", K, [
    k(o, {
      type: "date",
      markers: e.markers,
      "marker-date-prop": e.markerDateProp,
      "marker-color": e.markerColor,
      "show-header": e.showHeader,
      datetime: t.popupDate,
      phrases: e.phrases,
      "use12-hour": e.use12Hour,
      "hour-step": e.hourStep,
      "minute-step": e.minuteStep,
      "min-datetime": t.popupMinDatetime,
      "max-datetime": t.popupMaxDatetime,
      "week-start": e.weekStart,
      flow: e.flow,
      title: e.title,
      "no-steps": "",
      onConfirm: t.confirm
    }, null, 8, ["markers", "marker-date-prop", "marker-color", "show-header", "datetime", "phrases", "use12-hour", "hour-step", "minute-step", "min-datetime", "max-datetime", "week-start", "flow", "title", "onConfirm"])
  ]);
}
const x = /* @__PURE__ */ E(b, [["render", $]]), J = /* @__PURE__ */ f({
  __name: "KapixCalendarInput",
  props: Z([Date, String]),
  emits: ["update:modelValue"],
  setup(e, { emit: a }) {
    u("KapixCalendarInput", z);
    const r = e, n = a, i = D({
      get() {
        return T(_(r));
      },
      set(t) {
        var o;
        n("update:modelValue", t), (o = r.onValueChanged) == null || o.call(r, t);
      }
    });
    return (t, o) => t.editable ? (p(), m(x, {
      key: 0,
      modelValue: w(i),
      "onUpdate:modelValue": o[0] || (o[0] = (d) => C(i) ? i.value = d : null),
      class: V([t.templateClass, "kapix-calendar"]),
      markers: t.options.markers,
      "marker-date-prop": t.options.markerDateProp,
      "marker-color": t.options.markerColor,
      "show-header": t.options.showHeader
    }, null, 8, ["modelValue", "class", "markers", "marker-date-prop", "marker-color", "show-header"])) : (p(), m(M, g(I({ key: 1 }, r)), null, 16));
  }
});
export {
  J as default
};
