import { _asyncToGenerator } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import useEngineContext from "../../../../hooks/useEngineContext.js";
import { AmountDetails } from "../../components/AmountDetails/index.js";
import { CartItems } from "../../components/CartItems/index.js";
import { Client } from "../../components/Client/index.js";
import { Contact } from "../../components/Contact/index.js";
import { OrderNote } from "../../components/OrderNote/index.js";
import { SaleOverview } from "../../components/SaleOverview/index.js";
import { getRemotePrintActions } from "../../serve.js";
import { useSaleDetailActions } from "../../hooks/useSaleDetailActions.js";
import React, { useCallback, useEffect, useState } from "react";
import { ButtonGroupPreview } from "@pisell/materials";
import "./index.less";
//#region src/plus/saleDetail/tmpl/A/index.tsx
function SaleDetailTemplateAMain({ dataSource }) {
	var _dataSource$sales$tem, _dataSource$sales$tem2;
	return /* @__PURE__ */ React.createElement("main", { className: "pisell-sale-detail-main" }, /* @__PURE__ */ React.createElement(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.createElement(OrderNote, { dataSource: dataSource.sales.tempOrder.note }) : null, /* @__PURE__ */ React.createElement("div", { className: "pisell-sale-detail-scroll-content" }, /* @__PURE__ */ React.createElement(Contact, { dataSource: (_dataSource$sales$tem2 = dataSource.sales.tempOrder) === null || _dataSource$sales$tem2 === void 0 ? void 0 : _dataSource$sales$tem2.contacts_info }), /* @__PURE__ */ React.createElement(CartItems, {
		dataSource: dataSource.cart,
		sales: dataSource.sales
	})));
}
function SaleDetailTemplateA({ dataSource }) {
	var _dataSource$sales$tem4;
	const [remotePrintActions, setRemotePrintActions] = useState([]);
	const getData = useEngineContext().appHelper.utils.getData;
	const getRemotePrintActionsData = useCallback(_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 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]);
	useEffect(() => {
		getRemotePrintActionsData();
	}, [getRemotePrintActionsData]);
	const actionButtonGroupList = 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.createElement("div", { className: "pisell-sale-detail-tmpl-a" }, /* @__PURE__ */ React.createElement(SaleOverview, {
		className: "pisell-sale-detail-tmpl-overview",
		dataSource
	}), /* @__PURE__ */ React.createElement("main", { className: "pisell-sale-detail-tmpl-body" }, /* @__PURE__ */ React.createElement("section", { className: "pisell-sale-detail-tmpl-content" }, /* @__PURE__ */ React.createElement("div", { className: "pisell-sale-detail-inline-layout" }, /* @__PURE__ */ React.createElement(SaleDetailTemplateAMain, { dataSource }), /* @__PURE__ */ React.createElement("div", { className: "pisell-sale-detail-footer" }, /* @__PURE__ */ React.createElement(AmountDetails, { dataSource: {
		sales: dataSource.sales,
		summary: dataSource.summary
	} }), actionButtonGroupList.length ? /* @__PURE__ */ React.createElement("div", { className: "pisell-sale-detail-button-actions" }, /* @__PURE__ */ React.createElement(ButtonGroupPreview, { buttonGroupList: actionButtonGroupList })) : null)))));
}
//#endregion
export { SaleDetailTemplateA };
