import { getText } from "../../../../../../../locales/index.js";
import { _objectSpread2 } from "../../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _asyncToGenerator } from "../../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import { exportData } from "../../../../../serve.js";
import { defaultOptions } from "../../../../../status.js";
import { getFileDateName } from "../../utils/file.js";
import { message } from "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 = _asyncToGenerator(function* (params) {
		let { status } = yield exportData(params);
		if (status) {
			message.success({
				content: getText("table-action-export-import-export-success"),
				key: defaultOptions.exportValue
			});
			return true;
		} else message.destroy();
	});
	return function _batchExport(_x) {
		return _ref.apply(this, arguments);
	};
}();
const batchExport = (exportParams, exportImport) => {
	const { selectLists, apiUrl, otherParams } = exportImport;
	let _name = getFileDateName();
	let params = (otherParams === null || otherParams === void 0 ? void 0 : otherParams.export) ? _objectSpread2({}, otherParams === null || otherParams === void 0 ? void 0 : otherParams.export) : _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) || defaultOptions.exportType;
	if (type === defaultOptions.exportType) {
		_name = `${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 = `${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 = `${getText("table-action-export-import-selected-records")}(${getText("table-action-export-import-selected")} ${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
export { batchExport };
