"use strict";
const React = require("react");
const debounce = require("../../../../../../lodash@4.17.21/node_modules/lodash/debounce.js");
const util = require("./util.js");
const classNames = require("../_util/classNames.js");
const usePrevious = require("../_util/hooks/usePrevious.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
function TimeColumn(props) {
  var prefixCls = props.prefixCls, list = props.list, value = props.value, onHandleSelect = props.onHandleSelect, unit = props.unit, popupVisible = props.popupVisible, scrollSticky = props.scrollSticky;
  var lis = React.useRef(/* @__PURE__ */ new Map());
  var wrapper = React.useRef();
  var ul = React.useRef();
  var listItemHeight = React.useRef(0);
  var prevPopupVisible = usePrevious(popupVisible);
  var prevScrollTop = React.useRef(wrapper.current && wrapper.current.scrollTop);
  React.useEffect(function() {
    var li = lis.current.get(value);
    if (li && popupVisible && prevPopupVisible) {
      util.scrollTo(wrapper.current, li.offsetTop, 150);
      prevScrollTop.current = li.offsetTop;
    }
  }, [value]);
  React.useEffect(function() {
    if (popupVisible && popupVisible !== prevPopupVisible) {
      var li = lis.current.get(value);
      if (li) {
        util.scrollTo(wrapper.current, li.offsetTop, 0);
        prevScrollTop.current = li.offsetTop;
      }
    }
  }, [popupVisible, prevPopupVisible]);
  React.useEffect(function() {
    if (list.length <= 1) {
      return;
    }
    listItemHeight.current = (ul.current.clientHeight - wrapper.current.clientHeight) / (list.length - 1);
  }, [list.length]);
  var onScrollList = React.useCallback(debounce(function() {
    var mathFunc = wrapper.current.scrollTop - prevScrollTop.current > 0 ? Math.ceil : Math.floor;
    var index = mathFunc(wrapper.current.scrollTop / listItemHeight.current);
    if (index !== value && list[index] && !list[index].disabled) {
      onHandleSelect(list[index].value, unit);
    }
  }, 100), [onHandleSelect]);
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
    className: classNames(prefixCls + "-list"),
    ref: wrapper,
    onWheel: scrollSticky && onScrollList,
    children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("ul", {
      ref: ul,
      children: list.map(function(item) {
        var _a;
        return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("li", {
          className: classNames(prefixCls + "-cell", (_a = {}, _a[prefixCls + "-cell-disabled"] = item.disabled, _a[prefixCls + "-cell-selected"] = item.selected, _a)),
          onClick: function() {
            return !item.disabled && onHandleSelect(item.value, unit);
          },
          ref: function(element) {
            lis.current.set(item.value, element);
          },
          children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
            className: prefixCls + "-cell-inner",
            children: item.label
          })
        }, item.value);
      })
    })
  });
}
module.exports = TimeColumn;
//# sourceMappingURL=time-column.js.map
