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 { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import { request } from "../../utils/index.js";
import dayjs from "dayjs";
//#region src/plus/orderList/serve.ts
const _excluded = [
	"pageNumber",
	"pageSize",
	"orderDate",
	"total_amount",
	"sort_key"
];
/**
* 格式化订单列表请求参数
* @param params - 原始请求参数
* @returns 格式化后的请求参数
*/
const formatParams = (params) => {
	const { pageNumber, pageSize, orderDate, total_amount, sort_key } = params, rest = _objectWithoutProperties(params, _excluded);
	let order_by, sort;
	if (sort_key) {
		const [orderByValue, sortValue] = sort_key.split(":");
		order_by = orderByValue;
		sort = sortValue;
	}
	return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, rest), {}, {
		skip: pageNumber || 1,
		num: pageSize || 10
	}, (orderDate === null || orderDate === void 0 ? void 0 : orderDate[0]) && { start_time: dayjs(orderDate[0]).format("YYYY-MM-DD") }), (orderDate === null || orderDate === void 0 ? void 0 : orderDate[1]) && { end_time: dayjs(orderDate[1]).format("YYYY-MM-DD") }), (total_amount === null || total_amount === void 0 ? void 0 : total_amount.min) !== void 0 && { min_total_amount: total_amount.min }), (total_amount === null || total_amount === void 0 ? void 0 : total_amount.max) !== void 0 && { max_total_amount: total_amount.max }), order_by && { order_by }), sort && { sort }), {}, { with: [
		"customer",
		"contactsInfo",
		"tag",
		"createAccount",
		"paidPayment",
		"lastEditAccount"
	] });
};
const listApi = function() {
	var _ref = _asyncToGenerator(function* (params) {
		const res = yield request.getRequest().post(`/shop/order/v2/list`, formatParams(params), {
			abort: true,
			fullResult: true,
			isShopApi: true
		});
		return res === null || res === void 0 ? void 0 : res.data;
	});
	return function listApi(_x) {
		return _ref.apply(this, arguments);
	};
}();
const getCustomerSelectOptions = function() {
	var _ref2 = _asyncToGenerator(function* (params) {
		var _res$data;
		const res = yield request.getRequest().get(`/shop/customer`, {
			search: params,
			skip: 1,
			num: 100
		}, {
			abort: true,
			fullResult: true,
			isShopApi: true
		});
		return (res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.list) || [];
	});
	return function getCustomerSelectOptions(_x2) {
		return _ref2.apply(this, arguments);
	};
}();
const getTagSelectOptions = function() {
	var _ref3 = _asyncToGenerator(function* (params) {
		var _res$data2;
		const res = yield request.getRequest().get(`/shop/order/tag`, {
			name: params,
			skip: 1,
			num: 100
		}, {
			abort: true,
			fullResult: true,
			isShopApi: true
		});
		return (res === null || res === void 0 || (_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : _res$data2.list) || [];
	});
	return function getTagSelectOptions(_x3) {
		return _ref3.apply(this, arguments);
	};
}();
const getChannelSelectOptions = function() {
	var _ref4 = _asyncToGenerator(function* (params) {
		const res = yield request.getRequest().get(`/shop/product/channel`, {}, {
			abort: true,
			fullResult: true,
			isShopApi: true
		});
		return res === null || res === void 0 ? void 0 : res.data;
	});
	return function getChannelSelectOptions(_x4) {
		return _ref4.apply(this, arguments);
	};
}();
const getPaymentSelectOptions = function() {
	var _ref5 = _asyncToGenerator(function* (params) {
		const res = yield request.getRequest().get(`/shop/pay/custom-payment/shop`, {}, {
			abort: true,
			fullResult: true,
			isShopApi: true
		});
		return res === null || res === void 0 ? void 0 : res.data;
	});
	return function getPaymentSelectOptions(_x5) {
		return _ref5.apply(this, arguments);
	};
}();
const getLogisticsSelectOptions = function() {
	var _ref6 = _asyncToGenerator(function* (params) {
		const res = yield request.getRequest().get(`/shop/order/logistics-company`, {}, {
			abort: true,
			fullResult: true,
			isShopApi: true
		});
		return res === null || res === void 0 ? void 0 : res.data;
	});
	return function getLogisticsSelectOptions(_x6) {
		return _ref6.apply(this, arguments);
	};
}();
const getLocationSelectOptions = function() {
	var _ref7 = _asyncToGenerator(function* (params) {
		const res = yield request.getRequest().get(`/shop/shop/location`, {}, {
			abort: true,
			fullResult: true,
			isShopApi: true
		});
		return res === null || res === void 0 ? void 0 : res.data;
	});
	return function getLocationSelectOptions(_x7) {
		return _ref7.apply(this, arguments);
	};
}();
const channelModules = (biz) => {
	return {};
};
const editordership = (params) => {
	return request.getRequest().post("/shop/order/order/shipments", _objectSpread2(_objectSpread2({}, params), channelModules()), { isShopApi: true });
};
const postSendInvoice = (params) => {
	return request.getRequest().post("/shop/order/send-order-invoice", _objectSpread2(_objectSpread2({}, params), channelModules()), { isShopApi: true });
};
const openUrl = (host, url, shopId, ids) => {
	let str = (ids || []).reduce((str, item) => str + "&order_ids[]=" + item, "");
	try {
		var _app;
		const _host = host || ((_app = app) === null || _app === void 0 ? void 0 : _app.request.getConfig().getUrl({
			url: "",
			config: { isShopApi: true }
		}));
		const previewPrefix = "/shop";
		const prefix = _host.indexOf(previewPrefix) !== -1 ? "" : previewPrefix;
		window.open(`${_host}${prefix}${url}?shop_id=${shopId}${str}`);
	} catch (err) {}
};
const printPack = (params) => {
	return openUrl("", "/order/print/packing", params.shop_id, params.ids);
};
const printPicking = (params) => {
	return openUrl("", "/order/print/picking", params.shop_id, params.ids);
};
const batchAddOrderTags = (params) => {
	return request.getRequest().post("/shop/order/order/tag", _objectSpread2({ status: "attach" }, params), { isShopApi: true });
};
const batchDeleteOrderTags = (params) => {
	return request.getRequest().post("/shop/order/order/tag", _objectSpread2({ status: "detach" }, params), { isShopApi: true });
};
const batchPutOrderStatus = (params) => request.getRequest().put("/shop/order/update-status", _objectSpread2({
	order_ids: params.order_ids,
	status: params.status,
	is_void: params.is_void
}, channelModules()), { isShopApi: true });
//#endregion
export { batchAddOrderTags, batchDeleteOrderTags, batchPutOrderStatus, editordership, getChannelSelectOptions, getCustomerSelectOptions, getLocationSelectOptions, getLogisticsSelectOptions, getPaymentSelectOptions, getTagSelectOptions, listApi, postSendInvoice, printPack, printPicking };
