import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import "./gridComponents.js";
import React, { forwardRef, memo, useMemo } from "react";
import classNames from "classnames";
//#region src/plus/productSelect/ProductList/index.tsx
const _excluded = ["children"], _excluded2 = ["children", "index"];
const DefaultListComponent = memo((_ref) => {
	let { children } = _ref, listProps = _objectWithoutProperties(_ref, _excluded);
	return /* @__PURE__ */ React.createElement("div", _objectSpread2({ className: "product-list-wrapper" }, listProps), children);
});
const DefaultItemComponent = memo((_ref2) => {
	let { children, index } = _ref2, itemProps = _objectWithoutProperties(_ref2, _excluded2);
	return /* @__PURE__ */ React.createElement("div", _objectSpread2(_objectSpread2({}, itemProps), {}, {
		"data-index": index,
		"data-item-index": index
	}), children);
});
const ProductList = forwardRef((props, ref) => {
	const { className, data, context, components, itemContent } = props;
	const ListComponent = useMemo(() => (components === null || components === void 0 ? void 0 : components.List) || DefaultListComponent, [components === null || components === void 0 ? void 0 : components.List]);
	const ItemComponent = useMemo(() => (components === null || components === void 0 ? void 0 : components.Item) || DefaultItemComponent, [components === null || components === void 0 ? void 0 : components.Item]);
	const itemContentRenderer = useMemo(() => {
		if (itemContent) return (item, index) => itemContent(index, item, context);
		return (item, index) => /* @__PURE__ */ React.createElement("div", null, index);
	}, [itemContent, context]);
	const renderedItems = useMemo(() => {
		return data === null || data === void 0 ? void 0 : data.map((item, index) => {
			const content = itemContentRenderer(item, index);
			return /* @__PURE__ */ React.createElement(ItemComponent, {
				key: `${item.id || index}-${index}`,
				item,
				index,
				"data-index": index,
				"data-item-index": index,
				context
			}, content);
		});
	}, [
		data,
		ItemComponent,
		itemContentRenderer
	]);
	return /* @__PURE__ */ React.createElement("div", { className: classNames(className) }, /* @__PURE__ */ React.createElement(ListComponent, {
		ref,
		context
	}, renderedItems));
});
//#endregion
export { ProductList as default };
