require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_utils = require("../../../table/utils.js");
const require_usePlatform = require("../../hooks/usePlatform.js");
let react = require("react");
let ahooks = require("ahooks");
//#region src/components/dataSourceComponents/fields/Input.Phone/serve.ts
const _excluded = ["appHelper"];
/**
* 获取nocobase数据列表
*/
const getCountryDataList = function() {
	var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
		const { data } = yield require_utils.request.getRequest().get(`/country:list`, {
			page: 1,
			pageSize: 999
		}, {
			isNocobase: true,
			fullResult: true,
			headers: { "x-data-source": "pisell2" }
		});
		return data.map((item) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { prefix: `+${item.calling_code}` }));
	});
	return function getCountryDataList() {
		return _ref.apply(this, arguments);
	};
}();
const getShopCountryDataList = function() {
	var _ref2 = require_asyncToGenerator._asyncToGenerator(function* (locale) {
		const { data } = yield require_utils.request.getRequest().get("/shop/area/country", { "translate-locale": locale || "en" });
		return data.map((item) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { prefix: `+${item.calling_code}` }));
	});
	return function getShopCountryDataList(_x) {
		return _ref2.apply(this, arguments);
	};
}();
const useCountries = () => {
	const isShop = require_usePlatform.useIsShop();
	const isH5 = require_usePlatform.useIsH5();
	const isPc = require_usePlatform.useIsPc();
	const _useEngineContext = require_useEngineContext.default(), { appHelper } = _useEngineContext, others = require_objectWithoutProperties._objectWithoutProperties(_useEngineContext, _excluded);
	const { data, run } = (0, ahooks.useRequest)(getCountryDataList, {
		cacheKey: "phone-countries",
		staleTime: 1e3 * 60 * 5,
		cacheTime: 1e3 * 60 * 60,
		manual: true
	});
	const { data: shopData, run: runShop } = (0, ahooks.useRequest)(getShopCountryDataList, {
		cacheKey: "phone-shop-countries",
		staleTime: 1e3 * 60 * 5,
		cacheTime: 1e3 * 60 * 60,
		manual: true
	});
	(0, react.useEffect)(() => {
		if (!isShop && !isPc && !isH5) run();
	}, [isShop]);
	(0, react.useEffect)(() => {
		var _appHelper$utils;
		if (isShop && !(appHelper === null || appHelper === void 0 || (_appHelper$utils = appHelper.utils) === null || _appHelper$utils === void 0 || (_appHelper$utils = _appHelper$utils.store) === null || _appHelper$utils === void 0 || (_appHelper$utils = _appHelper$utils.getState()) === null || _appHelper$utils === void 0 || (_appHelper$utils = _appHelper$utils.global) === null || _appHelper$utils === void 0 || (_appHelper$utils = _appHelper$utils.codeList) === null || _appHelper$utils === void 0 ? void 0 : _appHelper$utils.length)) {
			var _others$engine;
			runShop(others === null || others === void 0 || (_others$engine = others.engine) === null || _others$engine === void 0 || (_others$engine = _others$engine.props) === null || _others$engine === void 0 ? void 0 : _others$engine.locale);
		}
	}, [isShop]);
	return { data: (0, react.useMemo)(() => {
		let codeList = null;
		if (isShop) {
			var _appHelper$utils2;
			codeList = (appHelper === null || appHelper === void 0 || (_appHelper$utils2 = appHelper.utils) === null || _appHelper$utils2 === void 0 || (_appHelper$utils2 = _appHelper$utils2.store) === null || _appHelper$utils2 === void 0 || (_appHelper$utils2 = _appHelper$utils2.getState()) === null || _appHelper$utils2 === void 0 || (_appHelper$utils2 = _appHelper$utils2.global) === null || _appHelper$utils2 === void 0 ? void 0 : _appHelper$utils2.codeList) || shopData;
		} else if (isPc) {
			var _appHelper$utils3;
			codeList = appHelper === null || appHelper === void 0 || (_appHelper$utils3 = appHelper.utils) === null || _appHelper$utils3 === void 0 || (_appHelper$utils3 = _appHelper$utils3.store) === null || _appHelper$utils3 === void 0 || (_appHelper$utils3 = _appHelper$utils3.getState()) === null || _appHelper$utils3 === void 0 || (_appHelper$utils3 = _appHelper$utils3.country) === null || _appHelper$utils3 === void 0 ? void 0 : _appHelper$utils3.country;
		} else if (isH5) {
			var _appHelper$utils4;
			codeList = appHelper === null || appHelper === void 0 || (_appHelper$utils4 = appHelper.utils) === null || _appHelper$utils4 === void 0 || (_appHelper$utils4 = _appHelper$utils4.getStore()) === null || _appHelper$utils4 === void 0 || (_appHelper$utils4 = _appHelper$utils4.getState()) === null || _appHelper$utils4 === void 0 || (_appHelper$utils4 = _appHelper$utils4.country) === null || _appHelper$utils4 === void 0 ? void 0 : _appHelper$utils4.country;
		}
		if (isShop || isPc || isH5) {
			codeList = (codeList === null || codeList === void 0 ? void 0 : codeList.length) > 0 ? codeList : defaultData;
			console.log("codeList", codeList);
			return codeList.map((item) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { prefix: `+${item.calling_code}` }));
		}
		return data;
	}, [
		isShop,
		isPc,
		isH5,
		data,
		shopData
	]) };
};
const 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"
	}
];
//#endregion
exports.useCountries = useCountries;
