var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/orderList/serve.ts
var serve_exports = {};
__export(serve_exports, {
  batchAddOrderTags: () => batchAddOrderTags,
  batchDeleteOrderTags: () => batchDeleteOrderTags,
  batchPutOrderStatus: () => batchPutOrderStatus,
  batchVoidedOrder: () => batchVoidedOrder,
  editordership: () => editordership,
  getChannelSelectOptions: () => getChannelSelectOptions,
  getCustomerSelectOptions: () => getCustomerSelectOptions,
  getLocationSelectOptions: () => getLocationSelectOptions,
  getLogisticsSelectOptions: () => getLogisticsSelectOptions,
  getPaymentSelectOptions: () => getPaymentSelectOptions,
  getTagSelectOptions: () => getTagSelectOptions,
  listApi: () => listApi,
  openUrl: () => openUrl,
  postSendInvoice: () => postSendInvoice,
  printPack: () => printPack,
  printPicking: () => printPicking
});
module.exports = __toCommonJS(serve_exports);
var import_utils = require("../../utils");
var import_dayjs = __toESM(require("dayjs"));
var formatParams = (params) => {
  const { pageNumber, pageSize, orderDate, total_amount, sort_key, ...rest } = params;
  let order_by, sort;
  if (sort_key) {
    const [orderByValue, sortValue] = sort_key.split(":");
    order_by = orderByValue;
    sort = sortValue;
  }
  return {
    ...rest,
    skip: pageNumber || 1,
    num: pageSize || 10,
    ...(orderDate == null ? void 0 : orderDate[0]) && { start_time: (0, import_dayjs.default)(orderDate[0]).format("YYYY-MM-DD") },
    ...(orderDate == null ? void 0 : orderDate[1]) && { end_time: (0, import_dayjs.default)(orderDate[1]).format("YYYY-MM-DD") },
    ...(total_amount == null ? void 0 : total_amount.min) !== void 0 && { min_total_amount: total_amount.min },
    ...(total_amount == null ? 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"
    ]
  };
};
var listApi = async (params) => {
  const res = await import_utils.request.getRequest().post(`/shop/order/v2/list`, formatParams(params), { abort: true, fullResult: true, isShopApi: true });
  return res == null ? void 0 : res.data;
};
var getCustomerSelectOptions = async (params) => {
  var _a;
  const res = await import_utils.request.getRequest().get(`/shop/customer`, { search: params, skip: 1, num: 100 }, { abort: true, fullResult: true, isShopApi: true });
  return ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) || [];
};
var getTagSelectOptions = async (params) => {
  var _a;
  const res = await import_utils.request.getRequest().get(`/shop/order/tag`, { name: params, skip: 1, num: 100 }, { abort: true, fullResult: true, isShopApi: true });
  return ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) || [];
};
var getChannelSelectOptions = async (params) => {
  const res = await import_utils.request.getRequest().get(`/shop/product/channel`, {}, { abort: true, fullResult: true, isShopApi: true });
  return res == null ? void 0 : res.data;
};
var getPaymentSelectOptions = async (params) => {
  const res = await import_utils.request.getRequest().get(`/shop/pay/custom-payment/shop`, {}, { abort: true, fullResult: true, isShopApi: true });
  return res == null ? void 0 : res.data;
};
var getLogisticsSelectOptions = async (params) => {
  const res = await import_utils.request.getRequest().get(`/shop/order/logistics-company`, {}, { abort: true, fullResult: true, isShopApi: true });
  return res == null ? void 0 : res.data;
};
var getLocationSelectOptions = async (params) => {
  const res = await import_utils.request.getRequest().get(`/shop/shop/location`, {}, { abort: true, fullResult: true, isShopApi: true });
  return res == null ? void 0 : res.data;
};
var channelModules = (biz) => {
  return {};
};
var editordership = (params) => {
  return import_utils.request.getRequest().post("/shop/order/order/shipments", { ...params, ...channelModules() }, { isShopApi: true });
};
var postSendInvoice = (params) => {
  return import_utils.request.getRequest().post("/shop/order/send-order-invoice", { ...params, ...channelModules() }, { isShopApi: true });
};
var openUrl = (host, url, shopId, ids) => {
  let str = (ids || []).reduce((str2, item) => str2 + "&order_ids[]=" + item, "");
  try {
    const _host = host || (app == null ? 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) {
  }
};
var printPack = (params) => {
  return openUrl("", "/order/print/packing", params.shop_id, params.ids);
};
var printPicking = (params) => {
  return openUrl("", "/order/print/picking", params.shop_id, params.ids);
};
var batchAddOrderTags = (params) => {
  return import_utils.request.getRequest().post("/shop/order/order/tag", {
    status: "attach",
    ...params
  }, {
    isShopApi: true
  });
};
var batchDeleteOrderTags = (params) => {
  return import_utils.request.getRequest().post("/shop/order/order/tag", {
    status: "detach",
    ...params
  }, {
    isShopApi: true
  });
};
var batchVoidedOrder = (params) => {
  return import_utils.request.getRequest().post("/shop/order/manual-voided", { ...params, ...channelModules() }, { isShopApi: true });
};
var batchPutOrderStatus = (params) => import_utils.request.getRequest().put("/shop/order/update-status", { order_ids: params.order_ids, status: params.status, is_void: params.is_void, ...channelModules() }, {
  isShopApi: true
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  batchAddOrderTags,
  batchDeleteOrderTags,
  batchPutOrderStatus,
  batchVoidedOrder,
  editordership,
  getChannelSelectOptions,
  getCustomerSelectOptions,
  getLocationSelectOptions,
  getLogisticsSelectOptions,
  getPaymentSelectOptions,
  getTagSelectOptions,
  listApi,
  openUrl,
  postSendInvoice,
  printPack,
  printPicking
});
