import { _objectSpread2 } from "../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import useEngineContext from "../../../../../../hooks/useEngineContext.js";
import { PREFIX } from "../../status.js";
import Action from "../Action/index.js";
import CardWrapper from "../CardWrapper/index.js";
import Cover from "../Cover/index.js";
import { useDynamicComponents } from "../../hooks/useDynamicComponents.js";
import locales_default from "../../locales.js";
import CardMoreText from "../CardMoreText/index.js";
import WarningLists from "../WarningLists/index.js";
import React, { useCallback, useMemo, useState } from "react";
import { locales } from "@pisell/utils";
import "./index.less";
//#region src/plus/productSelect/ProductCard/SkuCard/components/CardCom/index.tsx
const CardCom = ({ props, className }) => {
	var _context$appHelper$ut, _dataSource$sortKeys3;
	const context = useEngineContext();
	const [isFold, setIsFold] = useState(false);
	locales.init(locales_default, ((_context$appHelper$ut = context.appHelper.utils) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut = _context$appHelper$ut.storage) === null || _context$appHelper$ut === void 0 ? void 0 : _context$appHelper$ut.get("umi_locale")) || "en");
	const { skuCardConfig, skuImageConfig, dataSource, skuActionConfig, skuTextConfig } = props;
	const { renderComponents } = useDynamicComponents();
	const { layoutDirection, displayMode, isFoldable } = skuCardConfig || {};
	const { isCover, height } = skuImageConfig || {};
	const { method } = skuActionConfig || {};
	const { paddingY, justifyContent, alignItems, slot } = (skuTextConfig === null || skuTextConfig === void 0 ? void 0 : skuTextConfig.infoConfig) || {};
	/**
	* @title: 文本区域样式
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-09-09 13:38
	*/
	const contentStyle = useMemo(() => {
		return {
			minHeight: isCover && layoutDirection === "row" && displayMode !== "display_a1" ? `${height}` : "auto",
			padding: `${paddingY || 0}px 0`,
			alignItems: layoutDirection === "column" ? alignItems : "initial",
			justifyContent: layoutDirection === "row" ? justifyContent : "space-between"
		};
	}, [
		paddingY,
		justifyContent,
		alignItems,
		isCover,
		height,
		layoutDirection,
		displayMode
	]);
	/**
	* @title: 操作区域
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-09-11 18:21
	*/
	const actionCom = useCallback((key) => {
		if (displayMode === "display_a1") return false;
		if (key === "column") {
			if (layoutDirection === "column" && method === "button") return /* @__PURE__ */ React.createElement(Action, {
				props,
				className: `${PREFIX}__card-action-custom`
			});
			return false;
		}
		if (key === "row") return /* @__PURE__ */ React.createElement("div", { style: { opacity: layoutDirection === "column" ? 0 : 1 } }, /* @__PURE__ */ React.createElement(Action, { props }));
		return false;
	}, [props]);
	/**
	* @title: 图片区域
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-09-11 18:11
	*/
	const coverCom = useMemo(() => {
		if (isCover && displayMode !== "display_a1") return /* @__PURE__ */ React.createElement(Cover, { props });
		return null;
	}, [
		isCover,
		displayMode,
		props
	]);
	/**
	* @title: 展开收起
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-09-12 13:38
	*/
	const isShowMoreBtn = useMemo(() => {
		var _dataSource$sortKeys, _dataSource$sortKeys2;
		if ((dataSource === null || dataSource === void 0 || (_dataSource$sortKeys = dataSource.sortKeys) === null || _dataSource$sortKeys === void 0 ? void 0 : _dataSource$sortKeys.length) && (dataSource === null || dataSource === void 0 || (_dataSource$sortKeys2 = dataSource.sortKeys) === null || _dataSource$sortKeys2 === void 0 ? void 0 : _dataSource$sortKeys2.length) < 4) return false;
		if (displayMode !== "display_a9" || !isFoldable) return false;
		return true;
	}, [
		dataSource === null || dataSource === void 0 || (_dataSource$sortKeys3 = dataSource.sortKeys) === null || _dataSource$sortKeys3 === void 0 ? void 0 : _dataSource$sortKeys3.length,
		displayMode,
		isFoldable
	]);
	/**
	* @title: 格式化排序key
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-09-12 16:06
	*/
	const formatSortKeys = useMemo(() => {
		const sortKeys = (dataSource === null || dataSource === void 0 ? void 0 : dataSource.sortKeys) || [];
		if (displayMode === "display_a1") {
			const a1SortKeys = ["title", "price"];
			return sortKeys.filter((key) => a1SortKeys.includes(key));
		}
		if (displayMode === "display_a2") return sortKeys.slice(0, 3);
		if (displayMode === "display_a5") return sortKeys.slice(0, 5);
		if (isShowMoreBtn) return isFold ? sortKeys.slice(0, 4) : sortKeys;
		return sortKeys;
	}, [
		dataSource === null || dataSource === void 0 ? void 0 : dataSource.sortKeys,
		isShowMoreBtn,
		displayMode,
		isFold
	]);
	/**
	* @title: 内容区域
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-09-11 18:11
	*/
	const contentCom = useMemo(() => {
		if (slot) return slot;
		return /* @__PURE__ */ React.createElement("div", {
			className: `${PREFIX}__card-right-content ${className}-content `,
			style: contentStyle
		}, renderComponents(_objectSpread2(_objectSpread2({}, props), {}, { sortKeys: formatSortKeys })), /* @__PURE__ */ React.createElement(WarningLists, { lists: dataSource === null || dataSource === void 0 ? void 0 : dataSource.warning_lists }), isShowMoreBtn ? /* @__PURE__ */ React.createElement(CardMoreText, _objectSpread2(_objectSpread2({}, props), {}, {
			onChange: setIsFold,
			isFold
		})) : null);
	}, [
		slot,
		contentStyle,
		className,
		props,
		formatSortKeys,
		isShowMoreBtn,
		isFold
	]);
	/**
	* @title: 卡片插槽
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-09-12 16:49
	*/
	const cardSlot = useMemo(() => {
		if (skuCardConfig === null || skuCardConfig === void 0 ? void 0 : skuCardConfig.slot) return skuCardConfig === null || skuCardConfig === void 0 ? void 0 : skuCardConfig.slot;
		if (displayMode === "display_custom") return {
			type: "JSSlot",
			value: []
		};
		return null;
	}, [skuCardConfig === null || skuCardConfig === void 0 ? void 0 : skuCardConfig.slot, displayMode]);
	return /* @__PURE__ */ React.createElement(CardWrapper, props, /* @__PURE__ */ React.createElement("div", { className: `${PREFIX}__card ${PREFIX}__card-${layoutDirection} ${className}` }, cardSlot ? cardSlot : /* @__PURE__ */ React.createElement(React.Fragment, null, coverCom, /* @__PURE__ */ React.createElement("div", { className: `${PREFIX}__card-right` }, contentCom, actionCom("row")), actionCom("column"))));
};
//#endregion
export { CardCom as default };
