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 TimePicker_exports = {};
__export(TimePicker_exports, {
  TimePicker: () => TimePicker
});
module.exports = __toCommonJS(TimePicker_exports);
var import_react = require("react"),
  import_react_native = require("react-native-web"),
  import_tamagui = require("tamagui"),
  import_dateHelper = require("./dateHelper.cjs"),
  import_typography = require("./typography.cjs"),
  import_jsx_runtime = require("react/jsx-runtime");
const TimePicker = ({
    value,
    onChange,
    ...props
  }) => {
    const handleHourChange = input => {
        let sanitizedText = input.replace(/[^0-9]/g, "");
        sanitizedText.length >= 3 && (sanitizedText = sanitizedText.slice(1, sanitizedText.length));
        let numericValue = parseInt(sanitizedText, 10);
        const newDate = (0, import_dateHelper.isDateValid)(value) ? new Date(value) : /* @__PURE__ */new Date();
        (sanitizedText.length == 3 && sanitizedText.endsWith("0") && !sanitizedText.startsWith("0") || numericValue > 24) && (numericValue = 0), newDate.setHours(numericValue || 0), onChange(newDate);
      },
      handleMinuteChange = input => {
        let sanitizedText = input.replace(/[^0-9]/g, "");
        sanitizedText.length >= 3 && (sanitizedText = sanitizedText.slice(1, sanitizedText.length));
        let numericValue = parseInt(sanitizedText, 10);
        const newDate = (0, import_dateHelper.isDateValid)(value) ? new Date(value) : /* @__PURE__ */new Date();
        (sanitizedText.length == 3 && sanitizedText.endsWith("0") && !sanitizedText.startsWith("0") || numericValue > 59) && (numericValue = 0), newDate.setMinutes(numericValue), onChange(newDate);
      },
      renderHour = (0, import_react.useMemo)(() => {
        const hour = value?.getHours() || 0;
        return hour < 10 ? `0${hour}` : `${hour}`;
      }, [value]),
      renderMinute = (0, import_react.useMemo)(() => {
        const minute = value?.getMinutes() || 0;
        return minute < 10 ? `0${minute}` : `${minute}`;
      }, [value]);
    return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
      gap: 12,
      children: [/* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
        ai: "center",
        gap: 24,
        ...props,
        children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.YStack, {
          gap: 4,
          children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(TimeInput, {
            variant: "hour",
            value: renderHour,
            onChangeText: handleHourChange,
            keyboardType: "numeric",
            ...(import_react_native.Platform.OS != "web" ? {
              selection: {
                start: 0,
                end: 2
              }
            } : {})
          })
        }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_typography.Display, {
          size: "large",
          margin: -12,
          pb: 4,
          children: ":"
        }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.YStack, {
          gap: 4,
          children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(TimeInput, {
            variant: "minute",
            value: renderMinute,
            onChangeText: handleMinuteChange,
            keyboardType: "numeric",
            marginRight: -12,
            ...(import_react_native.Platform.OS != "web" ? {
              selection: {
                start: 0,
                end: 2
              }
            } : {})
          })
        })]
      }), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
        gap: 110,
        children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_typography.Body, {
          size: "small",
          children: "Hour"
        }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_typography.Body, {
          size: "small",
          children: "Minute"
        })]
      })]
    });
  },
  TimeInput = (0, import_tamagui.styled)(import_tamagui.Input, {
    name: "TimeInput",
    borderRadius: "$shape.corner_sm",
    height: 80,
    width: 96,
    focusStyle: {
      borderWidth: 0,
      outlineStyle: "none"
    },
    fos: 48,
    textAlign: "center",
    borderColor: "transparent",
    variants: {
      variant: {
        hour: {
          backgroundColor: "$primaryContainer",
          col: "$onPrimaryContainer",
          focusStyle: {
            borderWidth: 2,
            borderColor: "$primary"
          }
        },
        minute: {
          backgroundColor: "$surfaceContainerHighest",
          col: "$onSurface",
          focusStyle: {
            borderWidth: 2,
            borderColor: "$surfaceVariant"
          }
        }
      }
    }
  }),
  Frame = (0, import_tamagui.styled)(import_tamagui.ThemeableStack, {
    name: "VerticalSegments",
    height: 80,
    maxHeight: 80,
    width: 52,
    maxWidth: 52,
    borderWidth: 1,
    borderColor: "$outline",
    borderRadius: "$shape.corner_m",
    flexDirection: "column",
    fg: 1,
    overflow: "hidden"
  }),
  ItemContext = (0, import_tamagui.createStyledContext)({
    selected: !1
  }),
  Item = (0, import_tamagui.styled)(import_tamagui.ThemeableStack, {
    name: "VerticalSegmentsItem",
    context: ItemContext,
    justifyContent: "center",
    f: 1,
    alignItems: "center",
    variants: {
      selected: {
        true: {
          backgroundColor: "$tertiaryContainer",
          hoverStyle: {
            backgroundColor: "$surfaceContainer"
          }
        },
        false: {
          hoverStyle: {
            backgroundColor: "$surfaceContainer"
          }
        }
      }
    }
  }),
  Label = (0, import_tamagui.styled)(import_typography.Title, {
    size: "large",
    context: ItemContext,
    variants: {
      selected: {
        true: {
          col: "$onTertiaryContainer"
        },
        false: {}
      }
    }
  }),
  SegmentItem = (0, import_tamagui.withStaticProperties)(Item, {
    Props: ItemContext.Provider,
    Label
  }),
  VerticalSegment = (0, import_tamagui.withStaticProperties)(Frame, {
    Item: SegmentItem
  });