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/ProductList/gridComponents.tsx
var gridComponents_exports = {};
__export(gridComponents_exports, {
  GRID_LAYOUTS: () => GRID_LAYOUTS,
  createCustomGrid: () => createCustomGrid,
  createGridComponents: () => createGridComponents,
  createTwoColumnGrid: () => createTwoColumnGrid,
  parseGridConfig: () => parseGridConfig
});
module.exports = __toCommonJS(gridComponents_exports);
var import_react = __toESM(require("react"));
var parseGridConfig = (config) => {
  return config.split(":").map((num) => parseInt(num, 10)).filter((num) => !isNaN(num));
};
var calculateColumnWidth = (columns, index) => {
  const total = columns.reduce((sum, col) => sum + col, 0);
  const percentage = columns[index] / total * 100;
  return `${percentage}%`;
};
var createGridComponents = (layout) => {
  if (!layout) {
    layout = GRID_LAYOUTS.SINGLE_COLUMN;
  }
  const columns = parseGridConfig(layout.config);
  const isGrid = layout.grid && columns.length > 1;
  const GridListComponent = (0, import_react.memo)(({ children, ...props }) => {
    if (!isGrid) {
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: "product-list-wrapper",
          style: {
            display: "flex",
            flexDirection: "column",
            gap: "12px"
          },
          ...props
        },
        children
      );
    }
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "product-grid-wrapper",
        style: {
          display: "flex",
          flexWrap: "wrap",
          gap: "12px",
          ...props.style
        },
        ...props
      },
      children
    );
  });
  const GridItemComponent = (0, import_react.memo)(({ children, index, item, ...props }) => {
    if (!isGrid) {
      if (item && item.__typename === "category") {
        return /* @__PURE__ */ import_react.default.createElement("div", { id: `ps_category_${item.id}`, ...props }, children);
      }
      return /* @__PURE__ */ import_react.default.createElement("div", { ...props }, children);
    }
    if (item && item.__typename === "category") {
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          id: `ps_category_${item.id}`,
          style: {
            width: "100%",
            flexShrink: 0,
            ...props.style
          },
          ...props
        },
        children
      );
    }
    const columnIndex = index % columns.length;
    const width = calculateColumnWidth(columns, columnIndex);
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: {
          width: `calc(${width} - ${(columns.length - 1) * 12 / columns.length}px)`,
          flexShrink: 0,
          ...props.style
        },
        ...props
      },
      children
    );
  });
  GridListComponent.displayName = `GridListComponent_${layout.config}`;
  GridItemComponent.displayName = `GridItemComponent_${layout.config}`;
  return {
    List: GridListComponent,
    Item: GridItemComponent
  };
};
var GRID_LAYOUTS = {
  SINGLE_COLUMN: { grid: false, config: "12" },
  TWO_COLUMNS: { grid: true, config: "12:12" },
  THREE_COLUMNS: { grid: true, config: "8:8:8" },
  FOUR_COLUMNS: { grid: true, config: "6:6:6:6" },
  UNEQUAL_TWO: { grid: true, config: "8:16" },
  // 1:2 比例
  UNEQUAL_THREE: { grid: true, config: "6:12:6" }
  // 1:2:1 比例
};
var createTwoColumnGrid = () => createGridComponents(GRID_LAYOUTS.TWO_COLUMNS);
var createCustomGrid = (config) => createGridComponents({ grid: true, config });
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  GRID_LAYOUTS,
  createCustomGrid,
  createGridComponents,
  createTwoColumnGrid,
  parseGridConfig
});
