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/dataSourceComponents/fields/Input.Mobile/serve.ts
var serve_exports = {};
__export(serve_exports, {
  getCountryDataList: () => getCountryDataList,
  useCountries: () => useCountries
});
module.exports = __toCommonJS(serve_exports);
var import_react = require("react");
var import_ahooks = require("ahooks");
var import_utils = require("../../../table/utils");
var import_usePlatform = require("../../hooks/usePlatform");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var getCountryDataList = async () => {
  const { data } = await import_utils.request.getRequest().get(
    `/country:list`,
    {},
    {
      isNocobase: true,
      fullResult: true,
      headers: {
        "x-data-source": "pisell2"
      }
    }
  );
  return data.map((item) => ({
    ...item,
    prefix: `+${item.calling_code}`
  }));
};
var useCountries = () => {
  const isShop = (0, import_usePlatform.useIsShop)();
  const isH5 = (0, import_usePlatform.useIsH5)();
  const isPc = (0, import_usePlatform.useIsPc)();
  const { appHelper } = (0, import_useEngineContext.default)();
  const { data, run } = (0, import_ahooks.useRequest)(getCountryDataList, {
    cacheKey: "phone-countries",
    staleTime: 1e3 * 60 * 5,
    // 5分钟后数据过期
    cacheTime: 1e3 * 60 * 60,
    // 1小时后清除缓存
    manual: true
  });
  (0, import_react.useEffect)(() => {
    if (!isShop) {
      run();
    }
  }, [isShop]);
  const currentData = (0, import_react.useMemo)(() => {
    var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
    if (isShop) {
      const codeList = (_d = (_c = (_b = (_a = appHelper == null ? void 0 : appHelper.utils) == null ? void 0 : _a.store) == null ? void 0 : _b.getState()) == null ? void 0 : _c.global) == null ? void 0 : _d.codeList;
      if (codeList) {
        return codeList.map((item) => ({
          ...item,
          prefix: `+${item.calling_code}`
        }));
      }
    } else if (isPc) {
      const codeList = (_h = (_g = (_f = (_e = appHelper == null ? void 0 : appHelper.utils) == null ? void 0 : _e.store) == null ? void 0 : _f.getState()) == null ? void 0 : _g.country) == null ? void 0 : _h.country;
      if (codeList) {
        return codeList.map((item) => ({
          ...item,
          prefix: `+${item.calling_code}`
        }));
      }
    } else if (isH5) {
      const codeList = (_l = (_k = (_j = (_i = appHelper == null ? void 0 : appHelper.utils) == null ? void 0 : _i.getStore()) == null ? void 0 : _j.getState()) == null ? void 0 : _k.country) == null ? void 0 : _l.country;
      if (codeList) {
        return codeList.map((item) => ({
          ...item,
          prefix: `+${item.calling_code}`
        }));
      }
    }
    return data;
  }, [isShop, data]);
  return { data: currentData };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getCountryDataList,
  useCountries
});
