//#region src/pro/keyboards/phoneKeyboard/utils.ts
const normalizeCallingCode = (countryCallingCode) => `${countryCallingCode || ""}`.replace(/\D/g, "");
const normalizePhoneValue = (value) => `${value || ""}`.replace(/\D/g, "");
const joinGroups = (groups, separator) => groups.filter(Boolean).join(separator === "dash" ? "-" : " ");
const splitByGroups = (phone, groups) => {
	const result = [];
	let start = 0;
	groups.forEach((size) => {
		if (start >= phone.length) return;
		result.push(phone.slice(start, start + size));
		start += size;
	});
	if (start < phone.length) result.push(phone.slice(start));
	return result;
};
const formatByGroups = (phone, groups, separator) => joinGroups(splitByGroups(phone, groups), separator);
const formatWithOptionalLeadingZero = (phone, withZeroGroups, withoutZeroGroups, separator) => {
	return formatByGroups(phone, phone.startsWith("0") ? withZeroGroups : withoutZeroGroups, separator);
};
/**
* 按 phoneValidation 已覆盖的国家区号格式化手机号展示，返回值仅用于 UI 展示。
* @param phone 手机号，允许传入含空格或短横线的字符串
* @param countryCallingCode 国家区号，支持 61 或 +61
* @param separator 展示分隔符
*/
const formatPhoneDisplay = (phone, countryCallingCode, separator = "space") => {
	const normalizedPhone = normalizePhoneValue(phone);
	const normalizedCode = normalizeCallingCode(countryCallingCode);
	if (!normalizedPhone) return "";
	switch (normalizedCode) {
		case "61": return formatWithOptionalLeadingZero(normalizedPhone, [
			2,
			4,
			4
		], [
			1,
			4,
			4
		], separator);
		case "86": return formatByGroups(normalizedPhone, [
			3,
			4,
			4
		], separator);
		case "852":
		case "853":
		case "65": return formatByGroups(normalizedPhone, [4, 4], separator);
		case "886": return formatWithOptionalLeadingZero(normalizedPhone, [
			4,
			3,
			3
		], [
			3,
			3,
			3
		], separator);
		case "1": return formatByGroups(normalizedPhone, [
			3,
			3,
			4
		], separator);
		case "44": return formatWithOptionalLeadingZero(normalizedPhone, [
			4,
			3,
			4
		], [
			4,
			3,
			3
		], separator);
		case "81": return formatWithOptionalLeadingZero(normalizedPhone, [
			3,
			4,
			4
		], [
			2,
			4,
			4
		], separator);
		case "82": return formatByGroups(normalizedPhone, [
			3,
			3,
			4
		], separator);
		case "60": return formatByGroups(normalizedPhone, [
			2,
			4,
			4
		], separator);
		case "66":
		case "84":
		case "351": return formatByGroups(normalizedPhone, [
			3,
			3,
			3
		], separator);
		case "63":
		case "91": return formatByGroups(normalizedPhone, [
			3,
			3,
			4
		], separator);
		case "62": return formatByGroups(normalizedPhone, [
			3,
			4,
			4
		], separator);
		default: return formatByGroups(normalizedPhone, [
			3,
			3,
			3,
			3,
			3
		], separator);
	}
};
//#endregion
exports.formatPhoneDisplay = formatPhoneDisplay;
