import { isString as S } from "lodash-es";
import { D as M, c as b, a as n, d as u, s as g } from "./constants-f8ee2902.js";
import { at as C, a7 as w } from "./index-d46d84f5.js";
import { resolveComponent as d, openBlock as p, createBlock as c, withCtx as s, createElementVNode as h, renderSlot as o, normalizeClass as I, normalizeStyle as O, createElementBlock as V, createCommentVNode as f, createTextVNode as k, toDisplayString as D } from "vue";
const P = `.kapix-datetime-picker-container{width:100%;height:100%;min-width:0;min-height:0;display:flex;align-items:center}.vdatetime-fade-enter-active,.vdatetime-fade-leave-active{transition:opacity .4s}.vdatetime-fade-enter,.vdatetime-fade-leave-to{opacity:0}.vdatetime-overlay{z-index:999;position:fixed;top:0;right:0;bottom:0;left:0;background:rgba(0,0,0,.5);transition:opacity .5s}
`;
w("KapixDatetimePicker", P);
const E = {
  components: {
    DatetimePopup: M
  },
  // inheritAttrs: false,
  props: b,
  emits: ["update:modelValue", "close"],
  data() {
    return {
      isOpen: !1,
      datetime: null
    };
  },
  computed: {
    inputValue({ datetime: e, format: t, type: m, zone: r }) {
      if (!t)
        switch (m) {
          case "date":
            t = n.DATE_MED;
            break;
          case "time":
            t = n.TIME_24_SIMPLE;
            break;
          case "datetime":
          case "default":
            t = n.DATETIME_MED;
            break;
        }
      return S(t) ? e ? n.fromISO(e).setZone(r).toFormat(t) : "" : e ? e.setZone(r).toLocaleString(t) : "";
    },
    popupDate({ datetime: e }) {
      return e ? e.setZone(this.zone) : this.newPopupDatetime();
    },
    popupMinDatetime({ minDatetime: e }) {
      return e ? n.fromISO(e).setZone(this.zone) : null;
    },
    popupMaxDatetime({ maxDatetime: e }) {
      return e ? n.fromISO(e).setZone(this.zone) : null;
    }
  },
  watch: {
    modelValue: {
      immediate: !0,
      handler(e) {
        this.datetime = u(e, this.zone);
      }
    }
  },
  methods: {
    emitInput() {
      let e = this.datetime ? this.datetime.setZone(this.valueZone) : null;
      e && this.type === "date" && (e = g(e)), this.$emit("update:modelValue", e ? e.toJSDate() : null);
    },
    open(e) {
      e.target.blur(), this.isOpen = !0;
    },
    close() {
      this.isOpen = !1, this.$emit("close");
    },
    confirm(e) {
      this.datetime = e.toUTC(), this.emitInput(), this.close();
    },
    cancel() {
      this.close();
    },
    clickOutside() {
      this.backdropClick === !0 && this.cancel();
    },
    newPopupDatetime() {
      let e = n.utc().setZone(this.zone).set({ seconds: 0, milliseconds: 0 });
      if (this.popupMinDatetime && e < this.popupMinDatetime && (e = this.popupMinDatetime.set({ seconds: 0, milliseconds: 0 })), this.popupMaxDatetime && e > this.popupMaxDatetime && (e = this.popupMaxDatetime.set({ seconds: 0, milliseconds: 0 })), this.minuteStep === 1)
        return e;
      const t = Math.round(e.minute / this.minuteStep) * this.minuteStep;
      return t === 60 ? e.plus({ hours: 1 }).set({ minute: 0 }) : e.set({ minute: t });
    },
    setValue(e) {
      this.datetime = u(e.target.value), this.emitInput();
    }
  }
}, Z = ["id", "value"], z = ["name", "value"];
function T(e, t, m, r, l, i) {
  const v = d("DatetimePopup"), y = d("tippy");
  return p(), c(y, {
    interactive: "",
    trigger: "manual",
    placement: "bottom-start",
    visible: l.isOpen,
    theme: "no",
    onHidden: i.close
  }, {
    trigger: s(() => [
      h("div", {
        class: "kapix-datetime-picker-container",
        onClick: t[1] || (t[1] = (...a) => i.open && i.open(...a))
      }, [
        o(e.$slots, "before"),
        h("input", {
          id: e.inputId,
          class: I(["vdatetime-input", e.inputClass]),
          style: O(e.inputStyle),
          type: "text",
          value: i.inputValue
        }, null, 14, Z),
        e.hiddenName ? (p(), V("input", {
          key: 0,
          type: "hidden",
          name: e.hiddenName,
          value: e.value,
          onInput: t[0] || (t[0] = (...a) => i.setValue && i.setValue(...a))
        }, null, 40, z)) : f("", !0),
        o(e.$slots, "after")
      ])
    ]),
    default: s(() => [
      l.isOpen ? (p(), c(v, {
        key: 0,
        markers: e.markers,
        "marker-date-prop": e.markerDateProp,
        "marker-color": e.markerColor,
        type: e.type,
        datetime: i.popupDate,
        phrases: e.phrases,
        "use12-hour": e.use12Hour,
        "hour-step": e.hourStep,
        "minute-step": e.minuteStep,
        "min-datetime": i.popupMinDatetime,
        "max-datetime": i.popupMaxDatetime,
        auto: e.auto,
        "week-start": e.weekStart,
        flow: e.flow,
        title: e.title,
        onConfirm: i.confirm,
        onCancel: i.cancel
      }, {
        "button-cancel__internal": s((a) => [
          o(e.$slots, "button-cancel", {
            step: a.step
          }, () => [
            k(D(e.phrases.cancel), 1)
          ])
        ]),
        "button-confirm__internal": s((a) => [
          o(e.$slots, "button-confirm", {
            step: a.step
          }, () => [
            k(D(e.phrases.ok), 1)
          ])
        ]),
        _: 3
      }, 8, ["markers", "marker-date-prop", "marker-color", "type", "datetime", "phrases", "use12-hour", "hour-step", "minute-step", "min-datetime", "max-datetime", "auto", "week-start", "flow", "title", "onConfirm", "onCancel"])) : f("", !0)
    ]),
    _: 3
  }, 8, ["visible", "onHidden"]);
}
const A = /* @__PURE__ */ C(E, [["render", T]]);
export {
  A as K
};
