var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/select-time/index.tsx
var select_time_exports = {};
__export(select_time_exports, {
  default: () => select_time_default
});
module.exports = __toCommonJS(select_time_exports);
var import_react = __toESM(require("react"));
var import_Time = __toESM(require("../virtual-keyboard/Time"));
var import_antd = require("antd");
var import_RightPanel = __toESM(require("./RightPanel"));
var import_dayjs = __toESM(require("dayjs"));
var import_index = require("./index.less");
var SelectTime = (props) => {
  const { onChange, value, popoverProps, timePickerProps, timeProps, slice } = props;
  const [open, setOpen] = (0, import_react.useState)(false);
  const [_value, set_value] = (0, import_react.useState)("");
  (0, import_react.useEffect)(() => {
    set_value(value);
  }, [value]);
  const valueString = (0, import_react.useMemo)(() => {
    if (!_value) {
      return void 0;
    }
    if (typeof _value === "string") {
      return _value;
    }
    return _value == null ? void 0 : _value.valueString;
  }, [_value]);
  const previewValueString = (0, import_react.useMemo)(() => {
    if (!_value) {
      return null;
    }
    if (typeof _value === "string") {
      return _value;
    }
    return _value == null ? void 0 : _value.previewValueString;
  }, [_value]);
  const timePickerValue = (0, import_react.useMemo)(() => {
    if (!previewValueString) {
      return void 0;
    }
    return (0, import_dayjs.default)((0, import_dayjs.default)().format("YYYY-MM-DD") + " " + previewValueString);
  }, [previewValueString]);
  const _onChange = (e) => {
    if (!open) {
      return;
    }
    set_value(e);
  };
  const onEnter = (e) => {
    _onChange(e);
    onOpenChange(false, (e == null ? void 0 : e.previewValueString) || e);
  };
  const onOpenChange = (e, _val = previewValueString) => {
    setOpen(e);
    if (e) {
    } else {
      if (_val === value) {
        return;
      }
      onChange == null ? void 0 : onChange(_val);
    }
  };
  (0, import_react.useEffect)(() => {
    if (open) {
      document.body.classList.add("hide-scroll");
    } else {
      setTimeout(() => {
        document.body.classList.remove("hide-scroll");
      }, 150);
    }
  }, [open]);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Popover,
    {
      destroyTooltipOnHide: true,
      content: /* @__PURE__ */ import_react.default.createElement(
        import_Time.default,
        {
          onChange: _onChange,
          value: valueString,
          onEnter: (e) => {
            onEnter(e);
          },
          rightPanel: /* @__PURE__ */ import_react.default.createElement(
            import_RightPanel.default,
            {
              value: previewValueString,
              onChange: onEnter,
              slice
            }
          ),
          ...timeProps
        }
      ),
      open,
      placement: "bottom",
      arrow: false,
      onOpenChange,
      trigger: ["click"],
      ...popoverProps
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.TimePicker,
      {
        key: previewValueString || "",
        format: "HH:mm",
        size: "large",
        inputReadOnly: true,
        allowClear: false,
        open: false,
        value: timePickerValue,
        ...timePickerProps
      }
    )
  ));
};
var select_time_default = SelectTime;
