import Options from "../Packages/components/options/index.js";
import DeleteButton from "./DeleteButton/index.js";
import EditButton from "./EditButton/index.js";
import React, { useMemo } from "react";
import { formatAmount, image } from "@pisell/utils";
import classNames from "classnames";
import "./index.less";
//#region src/components/productCard/components/Header/index.tsx
const prefix = "pisell-lowcode-";
const Header = (props) => {
	const { isShowDelete, item, isShowImage, onDelete, disabledEdit, onEditProduct, isShowEditProduct } = props;
	const { id, options, bundle, product_option_string, image: image$1, name, price, symbol, disabled, relation_products, num = 1 } = item;
	/**
	* @title: 是否显示价格
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-23 16:13
	*/
	const showPrice = useMemo(() => {
		return (bundle === null || bundle === void 0 ? void 0 : bundle.length) > 0 || (options === null || options === void 0 ? void 0 : options.length) > 0 || ((relation_products === null || relation_products === void 0 ? void 0 : relation_products.length) || 0) > 0;
	}, [
		bundle,
		options,
		relation_products
	]);
	/**
	* @title: 样式是否居中
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-11-23 17:37
	*/
	const headerCenterStyle = useMemo(() => {
		return (options === null || options === void 0 ? void 0 : options.length) > 0 || product_option_string;
	}, [options, product_option_string]);
	/**
	* @title: 是否显示删除按钮
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-06-11 15:14
	*/
	const showDelete = useMemo(() => {
		return isShowDelete && !disabledEdit && !disabled;
	}, [
		isShowDelete,
		disabledEdit,
		disabled
	]);
	const renderImage = () => {
		if (!isShowImage) return null;
		if (image$1) return /* @__PURE__ */ React.createElement("img", {
			src: image.ali(image$1, 64),
			className: `${prefix}product-header-cover`
		});
		const displayText = name ? name.slice(0, 2) : "";
		return /* @__PURE__ */ React.createElement("div", { className: `${prefix}product-header-cover-text` }, displayText);
	};
	return /* @__PURE__ */ React.createElement("div", { className: classNames(`${prefix}product-header`, headerCenterStyle && `${prefix}product-options-header`) }, showDelete ? /* @__PURE__ */ React.createElement(DeleteButton, { onDelete }) : null, renderImage(), id ? /* @__PURE__ */ React.createElement("div", { className: classNames(`${prefix}product-right-wrap`, { [`${prefix}product-right-wrap-stretch`]: isShowEditProduct }) }, /* @__PURE__ */ React.createElement("div", { className: `${prefix}product-title` }, /* @__PURE__ */ React.createElement("span", { style: { paddingRight: showDelete ? "18px" : "0" } }, name), showPrice ? /* @__PURE__ */ React.createElement("span", { className: `${prefix}product-title-price` }, formatAmount(price, 2, symbol)) : null), product_option_string ? /* @__PURE__ */ React.createElement("span", { className: `${prefix}product-title-variant` }, product_option_string) : null, /* @__PURE__ */ React.createElement(Options, {
		options,
		amountSymbol: symbol
	}), isShowEditProduct && !disabledEdit && !disabled ? /* @__PURE__ */ React.createElement(EditButton, { onEdit: onEditProduct }) : null) : null);
};
//#endregion
export { Header as default };
