var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
  if (from && typeof from == "object" || typeof from == "function")
    for (let key of __getOwnPropNames(from))
      !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var DateTimePicker_exports = {};
__export(DateTimePicker_exports, {
  DateTimePicker: () => DateTimePicker
});
module.exports = __toCommonJS(DateTimePicker_exports);
var import_hooks = require("@datepicker-react/hooks"), import_icons_ui = require("@truststack/icons-ui"), import_react = require("react"), import_react_native = require("react-native-web"), import_tamagui = require("tamagui"), import_CalendarPicker = require("./CalendarPicker"), import_DatePickerProvider = require("./DatePickerProvider"), import_Dialog = require("./Dialog"), import_Sheet = require("./Sheet"), import_TextField = require("./TextField"), import_TimePicker = require("./TimePicker"), import_dateHelper = require("./dateHelper"), import_jsx_runtime = require("react/jsx-runtime");
function DateTimePicker({
  value,
  onChange,
  ...props
}) {
  const [time, setTime] = (0, import_react.useState)(value), { activeMonths, firstDayOfWeek, ...context } = (0, import_hooks.useDatepicker)({
    startDate: value,
    endDate: null,
    focusedInput: import_hooks.START_DATE,
    onDatesChange: handleDateChange,
    numberOfMonths: 1
  });
  function handleDateChange(data) {
    onChange && onChange(data.startDate);
  }
  const inputValue = (0, import_react.useMemo)(
    () => (0, import_dateHelper.getLocaleDateTime)({ date: new Date(value) }),
    [value]
  );
  return (0, import_react.useEffect)(() => {
    if (!value || !time) return;
    const year = value.getFullYear(), month = value.getMonth(), day = value.getDate(), hours = time.getHours(), minutes = time.getMinutes(), seconds = time.getSeconds(), milliseconds = time.getMilliseconds(), newDate = new Date(
      year,
      month,
      day,
      hours,
      minutes,
      seconds,
      milliseconds
    );
    newDate.getTime() !== value.getTime() && onChange && onChange((0, import_dateHelper.isDateValid)(newDate) ? newDate : /* @__PURE__ */ new Date());
  }, [time]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DatePickerProvider.DatepickerProvider, { ...context, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Dialog.Dialog, { modal: !0, children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_Dialog.Dialog.Trigger,
      {
        fg: 1,
        disabled: props.disabled,
        padding: 0,
        bc: "transparent",
        bw: 0,
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import_TextField.TextField,
          {
            ...props,
            pointerEvents: "none",
            cursor: "pointer",
            value: inputValue,
            placeholder: "DD/MM/YYYY",
            trailingIcon: import_icons_ui.Calendar
          }
        )
      }
    ),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.Adapt, { when: "sm", platform: "touch", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
      import_Sheet.Sheet,
      {
        modal: !0,
        dismissOnSnapToBottom: !0,
        snapPoints: [80],
        moveOnKeyboardChange: !0,
        animation: "quick",
        children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Sheet.Sheet.Overlay, {}),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Sheet.Sheet.Handle, {}),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Sheet.Sheet.Frame, { p: 16, pt: 20, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DatePickerProvider.DatepickerProvider, { ...context, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.Adapt.Contents, {}) }) })
        ]
      }
    ) }),
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_Dialog.Dialog.Portal, { children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Dialog.Dialog.Overlay, {}, "date-time-picker-overlay"),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import_Dialog.Dialog.Content,
        {
          fullscreen: !1,
          backgroundColor: "$surfaceContainerLowest",
          children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.ScrollView, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.YStack, { gap: 16, children: [
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              import_CalendarPicker.CalendarPicker,
              {
                col: "$onPrimaryContainer",
                activeMonths,
                firstDayOfWeek
              }
            ),
            /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.XStack, { justifyContent: "center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.KeyboardAvoidingView, { behavior: "padding", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              import_TimePicker.TimePicker,
              {
                value,
                onChange: (time2) => setTime(new Date(time2 || /* @__PURE__ */ new Date()))
              }
            ) }) })
          ] }) })
        },
        "date-time-picker-content"
      )
    ] }, "date-time-picker-portal")
  ] }) });
}
//# sourceMappingURL=DateTimePicker.js.map
