export const isValidSwedishPhone = (phone: string): boolean => {
	const cleanPhone = phone.replace(/[\s\-\(\)]/g, '');

	if (!cleanPhone) return false;

	// +46 / 46 path
	if (cleanPhone.startsWith('+46') || cleanPhone.startsWith('46')) {
		const cut = cleanPhone.startsWith('+46') ? 3 : 2; // <-- fix: 3 for +46, 2 for 46
		const withoutCountryCode = cleanPhone.slice(cut);

		// must be digits only after country code
		if (!/^\d+$/.test(withoutCountryCode)) return false;

		if (withoutCountryCode.startsWith('7')) {
			// mobile: exactly 9 digits after 46
			return withoutCountryCode.length === 9;
		} else {
			// landline: 6..10 digits, no leading 0
			return (
				withoutCountryCode.length >= 6 &&
				withoutCountryCode.length <= 10 &&
				/^[1-9]\d*$/.test(withoutCountryCode)
			);
		}
	}

	// Local 0-leading path
	if (cleanPhone.startsWith('0')) {
		if (!/^\d+$/.test(cleanPhone)) return false;

		if (cleanPhone.startsWith('07')) {
			// mobile: exactly 10 digits including leading 0
			return cleanPhone.length === 10;
		} else {
			// landline: 8..10 digits; second digit 1-9
			return (
				cleanPhone.length >= 8 &&
				cleanPhone.length <= 10 &&
				/^0[1-9]\d+$/.test(cleanPhone)
			);
		}
	}

	return false;
};
