const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_index = require("../../components/AmountDetails/index.js");
const require_index$1 = require("../../components/CartItems/index.js");
const require_index$2 = require("../../components/Client/index.js");
const require_index$3 = require("../../components/Contact/index.js");
const require_index$4 = require("../../components/OrderNote/index.js");
const require_index$5 = require("../../components/SaleOverview/index.js");
const require_serve = require("../../serve.js");
const require_useSaleDetailActions = require("../../hooks/useSaleDetailActions.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_materials = require("@pisell/materials");
require("./index.less");
//#region src/plus/saleDetail/tmpl/A/index.tsx
function SaleDetailTemplateAMain({ dataSource }) {
	var _dataSource$sales$tem, _dataSource$sales$tem2;
	return /* @__PURE__ */ react.default.createElement("main", { className: "pisell-sale-detail-main" }, /* @__PURE__ */ react.default.createElement(require_index$2.Client, { dataSource: dataSource.customer.selected }), ((_dataSource$sales$tem = dataSource.sales.tempOrder) === null || _dataSource$sales$tem === void 0 ? void 0 : _dataSource$sales$tem.note) ? /* @__PURE__ */ react.default.createElement(require_index$4.OrderNote, { dataSource: dataSource.sales.tempOrder.note }) : null, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-scroll-content" }, /* @__PURE__ */ react.default.createElement(require_index$3.Contact, { dataSource: (_dataSource$sales$tem2 = dataSource.sales.tempOrder) === null || _dataSource$sales$tem2 === void 0 ? void 0 : _dataSource$sales$tem2.contacts_info }), /* @__PURE__ */ react.default.createElement(require_index$1.CartItems, {
		dataSource: dataSource.cart,
		sales: dataSource.sales
	})));
}
function SaleDetailTemplateA({ dataSource }) {
	var _dataSource$sales$tem4;
	const [remotePrintActions, setRemotePrintActions] = (0, react.useState)([]);
	const getData = require_useEngineContext.default().appHelper.utils.getData;
	const getRemotePrintActionsData = (0, react.useCallback)(require_asyncToGenerator._asyncToGenerator(function* () {
		var _dataSource$sales$tem3;
		if (!((_dataSource$sales$tem3 = dataSource.sales.tempOrder) === null || _dataSource$sales$tem3 === void 0 ? void 0 : _dataSource$sales$tem3.order_id)) {
			setRemotePrintActions([]);
			return;
		}
		try {
			const res = yield require_serve.getRemotePrintActions({ order_id: String(dataSource.sales.tempOrder.order_id) }, { headers: { "Shop-Id": getData("shop_id") } });
			const nextActions = Array.isArray(res) ? res : res === null || res === void 0 ? void 0 : res.machine_code_print_info_v2;
			setRemotePrintActions(Array.isArray(nextActions) ? nextActions : []);
		} catch (error) {
			console.error(error);
		}
	}), [(_dataSource$sales$tem4 = dataSource.sales.tempOrder) === null || _dataSource$sales$tem4 === void 0 ? void 0 : _dataSource$sales$tem4.order_id, getData]);
	(0, react.useEffect)(() => {
		getRemotePrintActionsData();
	}, [getRemotePrintActionsData]);
	const actionButtonGroupList = require_useSaleDetailActions.useSaleDetailActions({
		dataSource,
		actions: [
			{
				name: "edit",
				row: 1,
				order: 10
			},
			{
				name: "print",
				row: 1,
				order: 20,
				items: ["print-wristband", "print-receipts"]
			},
			{
				name: "cancel",
				row: 1,
				order: 30
			},
			{
				name: "return",
				row: 2,
				order: 10
			},
			{
				name: "refund",
				row: 2,
				order: 20
			},
			{
				name: "checkout",
				row: 2,
				order: 30
			}
		],
		machineCodePrintActions: remotePrintActions,
		getRemotePrintActionsData
	});
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-tmpl-a" }, /* @__PURE__ */ react.default.createElement(require_index$5.SaleOverview, {
		className: "pisell-sale-detail-tmpl-overview",
		dataSource
	}), /* @__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 }), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-footer" }, /* @__PURE__ */ react.default.createElement(require_index.AmountDetails, { dataSource: {
		sales: dataSource.sales,
		summary: dataSource.summary
	} }), actionButtonGroupList.length ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-button-actions" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.ButtonGroupPreview, { buttonGroupList: actionButtonGroupList })) : null)))));
}
//#endregion
exports.SaleDetailTemplateA = SaleDetailTemplateA;
