var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/modules/SurchargeList/index.ts
var SurchargeList_exports = {};
__export(SurchargeList_exports, {
  SurchargeListModule: () => SurchargeListModule
});
module.exports = __toCommonJS(SurchargeList_exports);
var import_BaseModule = require("../BaseModule");
__reExport(SurchargeList_exports, require("./types"), module.exports);
var SurchargeListModule = class extends import_BaseModule.BaseModule {
  constructor(name, version) {
    super(name, version);
    this.defaultName = "surchargeList";
    this.defaultVersion = "1.0.0";
    this.loadingPromise = null;
  }
  async initialize(core, options) {
    var _a, _b, _c;
    this.core = core;
    this.store = options.store;
    this.request = this.core.getPlugin("request");
    const hasInitialSurchargeList = Array.isArray(
      (_a = options.initialState) == null ? void 0 : _a.surchargeList
    );
    this.store.surchargeList = hasInitialSurchargeList ? (_b = options.initialState) == null ? void 0 : _b.surchargeList : [];
    this.store.isLoaded = Boolean((_c = options.initialState) == null ? void 0 : _c.isLoaded) || hasInitialSurchargeList;
    if (!this.request) {
      throw new Error("SurchargeListModule 需要 request 插件支持");
    }
  }
  async getSurchargeList() {
    if (this.store.isLoaded)
      return this.store.surchargeList;
    if (this.loadingPromise)
      return this.loadingPromise;
    this.loadingPromise = this.loadSurchargeList();
    return this.loadingPromise;
  }
  async refreshSurchargeList() {
    this.loadingPromise = this.loadSurchargeList();
    return this.loadingPromise;
  }
  async loadSurchargeList() {
    try {
      const surchargeList = await this.request.get(
        "/order/custom-surcharge/available/v2",
        {
          channel: "online-store",
          is_assemble_product_data: 1,
          is_assemble_schedule_data: 1,
          with: ["relationSchedule"]
        }
      );
      this.store.surchargeList = (surchargeList == null ? void 0 : surchargeList.data) || [];
      this.store.isLoaded = true;
      return this.store.surchargeList;
    } catch (error) {
      console.warn("[SurchargeListModule] 加载附加费配置失败", error);
      this.store.surchargeList = [];
      this.store.isLoaded = true;
      return this.store.surchargeList;
    } finally {
      this.loadingPromise = null;
    }
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SurchargeListModule,
  ...require("./types")
});
