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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellFloorMapLayout/hooks/useShopFloorPlanSubscription.ts
var useShopFloorPlanSubscription_exports = {};
__export(useShopFloorPlanSubscription_exports, {
  useShopFloorPlanSubscription: () => useShopFloorPlanSubscription
});
module.exports = __toCommonJS(useShopFloorPlanSubscription_exports);
var import_react = require("react");
var import_shopFloorPlanPure = require("../shopFloorPlan/shopFloorPlanPure");
function useShopFloorPlanSubscription(params) {
  const {
    enabled,
    code,
    subscriberId,
    ensureByCode,
    unsubscribeQuery,
    onDetail,
    onLoadError,
    osServer = true
  } = params;
  const onDetailRef = (0, import_react.useRef)(onDetail);
  onDetailRef.current = onDetail;
  const onLoadErrorRef = (0, import_react.useRef)(onLoadError);
  onLoadErrorRef.current = onLoadError;
  const ensureByCodeRef = (0, import_react.useRef)(ensureByCode);
  ensureByCodeRef.current = ensureByCode;
  const unsubscribeQueryRef = (0, import_react.useRef)(unsubscribeQuery);
  unsubscribeQueryRef.current = unsubscribeQuery;
  (0, import_react.useEffect)(() => {
    if (!enabled) return;
    let cancelled = false;
    const subId = subscriberId;
    void ensureByCodeRef.current(code, {
      osServer,
      subscriberId: subId,
      callback: (res) => {
        if (cancelled) return;
        const detail = (0, import_shopFloorPlanPure.pickFloorPlanDetail)(res);
        if (!detail) return;
        onDetailRef.current(detail);
      }
    }).then((detail) => {
      if (cancelled || !detail) return;
      onDetailRef.current(detail);
    }).catch((err) => {
      var _a;
      if (!cancelled) {
        (_a = onLoadErrorRef.current) == null ? void 0 : _a.call(onLoadErrorRef, err);
      }
    });
    return () => {
      cancelled = true;
      void unsubscribeQueryRef.current(subId);
    };
  }, [enabled, code, subscriberId, osServer]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useShopFloorPlanSubscription
});
