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 IconFont from "../../iconfont/index.js";
import useEngineContext from "../../../hooks/useEngineContext.js";
import Action from "../components/Action/index.js";
import { defaultValue } from "../status.js";
import locales_default from "./locales.js";
import BasicInfo from "./components/basicInfo/index.js";
import DiscountReason from "./components/discountReason/index.js";
import TimeRange from "./components/timeRange/index.js";
import Resources from "./components/resources/index.js";
import Packages from "./components/packages/index.js";
import Sales from "./components/sales/index.js";
import { SwipeAction } from "./components/swipeAction/index.js";
import Note from "./components/Note/index.js";
import Footer from "./components/AmountFooter/index.js";
import MultiDay from "./components/MultiDay/index.js";
import React, { useMemo, useRef } from "react";
import { locales } from "@pisell/utils";
import classNames from "classnames";
import "./index.less";
//#region src/components/productCard/cartSkuCard/index.tsx
const _excluded = [
	"dataSource",
	"isShowImage",
	"isShowHolder",
	"isShowNote",
	"isShowDelete",
	"isShowAmountFooter",
	"isShowPackageNote",
	"isShowEditProduct",
	"onEditProduct",
	"onAction",
	"onDelete",
	"onNote",
	"onLike",
	"onCard",
	"onChangeResource",
	"onChangeHolder",
	"type",
	"rightActions",
	"escapeDom"
];
const PREFIX = "pisell-cart-sku-card";
const CartSkuCard = (props) => {
	var _context$appHelper$ut;
	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, onEditProduct, onAction, onDelete, onNote, onLike, onCard, onChangeResource, onChangeHolder, type, rightActions = [], escapeDom } = props, other = _objectWithoutProperties(props, _excluded);
	const useOpenNoteRef = useRef();
	const context = useEngineContext();
	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");
	console.log("prodcut props", props);
	const { isShowAction, actionText } = dataSource;
	const _rightActions = useMemo(() => {
		const deleteAction = {
			key: "delete",
			text: /* @__PURE__ */ React.createElement("div", { style: {
				display: "flex",
				justifyContent: "center",
				alignItems: "center",
				color: "white",
				cursor: "pointer",
				padding: "10px 0px"
			} }, /* @__PURE__ */ React.createElement(IconFont, {
				type: "pisell2-trash-01",
				style: {
					fontSize: 20,
					marginRight: 4
				}
			}), /* @__PURE__ */ React.createElement("span", { style: {
				fontSize: 12,
				fontWeight: 500
			} }, locales.getText("pisell2.cart.sku-card.actions.delete"))),
			color: "danger",
			onClick: (e) => {
				e.preventDefault();
				e.stopPropagation();
				onDelete === null || onDelete === void 0 || onDelete(dataSource);
			}
		};
		const actions = [...rightActions];
		if (isShowDelete) actions.unshift(deleteAction);
		return actions;
	}, [
		dataSource,
		onDelete,
		isShowDelete,
		rightActions
	]);
	const hideDivider = useMemo(() => {
		return false;
	}, [dataSource]);
	const renderA2 = () => {
		return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BasicInfo, {
			isShowImage,
			dataSource,
			isMainProduct: true
		}), /* @__PURE__ */ React.createElement(DiscountReason, { dataSource }), isShowNote ? /* @__PURE__ */ React.createElement(Note, _objectSpread2(_objectSpread2({}, other), {}, {
			item: dataSource,
			openNote: () => {
				useOpenNoteRef.current.open({ item: dataSource });
			}
		})) : null);
	};
	const renderA5 = () => {
		var _dataSource$bundle, _dataSource$items;
		return /* @__PURE__ */ React.createElement(React.Fragment, null, isShowDelete ? /* @__PURE__ */ React.createElement("div", {
			className: `${PREFIX}__delete-btn`,
			onClick: (e) => {
				e.preventDefault();
				e.stopPropagation();
				onDelete === null || onDelete === void 0 || onDelete(dataSource);
			}
		}, /* @__PURE__ */ React.createElement(IconFont, { type: "pisell2-trash-01" })) : null, /* @__PURE__ */ React.createElement(BasicInfo, {
			isShowImage,
			dataSource,
			isMainProduct: true,
			type
		}), /* @__PURE__ */ React.createElement(TimeRange, { dataSource }), /* @__PURE__ */ React.createElement(Resources, { dataSource }), /* @__PURE__ */ React.createElement(Packages, {
			dataSource,
			isShowImage
		}), /* @__PURE__ */ React.createElement(Sales, {
			dataSource,
			hideDivider: !!(dataSource === null || dataSource === void 0 || (_dataSource$bundle = dataSource.bundle) === null || _dataSource$bundle === void 0 ? void 0 : _dataSource$bundle.length),
			isShowImage
		}), ((_dataSource$items = dataSource.items) === null || _dataSource$items === void 0 ? void 0 : _dataSource$items.length) ? /* @__PURE__ */ React.createElement(MultiDay, {
			dataSource,
			hideDivider
		}) : isShowAmountFooter ? /* @__PURE__ */ React.createElement(Footer, {
			item: dataSource,
			hideDivider,
			type: "total"
		}) : null, 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);
	};
	const renderContent = () => {
		if (type === "a5") return renderA5();
		return renderA2();
	};
	return /* @__PURE__ */ React.createElement(SwipeAction, {
		closeOnAction: false,
		className: classNames(`${PREFIX}-wrapper`),
		rightActions: _rightActions,
		escapeDom
	}, /* @__PURE__ */ React.createElement("div", {
		className: classNames(PREFIX, `${PREFIX}--${type}`),
		onClick: (e) => {
			e.preventDefault();
			e.stopPropagation();
			onCard === null || onCard === void 0 || onCard(dataSource);
		}
	}, renderContent()));
};
//#endregion
export { PREFIX, CartSkuCard as default };
