require("../../../../../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../../../../../../locales/index.js");
const require_objectSpread2 = require("../../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_serve = require("../../../../../serve.js");
const require_status = require("../../../../../status.js");
const require_file = require("../../utils/file.js");
let antd = require("antd");
//#region src/components/table/Actions/component/ExportImport/components/ExportTable/function.ts
const exportImportTypeMap = {
	"current-page": "page",
	"all-records": "all",
	"selected-records": "select"
};
const _batchExport = function() {
	var _ref = require_asyncToGenerator._asyncToGenerator(function* (params) {
		let { status } = yield require_serve.exportData(params);
		if (status) {
			antd.message.success({
				content: require_index.getText("table-action-export-import-export-success"),
				key: require_status.defaultOptions.exportValue
			});
			return true;
		} else antd.message.destroy();
	});
	return function _batchExport(_x) {
		return _ref.apply(this, arguments);
	};
}();
const batchExport = (exportParams, exportImport) => {
	const { selectLists, apiUrl, otherParams } = exportImport;
	let _name = require_file.getFileDateName();
	let params = (otherParams === null || otherParams === void 0 ? void 0 : otherParams.export) ? require_objectSpread2._objectSpread2({}, otherParams === null || otherParams === void 0 ? void 0 : otherParams.export) : require_objectSpread2._objectSpread2({}, otherParams);
	params.url = apiUrl === null || apiUrl === void 0 ? void 0 : apiUrl.export;
	console.log("exportParams", exportParams);
	const type = (exportParams === null || exportParams === void 0 ? void 0 : exportParams.type) || require_status.defaultOptions.exportType;
	if (type === require_status.defaultOptions.exportType) {
		_name = `${require_index.getText("table-action-export-import-current-page")}${_name}`;
		params.ids = ((exportParams === null || exportParams === void 0 ? void 0 : exportParams.currentDataSource) || []).map((item) => (item === null || item === void 0 ? void 0 : item.id) || (item === null || item === void 0 ? void 0 : item.form_record_id));
		params.file_name = _name;
	}
	if (type === "all-records") {
		_name = `${require_index.getText("table-action-export-import-all-records")}${_name}`;
		if ((otherParams === null || otherParams === void 0 ? void 0 : otherParams.form_id) || (otherParams === null || otherParams === void 0 ? void 0 : otherParams.code)) params.ids = ((exportParams === null || exportParams === void 0 ? void 0 : exportParams.originDataSource) || []).map((item) => (item === null || item === void 0 ? void 0 : item.id) || (item === null || item === void 0 ? void 0 : item.form_record_id));
		params.file_name = _name;
	}
	if (type === "selected-records") {
		_name = `${require_index.getText("table-action-export-import-selected-records")}(${require_index.getText("table-action-export-import-selected")} ${require_index.getText("table-action-export-import-item")(selectLists === null || selectLists === void 0 ? void 0 : selectLists.length)}) ${_name}`;
		params.ids = selectLists || [];
		params.file_name = _name;
	}
	if (type !== "all-records") {
		params === null || params === void 0 || delete params.shipping_status;
		params === null || params === void 0 || delete params.payment_status;
		params === null || params === void 0 || delete params.status;
	} else params === null || params === void 0 || delete params.ids;
	params.export_select = exportImportTypeMap[type];
	return _batchExport(params);
};
//#endregion
exports.batchExport = batchExport;
