import { jsxs as D, jsx as r } from "react/jsx-runtime";
import { DatePicker as T } from "./index-DatePicker.js";
import { TimePicker as j } from "./index-TimePicker.js";
import i from "./index-moment.js";
import { useState as u, useEffect as w } from "react";
import I from "./index-DateTimePicker.module.scss.js";
const z = (c) => {
  const {
    date: s,
    time: f,
    onChange: l,
    minDate: d,
    maxDate: h,
    minTime: x,
    maxTime: H,
    pickerRef: P,
    disablePast: b,
    labelDate: g,
    freeSolo: p,
    labelTime: v,
    showAmPm: k,
    locale: y
  } = c, [m, C] = u(s !== void 0 ? i.unix(s).startOf("day") : void 0), [e, n] = u(f !== void 0 ? i(f, "HH:mm") : void 0);
  w(() => {
    if (l) {
      const t = m == null ? void 0 : m.clone().unix().valueOf(), a = e == null ? void 0 : e.clone().format("HH:mm");
      let o;
      t && a && (o = m == null ? void 0 : m.clone().set({
        hour: e == null ? void 0 : e.hour(),
        minute: e == null ? void 0 : e.minute()
      })), l(t, a, o);
    }
  }, [m, e]);
  const S = (t) => {
    t && C(i(t).startOf("day"));
  }, A = (t, a) => {
    const o = a == null ? void 0 : a.value;
    typeof o == "string" && (o.includes("AM") || o.includes("PM") ? n(i(o, "hh:mm A")) : n(i(o, "HH:mm")));
  };
  return D("div", {
    ref: P,
    className: I.container,
    children: [r(T, {
      label: g ?? "Start date",
      locale: y,
      disablePast: b,
      onChange: S,
      value: m == null ? void 0 : m.valueOf(),
      minDate: d,
      maxDate: h,
      required: !0
    }), r(j, {
      value: (e == null ? void 0 : e.format("HH:mm")) ?? "",
      label: v ?? "Start time",
      showAmPm: !!k,
      hourListType: "half",
      onChange: A,
      min: x,
      freeSolo: p,
      max: H
    })]
  });
};
export {
  z as DateTimePicker
};
