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.Phone/serve.ts
var serve_exports = {};
__export(serve_exports, {
  getCountryDataList: () => getCountryDataList,
  getShopCountryDataList: () => getShopCountryDataList,
  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 getShopCountryDataList = async (locale) => {
  const { data } = await import_utils.request.getRequest().get("/shop/area/country", { "translate-locale": locale || "en" });
  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, ...others } = (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
  });
  const { data: shopData, run: runShop } = (0, import_ahooks.useRequest)(getShopCountryDataList, {
    cacheKey: "phone-shop-countries",
    staleTime: 1e3 * 60 * 5,
    // 5分钟后数据过期
    cacheTime: 1e3 * 60 * 60,
    // 1小时后清除缓存
    manual: true
  });
  (0, import_react.useEffect)(() => {
    if (!isShop && !isPc && !isH5) {
      run();
    }
  }, [isShop]);
  (0, import_react.useEffect)(() => {
    var _a, _b, _c, _d, _e, _f, _g;
    if (isShop && !((_e = (_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) == null ? void 0 : _e.length)) {
      runShop((_g = (_f = others == null ? void 0 : others.engine) == null ? void 0 : _f.props) == null ? void 0 : _g.locale);
    }
  }, [isShop]);
  const currentData = (0, import_react.useMemo)(() => {
    var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
    let codeList = null;
    if (isShop) {
      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) || shopData;
    } else if (isPc) {
      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;
    } else if (isH5) {
      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 (isShop || isPc || isH5) {
      codeList = (codeList == null ? void 0 : codeList.length) > 0 ? codeList : defaultData;
      console.log("codeList", codeList);
      return codeList.map((item) => ({
        ...item,
        prefix: `+${item.calling_code}`
      }));
    }
    return data;
  }, [isShop, isPc, isH5, data, shopData]);
  return { data: currentData };
};
var defaultData = [
  {
    name: "Mexico",
    code: "MX",
    calling_code: "52",
    currency_code: "MXN"
  },
  {
    name: "美国",
    code: "US",
    calling_code: "1",
    currency_code: "USD"
  },
  {
    name: "加拿大",
    code: "CA",
    calling_code: "1",
    currency_code: "CAD"
  },
  {
    name: "澳大利亚",
    code: "AU",
    calling_code: "61",
    currency_code: "AUD"
  },
  {
    name: "新西兰",
    code: "NZ",
    calling_code: "64",
    currency_code: "NZD"
  },
  {
    name: "新加坡",
    code: "SG",
    calling_code: "65",
    currency_code: "SGD"
  },
  {
    name: "香港特别行政区",
    code: "HK",
    calling_code: "852",
    currency_code: "HKD"
  },
  {
    name: "台湾",
    code: "TW",
    calling_code: "886",
    currency_code: "TWD"
  },
  {
    name: "中国",
    code: "CN",
    calling_code: "86",
    currency_code: "AUD"
  },
  {
    name: "日本",
    code: "JP",
    calling_code: "81",
    currency_code: "JPY"
  },
  {
    name: "韩国",
    code: "KR",
    calling_code: "82",
    currency_code: "KRW"
  },
  {
    name: "马来西亚",
    code: "MY",
    calling_code: "60",
    currency_code: "USD"
  },
  {
    name: "英国",
    code: "GB",
    calling_code: "44",
    currency_code: "GBP"
  },
  {
    name: "法国",
    code: "FR",
    calling_code: "33",
    currency_code: "EUR"
  },
  {
    name: "意大利",
    code: "IT",
    calling_code: "39",
    currency_code: "EUR"
  },
  {
    name: "Ireland",
    code: "IE",
    calling_code: "353",
    currency_code: "EUR"
  },
  {
    name: "Netherlands",
    code: "NL",
    calling_code: "31",
    currency_code: "EUR"
  },
  {
    name: "Germany",
    code: "DE",
    calling_code: "49",
    currency_code: "EUR"
  },
  {
    name: "Spain",
    code: "ES",
    calling_code: "34",
    currency_code: "EUR"
  },
  {
    name: "Finland",
    code: "FI",
    calling_code: "358",
    currency_code: "EUR"
  },
  {
    name: "Hungary",
    code: "HU",
    calling_code: "36",
    currency_code: "HUF"
  },
  {
    name: "Indonesia",
    code: "ID",
    calling_code: "62",
    currency_code: "IDR"
  },
  {
    name: "India",
    code: "IND",
    calling_code: "91",
    currency_code: "INR"
  },
  {
    name: "Nigeria",
    code: "NG",
    calling_code: "234",
    currency_code: "NGN"
  },
  {
    name: "Islamic Republic of Pakistan‎",
    code: "PAK",
    calling_code: "92",
    currency_code: "PRK"
  },
  {
    name: "Philippines",
    code: "PH",
    calling_code: "63",
    currency_code: "PHP"
  },
  {
    name: "Thailand",
    code: "TH",
    calling_code: "66",
    currency_code: "THB"
  },
  {
    name: "South Africa",
    code: "ZA",
    calling_code: "27",
    currency_code: "ZAR"
  }
];
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getCountryDataList,
  getShopCountryDataList,
  useCountries
});
