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/list/components/WaterfallList/WaterfallList.tsx
var WaterfallList_exports = {};
__export(WaterfallList_exports, {
  default: () => WaterfallList_default
});
module.exports = __toCommonJS(WaterfallList_exports);
var import_react = __toESM(require("react"));
var import_WaterfallList = require("./WaterfallList.less");
var WaterfallList = (props) => {
  const {
    layout,
    layoutDirection,
    columnGap,
    rowGap,
    columns,
    rows,
    registerItemRef,
    children,
    renderItem
  } = props;
  const hasChildren = children && import_react.default.Children.count(children) > 0;
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "waterfall-container",
      style: {
        display: "flex",
        // 垂直模式：轨道间距用列间距，水平模式：轨道间距用行间距
        gap: layoutDirection === "vertical" ? `${columnGap}px` : `${rowGap}px`,
        width: "100%",
        flexDirection: layoutDirection === "vertical" ? "row" : "column",
        // 垂直模式时轨道横向排列，水平模式时轨道纵向排列
        alignItems: "flex-start",
        // 防止瀑布流列被拉伸到相同高度
        // 水平模式下需要足够的高度来容纳多行
        ...layoutDirection === "horizontal" && {
          minHeight: "fit-content",
          height: "auto"
        }
      }
    },
    false,
    layout.tracks.map((track, trackIndex) => {
      let globalIndex = 0;
      for (let i = 0; i < trackIndex; i++) {
        globalIndex += layout.tracks[i].items.length;
      }
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          key: trackIndex,
          className: `waterfall-track waterfall-track-${layoutDirection}`,
          style: {
            // 垂直模式：每列等宽不收缩，水平模式：每行自适应高度
            flex: layoutDirection === "vertical" ? "1 0 0" : "0 0 auto",
            display: "flex",
            flexDirection: layoutDirection === "vertical" ? "column" : "row",
            // 垂直模式时轨道内垂直排列，水平模式时轨道内水平排列
            // 垂直模式：轨道内用行间距，水平模式：轨道内用列间距
            gap: layoutDirection === "vertical" ? `${rowGap}px` : `${columnGap}px`,
            // 水平模式下的额外样式
            ...layoutDirection === "horizontal" && {
              width: "100%",
              minHeight: "120px",
              // 确保行有最小高度
              alignItems: "flex-start"
            }
          }
        },
        track.items.map((item, trackItemIndex) => {
          const itemIndex = globalIndex + trackItemIndex;
          return /* @__PURE__ */ import_react.default.createElement(
            "div",
            {
              key: item.id || `${trackIndex}-${trackItemIndex}`,
              className: "list-item waterfall-item",
              ref: (el) => registerItemRef(item.id || `${trackIndex}-${trackItemIndex}`, el),
              style: {
                // 根据布局方向设置尺寸约束 - 应用到容器上
                ...layoutDirection === "vertical" ? {
                  width: "100%",
                  height: item.height ? `${item.height}px` : "auto",
                  minHeight: "unset",
                  maxHeight: "none",
                  flexShrink: 0,
                  flexGrow: 0,
                  boxSizing: "border-box",
                  overflow: "hidden",
                  // 防止内容溢出
                  position: "relative"
                  // 为调试信息定位
                } : {
                  width: item.width ? `${item.width}px` : "auto",
                  flexShrink: 0
                  // 水平模式：保持预设宽度，不收缩
                }
              }
            },
            false,
            hasChildren ? import_react.default.Children.map(children, (child, childIndex) => {
              if ((0, import_react.isValidElement)(child)) {
                return (0, import_react.cloneElement)(child, {
                  ...child.props,
                  item,
                  index: itemIndex,
                  key: `${item.id || `${trackIndex}-${trackItemIndex}`}-${childIndex}`
                });
              }
              return child;
            }) : renderItem ? renderItem(item, itemIndex) : (
              // 瀑布流的默认渲染 - 高度由容器控制
              /* @__PURE__ */ import_react.default.createElement(
                "div",
                {
                  className: "default-waterfall-item",
                  style: {
                    // 内容样式，高度由外部容器控制
                    ...layoutDirection === "horizontal" && {
                      width: item.width ? `${item.width}px` : "200px",
                      minHeight: "120px",
                      flexShrink: 0
                    },
                    padding: "16px",
                    backgroundColor: "#fff",
                    borderRadius: "8px",
                    boxShadow: "0 2px 8px rgba(0, 0, 0, 0.1)",
                    border: "1px solid #f0f0f0",
                    display: "flex",
                    flexDirection: "column",
                    // 调试用：显示实际高度
                    position: "relative",
                    // 填充容器高度
                    height: "100%",
                    boxSizing: "border-box"
                  }
                },
                item.title && /* @__PURE__ */ import_react.default.createElement("h3", { style: { margin: "0 0 12px 0", fontSize: "16px", fontWeight: 500, color: "#333" } }, item.title),
                item.name && !item.title && /* @__PURE__ */ import_react.default.createElement("h3", { style: { margin: "0 0 12px 0", fontSize: "16px", fontWeight: 500, color: "#333" } }, item.name),
                item.content && /* @__PURE__ */ import_react.default.createElement("p", { style: { margin: 0, fontSize: "14px", lineHeight: "1.5", color: "#666" } }, item.content),
                item.description && !item.content && /* @__PURE__ */ import_react.default.createElement("p", { style: { margin: 0, fontSize: "14px", lineHeight: "1.5", color: "#666" } }, item.description),
                !item.title && !item.name && !item.content && !item.description && /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: "14px", color: "#999", wordBreak: "break-all" } }, typeof item === "object" ? Object.entries(item).slice(0, 3).map(([key, value]) => /* @__PURE__ */ import_react.default.createElement("div", { key, style: { marginBottom: "4px" } }, /* @__PURE__ */ import_react.default.createElement("strong", null, key, ":"), " ", String(value))) : String(item))
              )
            )
          );
        })
      );
    })
  );
};
var WaterfallList_default = WaterfallList;
