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/components/wallet/DetailContext.tsx
var DetailContext_exports = {};
__export(DetailContext_exports, {
  DetailProvider: () => DetailProvider,
  useDetail: () => useDetail
});
module.exports = __toCommonJS(DetailContext_exports);
var import_react = __toESM(require("react"));
var import_Detail = __toESM(require("./Detail"));
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_locales = __toESM(require("./Detail/locales"));
var import_utils2 = require("../../utils");
var DetailContext = (0, import_react.createContext)(null);
var DetailProvider = ({ children }) => {
  var _a, _b, _c;
  const [currentDetail, setCurrentDetail] = (0, import_react.useState)(null);
  const [isOpen, setIsOpen] = (0, import_react.useState)(false);
  const [isInitialized, setIsInitialized] = (0, import_react.useState)(false);
  const detailRef = (0, import_react.useRef)(null);
  const context = (0, import_useEngineContext.default)();
  const utils = ((_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.utils) || {};
  const dvaStore = (_c = (_b = utils == null ? void 0 : utils.getStore) == null ? void 0 : _b.call(utils)) == null ? void 0 : _c.getState();
  (0, import_react.useEffect)(() => {
    var _a2;
    import_utils.locales.init(import_locales.default, ((_a2 = dvaStore == null ? void 0 : dvaStore.core) == null ? void 0 : _a2.translateLocale) || "en");
    import_utils2.request.setRequest(utils == null ? void 0 : utils.request);
    setIsInitialized(true);
  }, []);
  const platform = (0, import_react.useMemo)(() => (0, import_utils.isMobile)() ? "h5" : "pc", []);
  const isMobileDevice = (0, import_react.useMemo)(() => (0, import_utils.isMobile)(), []);
  const openDetail = (detail) => {
    setCurrentDetail(detail);
    setIsOpen(true);
  };
  const closeDetail = () => {
    setIsOpen(false);
  };
  const addWalletCard = () => {
    var _a2;
    (_a2 = detailRef.current) == null ? void 0 : _a2.addWalletCard();
  };
  const setShowModal = (show) => {
    setIsOpen(show);
  };
  const renderDetail = (detail) => {
    if (!detail) return null;
    const { buttonGroupList = [], showWalletBar, onBack, ...restDetail } = detail;
    return /* @__PURE__ */ import_react.default.createElement(
      import_Detail.default,
      {
        detail: restDetail,
        showWalletBar,
        onBack,
        addWalletCallback: (addWallet) => {
        },
        buttonGroupList
      }
    );
  };
  const contextValue = (0, import_react.useMemo)(() => ({
    openDetail,
    closeDetail,
    currentDetail,
    isOpen,
    addWalletCard,
    setShowModal,
    renderDetail,
    isInitialized
  }), [currentDetail, isOpen, isInitialized]);
  (0, import_react.useEffect)(() => {
    window.__WALLET_DETAIL_CONTEXT__ = contextValue;
    return () => {
      delete window.__WALLET_DETAIL_CONTEXT__;
    };
  }, [contextValue]);
  return /* @__PURE__ */ import_react.default.createElement(DetailContext.Provider, { value: contextValue }, children);
};
var useDetail = () => {
  const context = (0, import_react.useContext)(DetailContext);
  if (!context) {
    throw new Error("useDetail必须在DetailProvider内部使用");
  }
  return context;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DetailProvider,
  useDetail
});
