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/salesSdk/demo/hosts/legacyOpenProductDetail.ts
var legacyOpenProductDetail_exports = {};
__export(legacyOpenProductDetail_exports, {
  createLegacyOpenProductDetailHost: () => createLegacyOpenProductDetailHost
});
module.exports = __toCommonJS(legacyOpenProductDetail_exports);
var import_dayjs = __toESM(require("dayjs"));
var OPEN_PRODUCT_DETAIL_TIMEOUT_MS = 12e4;
var formatBundle = (bundle) => {
  if (!Array.isArray(bundle)) return [];
  return bundle.map((item) => ({
    ...item,
    bundle_product_id: item._bundle_product_id
  }));
};
function createLegacyOpenProductDetailHost(deps) {
  const { action, getRuntime } = deps;
  return (payload) => {
    if (!action) {
      return Promise.reject(
        new Error("[SalesSdk Demo] openProductDetail: appHelper.utils.action 不可用")
      );
    }
    const item = payload.productData ?? payload.item;
    const runtime = getRuntime();
    const rawDate = payload.date ?? runtime.date;
    const date = (0, import_dayjs.default)(rawDate).isValid() ? (0, import_dayjs.default)(rawDate).format("YYYY-MM-DD") : (0, import_dayjs.default)().format("YYYY-MM-DD");
    return new Promise((resolve, reject) => {
      var _a;
      let settled = false;
      const settle = (fn) => {
        if (settled) return;
        settled = true;
        clearTimeout(timer);
        fn();
      };
      const timer = setTimeout(() => {
        settle(
          () => reject(
            new Error(
              "[SalesSdk] openProductDetail 超时：页面未响应 pisell1.handleOpenProductModal（请确认低代码页已注册该 action，且场次弹窗能正常打开）"
            )
          )
        );
      }, OPEN_PRODUCT_DETAIL_TIMEOUT_MS);
      action({
        type: "pisell1.handleOpenProductModal",
        data: {
          id: item == null ? void 0 : item.id,
          date,
          productDetail: item,
          showConfig: payload.showConfig,
          value: item == null ? void 0 : item.initValue,
          isOnlySession: payload.isOnlySession,
          is_eject: payload.isEject ? 1 : 0,
          customer_id: payload.customerId ?? runtime.customerId,
          isOS: (_a = payload.showConfig) == null ? void 0 : _a.session
        },
        onCancel: () => settle(() => resolve(null)),
        callback: (e, extension_type, detail) => {
          console.log(e, extension_type, detail, "detail1234");
          settle(
            () => resolve({
              e: {
                ...e,
                bundle: formatBundle(e.bundle)
              },
              extension_type,
              detail
            })
          );
        }
      });
    });
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createLegacyOpenProductDetailHost
});
