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 useEngineContext from "../../hooks/useEngineContext.js";
import cardPro_default from "../cardPro/index.js";
import DeleteButton from "./components/Header/DeleteButton/index.js";
import Header from "./components/Header/index.js";
import Time from "./components/Time/index.js";
import Footer from "./components/AmountFooter/index.js";
import Note from "./components/Note/index.js";
import Packages from "./components/Packages/index.js";
import Sales from "./components/Sales/index.js";
import MultiDay from "./components/MultiDay/index.js";
import Action from "./components/Action/index.js";
import useOpenNote_default from "./hooks/useOpenNote.js";
import locales_default from "./locales.js";
import { defaultValue } from "./status.js";
import Warning from "./components/Warning/index.js";
import CartSkuCard from "./cartSkuCard/index.js";
import React, { useMemo, useRef } from "react";
import { locales } from "@pisell/utils";
import classNames from "classnames";
import "./index.less";
//#region src/components/productCard/index.tsx
const _excluded = [
	"dataSource",
	"isShowImage",
	"isShowHolder",
	"isShowNote",
	"isShowDelete",
	"isShowAmountFooter",
	"isShowPackageNote",
	"isShowEditProduct",
	"scenario",
	"onEditProduct",
	"onAction",
	"onDelete",
	"onNote",
	"onLike",
	"onCard",
	"onChangeResource",
	"onChangeHolder"
];
const ProductCard = (props) => {
	var _utils$storage, _dataSource$items;
	const utils = useEngineContext().appHelper.utils || {};
	const { dataSource = defaultValue.dataSource, isShowImage = defaultValue.isShowImage, isShowHolder = defaultValue.isShowHolder, isShowNote = defaultValue.isShowNote, isShowDelete = defaultValue.isShowDelete, isShowAmountFooter = defaultValue.isShowAmountFooter, isShowPackageNote = defaultValue.isShowPackageNote, isShowEditProduct = defaultValue.isShowEditProduct, scenario, onEditProduct, onAction, onDelete, onNote, onLike, onCard, onChangeResource, onChangeHolder } = props, other = _objectWithoutProperties(props, _excluded);
	const useOpenNoteRef = useRef();
	const locale = (utils === null || utils === void 0 || (_utils$storage = utils.storage) === null || _utils$storage === void 0 ? void 0 : _utils$storage.get("umi_locale")) || localStorage.getItem("umi_locale");
	locales.init(locales_default, locale || "en");
	const { image, bundle, relation_products, _id, isShowAction, actionText, errorMessage, isNormalProduct, osWarnTips = [] } = dataSource;
	/**
	* @title: 显示图片
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-21 19:33
	*/
	const showImage = useMemo(() => {
		return isShowImage && image;
	}, [isShowImage, image]);
	/**
	* @title: 是否隐藏footer分割线
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-23 13:30
	*/
	const hideDivider = useMemo(() => {
		return (bundle === null || bundle === void 0 ? void 0 : bundle.length) || (relation_products === null || relation_products === void 0 ? void 0 : relation_products.length);
	}, [bundle, relation_products]);
	return /* @__PURE__ */ React.createElement("div", {
		className: classNames("pisell-lowcode-product-card-wrap", { ["pisell-lowcode-product-card-disabled"]: dataSource === null || dataSource === void 0 ? void 0 : dataSource.disabled }),
		id: dataSource === null || dataSource === void 0 ? void 0 : dataSource.rowKey
	}, (dataSource === null || dataSource === void 0 ? void 0 : dataSource.disabled) && /* @__PURE__ */ React.createElement("div", { className: "delete-btn-wrapper" }, /* @__PURE__ */ React.createElement(DeleteButton, { onDelete: () => onDelete === null || onDelete === void 0 ? void 0 : onDelete(dataSource) })), /* @__PURE__ */ React.createElement(cardPro_default, {
		className: classNames("pisell-lowcode-product-card", {
			["pisell-lowcode-product-card-image"]: !showImage && scenario !== "booking2",
			["pisell-lowcode-normal-product-card"]: !showImage && isNormalProduct && scenario !== "booking2",
			["pisell-lowcode-product-card-image-booking2"]: scenario === "booking2"
		}),
		key: _id
	}, /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { onClick: (e) => {
		e.preventDefault();
		e.stopPropagation();
		onCard === null || onCard === void 0 || onCard(dataSource);
	} }, /* @__PURE__ */ React.createElement(Header, _objectSpread2(_objectSpread2({}, other), {}, {
		item: dataSource,
		isShowImage,
		isShowDelete,
		isShowEditProduct,
		showImage,
		onEditProduct: () => onEditProduct === null || onEditProduct === void 0 ? void 0 : onEditProduct(dataSource),
		onDelete: () => {
			onDelete === null || onDelete === void 0 || onDelete(dataSource);
		}
	})), /* @__PURE__ */ React.createElement(Time, {
		item: dataSource,
		isShowHolder,
		isShowChangeResource: other === null || other === void 0 ? void 0 : other.isShowChangeResource,
		isShowChangeHolder: other === null || other === void 0 ? void 0 : other.isShowChangeHolder,
		holderMode: other === null || other === void 0 ? void 0 : other.holderMode,
		onLike: (item) => onLike === null || onLike === void 0 ? void 0 : onLike(item),
		changeResource: onChangeResource,
		changeHolder: onChangeHolder,
		onAddHolder: other === null || other === void 0 ? void 0 : other.onAddHolder,
		isShowAddHolderButton: other === null || other === void 0 ? void 0 : other.isShowAddHolderButton,
		onClearResource: other === null || other === void 0 ? void 0 : other.onClearResource,
		onClearHolder: other === null || other === void 0 ? void 0 : other.onClearHolder
	}), /* @__PURE__ */ React.createElement(Packages, {
		item: dataSource,
		isShowPackageNote
	}), /* @__PURE__ */ React.createElement(Sales, {
		item: dataSource,
		isShowNote
	}), ((_dataSource$items = dataSource.items) === null || _dataSource$items === void 0 ? void 0 : _dataSource$items.length) ? /* @__PURE__ */ React.createElement(MultiDay, {
		dataSource,
		hideDivider
	}) : /* @__PURE__ */ React.createElement(Footer, {
		item: dataSource,
		hideDivider,
		type: "total"
	}), isShowNote ? /* @__PURE__ */ React.createElement(Note, _objectSpread2(_objectSpread2({}, other), {}, {
		item: dataSource,
		openNote: () => {
			useOpenNoteRef.current.open({ item: dataSource });
		}
	})) : null, isShowAction && actionText ? /* @__PURE__ */ React.createElement(Action, {
		item: dataSource,
		onAction: () => onAction === null || onAction === void 0 ? void 0 : onAction(dataSource)
	}) : null, /* @__PURE__ */ React.createElement(Warning, {
		errorMessage,
		osWarnTips
	})), /* @__PURE__ */ React.createElement(useOpenNote_default, {
		ref: useOpenNoteRef,
		onNoteChange: (e) => {
			onNote === null || onNote === void 0 || onNote(_objectSpread2(_objectSpread2({}, dataSource), {}, { note: e || "" }));
		}
	}))));
};
ProductCard.V2 = CartSkuCard;
//#endregion
export { ProductCard as default };
