import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import Card from "./components/Card/index.js";
import Media from "./components/Media/index.js";
import usePresetItemProps from "./hooks/usePresetItemProps.js";
import { SelectorContext } from "./Selector.js";
import React, { useContext } from "react";
//#region src/pro/Selector/Item.tsx
const Item = (props) => {
	const { actions, dataSource, indicator, numberSelector, optionItemValue, quantityInfo, values, children } = props;
	const { disabled, mode, variant, itemProps, preset, itemLayout } = useContext(SelectorContext);
	const { mediaProps, cardProps } = usePresetItemProps({
		variant,
		itemLayout,
		preset,
		itemProps,
		indicator,
		numberSelector,
		mode,
		disabled: disabled || dataSource.disabled,
		selected: dataSource.selected
	});
	const handleClick = () => {
		if (disabled || dataSource.disabled) return;
		if (dataSource.selected) actions.update(dataSource._key, { quantity: 0 });
		else {
			const quantity = dataSource.effectiveMin || 1;
			actions.update(dataSource._key, { quantity });
		}
	};
	if (variant === "media") return /* @__PURE__ */ React.createElement(Media, _objectSpread2(_objectSpread2({}, mediaProps), {}, {
		cover: dataSource.cover,
		label: dataSource._label,
		extra: numberSelector,
		indicator,
		selected: dataSource.selected,
		disabled: disabled || dataSource.disabled,
		onClick: handleClick
	}));
	const renderChildren = () => {
		if (typeof (cardProps === null || cardProps === void 0 ? void 0 : cardProps.renderContent) === "function") {
			var _cardProps$renderCont;
			return cardProps === null || cardProps === void 0 || (_cardProps$renderCont = cardProps.renderContent) === null || _cardProps$renderCont === void 0 ? void 0 : _cardProps$renderCont.call(cardProps, { dataSource });
		}
		if ("design" === props.__designMode) {
			if (children == null || Array.isArray(children) && !children.length) return /* @__PURE__ */ React.createElement("div", { className: "lc-container-placeholder" }, "拖拽组件或模板到这里");
		}
		return children ? children : /* @__PURE__ */ React.createElement("span", null, dataSource._label);
	};
	return /* @__PURE__ */ React.createElement(Card, _objectSpread2(_objectSpread2({}, cardProps), {}, {
		selected: dataSource.selected,
		disabled: disabled || dataSource.disabled,
		onClick: handleClick
	}), renderChildren());
};
//#endregion
export { Item as default };
