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 DateRangePicker_exports = {};
__export(DateRangePicker_exports, {
  DateRangePicker: () => DateRangePicker
});
module.exports = __toCommonJS(DateRangePicker_exports);
var import_jsx_runtime = require("react/jsx-runtime"), import_hooks = require("@datepicker-react/hooks"), import_icons_ui = require("@truststack/icons-ui"), import_react = require("react"), 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_dateHelper = require("./dateHelper");
function DateRangePicker(param) {
  var { startDate, endDate, onChange, ...props } = param, [state, setState] = (0, import_react.useState)({
    startDate,
    endDate,
    focusedInput: import_hooks.START_DATE
  }), { activeMonths, firstDayOfWeek, ...context } = (0, import_hooks.useDatepicker)({
    startDate: state.startDate,
    endDate: state.endDate,
    focusedInput: state.focusedInput,
    onDatesChange: handleDateChange,
    numberOfMonths: 1
  });
  function handleDateChange(data) {
    data.focusedInput ? setState(data) : setState({
      ...data,
      focusedInput: import_hooks.START_DATE
    }), typeof onChange == "function" && onChange(data);
  }
  var getInputValue = function() {
    return !state.startDate && !state.endDate ? "" : state.startDate && !state.endDate ? (0, import_dateHelper.getLocaleDate)({
      date: state.startDate
    }) : `${(0, import_dateHelper.getLocaleDate)({
      date: state.startDate
    })}${state.endDate ? " - " + (0, import_dateHelper.getLocaleDate)({
      date: state.endDate
    }) : ""}`;
  };
  return (0, import_react.useEffect)(function() {
    setState({
      ...state,
      startDate,
      endDate
    });
  }, [
    startDate,
    endDate
  ]), /* @__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: getInputValue(),
            // 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,
            snapPoints: [
              80
            ],
            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, {
                children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Sheet.SheetContent, {
                  margin: "$spacing.compact_margin",
                  children: (
                    /* We need to repropagate the context for this to work on Android */
                    /* @__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_CalendarPicker.CalendarPicker, {
                activeMonths,
                firstDayOfWeek
              })
            }, "date-time-picker-content")
          ]
        }, "date-time-picker-portal")
      ]
    })
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DateRangePicker
});
//# sourceMappingURL=DateRangePicker.js.map
