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 DatePicker_exports = {};
__export(DatePicker_exports, {
  DatePicker: () => DatePicker
});
module.exports = __toCommonJS(DatePicker_exports);
var import_hooks = require("@datepicker-react/hooks"),
  import_icons_ui = require("@truststack/icons-ui"),
  import_react = require("react"),
  import_tamagui = require("tamagui"),
  import_Button = require("./Button.cjs"),
  import_CalendarPicker = require("./CalendarPicker.cjs"),
  import_DatePickerProvider = require("./DatePickerProvider.cjs"),
  import_Dialog = require("./Dialog.cjs"),
  import_Sheet = require("./Sheet.cjs"),
  import_TextField = require("./TextField.cjs"),
  import_dateHelper = require("./dateHelper.cjs"),
  import_jsx_runtime = require("react/jsx-runtime");
function DatePicker({
  value,
  onChange,
  required,
  ...props
}) {
  const [open, setOpen] = (0, import_react.useState)(!1),
    [state, setState] = (0, import_react.useState)({
      startDate: value,
      endDate: null,
      focusedInput: import_hooks.START_DATE
    }),
    {
      activeMonths,
      firstDayOfWeek,
      ...context
    } = (0, import_hooks.useDatepicker)({
      startDate: state.startDate,
      endDate: null,
      focusedInput: state.focusedInput,
      onDatesChange: handleDateChange,
      numberOfMonths: 1
    });
  function handleDateChange(data) {
    setState({
      ...data,
      focusedInput: import_hooks.START_DATE
    });
  }
  const inputValue = (0, import_dateHelper.getLocaleDate)({
      date: value
    }),
    selectedDate = (0, import_dateHelper.getLocaleDate)({
      date: state.startDate
    }),
    label = required ? `${props.label} *` : props.label;
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_DatePickerProvider.DatepickerProvider, {
    ...context,
    children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_Dialog.Dialog, {
      modal: !0,
      open,
      onOpenChange: setOpen,
      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,
          label,
          pointerEvents: "none",
          placeholder: "DD/MM/YYYY",
          cursor: "pointer",
          value: inputValue || void 0,
          trailingIcon: import_icons_ui.Calendar,
          focusable: !0
        })
      }), /* @__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",
          dismissOnOverlayPress: !0,
          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: /* @__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.jsxs)(import_Dialog.Dialog.Content, {
          fullscreen: !1,
          backgroundColor: "$surfaceContainerLowest",
          children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_CalendarPicker.CalendarPicker, {
            activeMonths,
            firstDayOfWeek
          }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.View, {
            marginTop: 12,
            justifyContent: "flex-end",
            flexDirection: "row",
            children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_Button.Button, {
              disabled: !state.startDate,
              onPress: () => {
                onChange(state.startDate), setOpen(!1);
              },
              children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Button.Button.Icon, {
                Icon: import_icons_ui.Calendar
              }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Button.Button.Text, {
                children: selectedDate ? `Confirm: ${selectedDate}` : "Select a date"
              })]
            })
          })]
        }, "date-time-picker-content")]
      }, "date-time-picker-portal")]
    })
  });
}