const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../../../pro/PersistentBottomSheet/index.js");
const require_index$1 = require("../../components/AmountDetails/index.js");
const require_index$2 = require("../../components/CartActions/index.js");
const require_index$3 = require("../../components/CartItems/index.js");
const require_index$4 = require("../../components/Client/index.js");
const require_index$5 = require("../../components/Contact/index.js");
const require_index$6 = require("../../components/SaleQrButton/index.js");
const require_index$7 = require("../../hooks/saleDetailActions/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./index.less");
//#region src/plus/saleDetail/tmpl/A/index.tsx
function SaleDetailTemplateAMain({ dataSource, moduleConfig }) {
	var _dataSource$cart3, _dataSource$cart4, _dataSource$sales$tem;
	const hiddenModules = (moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.hidden) || [];
	const showCustomer = !hiddenModules.includes("customer");
	const showContact = !hiddenModules.includes("contact");
	const showCartItems = !hiddenModules.includes("cartItems");
	const showCartActions = !hiddenModules.includes("cartActions");
	const hasCartItems = (0, react.useMemo)(() => {
		var _dataSource$cart, _dataSource$cart2;
		return Boolean((_dataSource$cart = dataSource.cart) === null || _dataSource$cart === void 0 || (_dataSource$cart = _dataSource$cart.bookings) === null || _dataSource$cart === void 0 ? void 0 : _dataSource$cart.length) || Boolean((_dataSource$cart2 = dataSource.cart) === null || _dataSource$cart2 === void 0 || (_dataSource$cart2 = _dataSource$cart2.items) === null || _dataSource$cart2 === void 0 ? void 0 : _dataSource$cart2.length);
	}, [(_dataSource$cart3 = dataSource.cart) === null || _dataSource$cart3 === void 0 || (_dataSource$cart3 = _dataSource$cart3.bookings) === null || _dataSource$cart3 === void 0 ? void 0 : _dataSource$cart3.length, (_dataSource$cart4 = dataSource.cart) === null || _dataSource$cart4 === void 0 || (_dataSource$cart4 = _dataSource$cart4.items) === null || _dataSource$cart4 === void 0 ? void 0 : _dataSource$cart4.length]);
	return /* @__PURE__ */ react.default.createElement("main", { className: "pisell-sale-detail-main" }, showCustomer ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-client-entry" }, /* @__PURE__ */ react.default.createElement(require_index$4.Client, {
		dataSource: {
			customer: dataSource.customer,
			sales: dataSource.sales
		},
		isShowAvatar: true
	}), /* @__PURE__ */ react.default.createElement(require_index$6.SaleQrButton, { onClick: () => dataSource.sales.activateCamera() })) : null, showContact ? /* @__PURE__ */ react.default.createElement(require_index$5.Contact, {
		dataSource: (_dataSource$sales$tem = dataSource.sales.tempOrder) === null || _dataSource$sales$tem === void 0 ? void 0 : _dataSource$sales$tem.contacts_info,
		sales: dataSource.sales,
		showAction: true,
		showEmpty: true
	}) : null, showCartItems ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-scroll-content" }, /* @__PURE__ */ react.default.createElement(require_index$3.CartItems, {
		dataSource: dataSource.cart,
		sales: dataSource.sales,
		showEmpty: true
	})) : null, showCartActions ? /* @__PURE__ */ react.default.createElement(require_index$2.CartActions, {
		dataSource: {
			cart: dataSource.cart,
			sales: dataSource.sales,
			summary: dataSource.summary
		},
		hasCartItems
	}) : null);
}
function SaleDetailTemplateA({ dataSource, mobilePresentation, moduleConfig, renderType, variant }) {
	var _moduleConfig$amountD;
	const [mobileSheetOpen, setMobileSheetOpen] = (0, react.useState)(false);
	const hiddenModules = (moduleConfig === null || moduleConfig === void 0 ? void 0 : moduleConfig.hidden) || [];
	const showAmountDetails = !hiddenModules.includes("amountDetails");
	const showOrderActions = !hiddenModules.includes("orderActions");
	const isMobileBottomSheet = variant === "phone" && renderType === "current" && mobilePresentation === "bottomSheet";
	const actionButtonGroupList = require_index$7.useSaleDetailActions({
		dataSource,
		actions: [
			{
				name: "note",
				row: 1,
				order: 10
			},
			{
				name: "save",
				row: 1,
				order: 20,
				buttonProps: { icon: null }
			},
			{
				name: "checkout",
				row: 1,
				order: 30,
				hidden: false,
				buttonProps: { icon: null }
			}
		]
	});
	const actionOverlays = actionButtonGroupList.flat().map((item) => item.renderAfter).filter(Boolean);
	const showFooter = showAmountDetails || showOrderActions && actionButtonGroupList.length;
	const bodyContent = /* @__PURE__ */ react.default.createElement("main", { className: "pisell-sale-detail-tmpl-body" }, /* @__PURE__ */ react.default.createElement("section", { className: "pisell-sale-detail-tmpl-content" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-inline-layout" }, /* @__PURE__ */ react.default.createElement(SaleDetailTemplateAMain, {
		dataSource,
		moduleConfig
	}))));
	const footerContent = showFooter ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-footer" }, showAmountDetails ? /* @__PURE__ */ react.default.createElement(require_index$1.AmountDetails, {
		defaultExpanded: moduleConfig === null || moduleConfig === void 0 || (_moduleConfig$amountD = moduleConfig.amountDetails) === null || _moduleConfig$amountD === void 0 ? void 0 : _moduleConfig$amountD.defaultExpanded,
		dataSource: {
			sales: dataSource.sales,
			summary: dataSource.summary
		}
	}) : null, showOrderActions && actionButtonGroupList.length ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-button-actions pisell-sale-detail-button-actions--template-a" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.ButtonGroupPreview, { buttonGroupList: actionButtonGroupList }), actionOverlays) : null) : null;
	if (isMobileBottomSheet) return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-tmpl-a pisell-sale-detail-tmpl-a--mobile-sheet" }, /* @__PURE__ */ react.default.createElement(require_index.default, {
		open: mobileSheetOpen,
		onOpenChange: setMobileSheetOpen,
		maxHeight: "95dvh",
		mask: true,
		maskClosable: true,
		destroyOnHidden: false,
		className: (0, classnames.default)("pisell-sale-detail-mobile-sheet", { "pisell-sale-detail-mobile-sheet--open": mobileSheetOpen }),
		header: /* @__PURE__ */ react.default.createElement("button", {
			type: "button",
			className: (0, classnames.default)("pisell-sale-detail-mobile-sheet__handler", { "pisell-sale-detail-mobile-sheet__handler--open": mobileSheetOpen }),
			"aria-expanded": mobileSheetOpen,
			onClick: () => setMobileSheetOpen((open) => !open)
		}, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-sale-detail-mobile-sheet__handler-icon" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-chevron-down-double" }))),
		classNames: {
			body: (0, classnames.default)("pisell-sale-detail-mobile-sheet__body", { "pisell-sale-detail-mobile-sheet__body--open": mobileSheetOpen }),
			footer: "pisell-sale-detail-mobile-sheet__footer pisell-sale-detail-mobile-sheet__footer--safe-area"
		},
		footer: footerContent,
		zIndex: 100
	}, bodyContent));
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-tmpl-a" }, /* @__PURE__ */ react.default.createElement("main", { className: "pisell-sale-detail-tmpl-body" }, /* @__PURE__ */ react.default.createElement("section", { className: "pisell-sale-detail-tmpl-content" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-inline-layout" }, /* @__PURE__ */ react.default.createElement(SaleDetailTemplateAMain, {
		dataSource,
		moduleConfig
	}), footerContent))));
}
//#endregion
exports.SaleDetailTemplateA = SaleDetailTemplateA;
