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/plus/productSelect/CategoryTabs/index.tsx
var CategoryTabs_exports = {};
__export(CategoryTabs_exports, {
  CategorySkeleton: () => import_CategorySkeleton.default,
  default: () => CategoryTabs_default
});
module.exports = __toCommonJS(CategoryTabs_exports);
var import_react = __toESM(require("react"));
var import_IntersectionObserver = __toESM(require("../components/IntersectionObserver"));
var import_TabsStructure = require("../components/TabsStructure");
var import_TabsStructure2 = require("../components/TabsStructure/TabsStructure.less");
var import_CategorySkeleton = __toESM(require("./CategorySkeleton"));
var import__ = require("../index");
var CategoryTabs = (0, import_react.forwardRef)((props, ref) => {
  const { items, activeKey, onChange, loading = false, skeleton } = props;
  const railRef = (0, import_react.useRef)(null);
  const [isAtStart, setIsAtStart] = (0, import_react.useState)(true);
  const [isAtEnd, setIsAtEnd] = (0, import_react.useState)(false);
  const [needsScrollButtons, setNeedsScrollButtons] = (0, import_react.useState)(false);
  const scrollLeft = (0, import_react.useCallback)(() => {
    if (!railRef.current) return;
    const container = railRef.current;
    const scrollAmount = container.clientWidth * 0.8;
    const newPosition = Math.max(0, container.scrollLeft - scrollAmount);
    container.scrollTo({ left: newPosition, behavior: "smooth" });
  }, []);
  const scrollRight = (0, import_react.useCallback)(() => {
    if (!railRef.current) return;
    const container = railRef.current;
    const scrollAmount = container.clientWidth * 0.8;
    const maxScroll = container.scrollWidth - container.clientWidth;
    const newPosition = Math.min(
      maxScroll,
      container.scrollLeft + scrollAmount
    );
    container.scrollTo({ left: newPosition, behavior: "smooth" });
  }, []);
  (0, import_react.useEffect)(() => {
    const updateScrollButtonsVisibility = () => {
      if (railRef.current) {
        const { scrollWidth, clientWidth } = railRef.current;
        console.log("检测滚动按钮需求:", {
          scrollWidth,
          clientWidth,
          needsScroll: scrollWidth > clientWidth
        });
        setNeedsScrollButtons(scrollWidth > clientWidth);
      }
    };
    let resizeObserver = null;
    const timer = setTimeout(() => {
      const container = railRef.current;
      if (!container) {
        console.log("容器未找到，跳过滚动按钮检测");
        return;
      }
      updateScrollButtonsVisibility();
      resizeObserver = new ResizeObserver(updateScrollButtonsVisibility);
      resizeObserver.observe(container);
    }, 100);
    return () => {
      clearTimeout(timer);
      if (resizeObserver) {
        resizeObserver.disconnect();
      }
    };
  }, [items]);
  const { selectionIndicatorProps, listContainerProps } = (0, import_TabsStructure.useSelectionIndicator)(
    railRef,
    activeKey || ""
  );
  if (loading && skeleton) {
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, skeleton);
  }
  return /* @__PURE__ */ import_react.default.createElement(import_IntersectionObserver.default, null, items.length > 0 && /* @__PURE__ */ import_react.default.createElement("div", { className: `${import__.PREFIX}__tabs-wrapper` }, /* @__PURE__ */ import_react.default.createElement(
    import_TabsStructure.TabsStructure,
    {
      variant: "pill",
      backgroundVariant: "onPage",
      selectedTab: activeKey
    },
    needsScrollButtons && /* @__PURE__ */ import_react.default.createElement(
      import_TabsStructure.TabsStructure.ChevronButton,
      {
        direction: "prev",
        disabled: isAtStart,
        onClick: scrollLeft,
        style: { marginRight: "8px" }
      }
    ),
    /* @__PURE__ */ import_react.default.createElement(import_TabsStructure.TabsStructure.Rail, { ref: railRef }, /* @__PURE__ */ import_react.default.createElement(
      import_IntersectionObserver.IntersectionTrigger,
      {
        onShow: () => {
          console.log("is start");
          setIsAtStart(true);
        },
        onHide: () => {
          console.log("is start false");
          setIsAtStart(false);
        },
        style: {
          width: 1,
          height: 1,
          flexShrink: 0,
          background: "rgba(0,0,0,0)",
          transform: "translateX(1px)"
        },
        className: "visibility-detector start-detector"
      }
    ), /* @__PURE__ */ import_react.default.createElement(import_TabsStructure.TabsStructure.SelectionIndicator, { ...selectionIndicatorProps }), /* @__PURE__ */ import_react.default.createElement(import_TabsStructure.TabsStructure.ListContainer, { ...listContainerProps }, items.map((item) => /* @__PURE__ */ import_react.default.createElement(
      import_TabsStructure.TabsStructure.Item,
      {
        key: item.key,
        tabId: item.key,
        "aria-selected": activeKey === item.key,
        onClick: () => onChange(item.key),
        className: "tab-item"
      },
      item.label
    ))), /* @__PURE__ */ import_react.default.createElement(
      import_IntersectionObserver.IntersectionTrigger,
      {
        className: "visibility-detector end-detector",
        onShow: () => {
          console.log("is end");
          setIsAtEnd(true);
        },
        onHide: () => {
          console.log("is end false");
          setIsAtEnd(false);
        },
        style: {
          width: 1,
          height: 1,
          flexShrink: 0,
          background: "rgba(0,0,0,0)",
          transform: "translateX(-1px)"
        }
      }
    )),
    needsScrollButtons && /* @__PURE__ */ import_react.default.createElement(
      import_TabsStructure.TabsStructure.ChevronButton,
      {
        direction: "next",
        disabled: isAtEnd,
        onClick: scrollRight,
        style: { marginLeft: "8px" }
      }
    )
  )));
});
var CategoryTabs_default = CategoryTabs;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  CategorySkeleton
});
