//#region src/components/UserProfile/utils.ts
const currentSessionFirst = (id) => (a) => a.id === id ? -1 : 1;
const defaultFirst = (a) => a.defaultSecondFactor ? -1 : 1;
function getSecondFactors(attributes) {
	const secondFactors = [];
	Object.entries(attributes).forEach(([, attr]) => {
		if (attr.used_for_second_factor) secondFactors.push(...attr.second_factors);
	});
	return secondFactors;
}
function getSecondFactorsAvailableToAdd(attributes, user) {
	let sfs = getSecondFactors(attributes);
	if (user.totpEnabled) sfs = sfs.filter((f) => f !== "totp");
	if (user.backupCodeEnabled || !user.twoFactorEnabled) sfs = sfs.filter((f) => f !== "backup_code");
	return sfs;
}
function sortIdentificationBasedOnVerification(array, primaryId) {
	if (!array) return [];
	const primaryItem = array.filter((item) => item.id === primaryId);
	const itemsWithoutPrimary = array.filter((item) => item.id !== primaryId);
	const verifiedItems = itemsWithoutPrimary.filter((item) => item.verification?.status === "verified");
	const unverifiedItems = itemsWithoutPrimary.filter((item) => !!item.verification?.status && item.verification?.status !== "verified");
	const unverifiedItemsWithoutVerification = itemsWithoutPrimary.filter((item) => !item.verification.status);
	verifiedItems.sort((a, b) => a.id.localeCompare(b.id));
	unverifiedItems.sort((a, b) => {
		if (!a.verification?.expireAt || !b.verification?.expireAt) return 0;
		return a.verification.expireAt.getTime() - b.verification.expireAt.getTime();
	});
	return [
		...primaryItem,
		...verifiedItems,
		...unverifiedItems,
		...unverifiedItemsWithoutVerification
	];
}

//#endregion
export { currentSessionFirst, defaultFirst, getSecondFactors, getSecondFactorsAvailableToAdd, sortIdentificationBasedOnVerification };
//# sourceMappingURL=utils.js.map