<commit_before>import {callPhone} from '../../components/call-phone'
import {sendEmail} from '../../components/send-email'
import {entities} from '@frogpond/html-lib'
import type {FABGroupAction} from 'react-native-paper'
import type {
	CampusLocation,
	DirectoryItem,
	OfficeHours,
	SearchResults,
} from './types'

export const buildPhoneActions = (
	loc: CampusLocation,
	locationsCount: number,
): FABGroupAction => {
	return {
		icon: 'phone',
		label:
			locationsCount === 1 ? 'Call' : `Call ${loc.buildingabbr} ${loc.room}`,
		onPress: () => callPhone(loc.phone),
	}
}

export const buildEmailAction = (
	email: DirectoryItem['email'],
): FABGroupAction[] => {
	if (!email) return []

	return [
		{
			icon: 'email',
			label: 'Email',
			onPress: () => sendEmail({to: [email], subject: '', body: ''}),
		},
	]
}

const prefixTitle = (prefix: OfficeHours['prefix']): string => {
	return prefix.endsWith(':') ? prefix.slice(0, -1) : prefix
}

const officeHoursTitle = (officeHours: OfficeHours): string => {
	const content = officeHours.content || ''
	const label = officeHours.hrefLabel || ''

	return `${content} ${label}`
}

const descriptionText = (
	shortRoom: CampusLocation['shortLocation'],
	item: DirectoryItem,
): string | null => {
	const description =
		shortRoom && item.title
			? `${shortRoom} • ${item.title}`
			: shortRoom
			? shortRoom
			: item.title

	return description && entities.decode(description)
}

const shortRoomText = (
	campusLocations: DirectoryItem['campusLocations'],
): string => {
	return campusLocations
		.map((loc) => `${loc.buildingabbr} ${loc.room}`.trim())
		.join(' / ')
}

const shortRoomDetail = (loc: CampusLocation): string => {
	const shortRoom = `${loc.buildingabbr} ${loc.room}`.trim()
	return `${shortRoom ? `${shortRoom} • ` : ''}${loc.phone}`
}

export const formatResults = (
	data: SearchResults,
): SearchResults['results'] => {
	return data.results.map((item: DirectoryItem) => {
		const {campusLocations, displayTitle, officeHours} = item
		const shortRoom = shortRoomText(campusLocations)

		const result = {
			...item,
			description: descriptionText(shortRoom, item),
			displayTitle: displayTitle && entities.decode(displayTitle),
		}

		if (officeHours) {<commit_msg>fix call while decoding entities in directory helpers<commit_after>import {callPhone} from '../../components/call-phone'
import {sendEmail} from '../../components/send-email'
import type {FABGroupAction} from 'react-native-paper'
import {decode} from '@frogpond/html-lib'
import type {
	CampusLocation,
	DirectoryItem,
	OfficeHours,
	SearchResults,
} from './types'

export const buildPhoneActions = (
	loc: CampusLocation,
	locationsCount: number,
): FABGroupAction => {
	return {
		icon: 'phone',
		label:
			locationsCount === 1 ? 'Call' : `Call ${loc.buildingabbr} ${loc.room}`,
		onPress: () => callPhone(loc.phone),
	}
}

export const buildEmailAction = (
	email: DirectoryItem['email'],
): FABGroupAction[] => {
	if (!email) return []

	return [
		{
			icon: 'email',
			label: 'Email',
			onPress: () => sendEmail({to: [email], subject: '', body: ''}),
		},
	]
}

const prefixTitle = (prefix: OfficeHours['prefix']): string => {
	return prefix.endsWith(':') ? prefix.slice(0, -1) : prefix
}

const officeHoursTitle = (officeHours: OfficeHours): string => {
	const content = officeHours.content || ''
	const label = officeHours.hrefLabel || ''

	return `${content} ${label}`
}

const descriptionText = (
	shortRoom: CampusLocation['shortLocation'],
	item: DirectoryItem,
): string | null => {
	const description =
		shortRoom && item.title
			? `${shortRoom} • ${item.title}`
			: shortRoom
			? shortRoom
			: item.title

	return description && decode(description)
}

const shortRoomText = (
	campusLocations: DirectoryItem['campusLocations'],
): string => {
	return campusLocations
		.map((loc) => `${loc.buildingabbr} ${loc.room}`.trim())
		.join(' / ')
}

const shortRoomDetail = (loc: CampusLocation): string => {
	const shortRoom = `${loc.buildingabbr} ${loc.room}`.trim()
	return `${shortRoom ? `${shortRoom} • ` : ''}${loc.phone}`
}

export const formatResults = (
	data: SearchResults,
): SearchResults['results'] => {
	return data.results.map((item: DirectoryItem) => {
		const {campusLocations, displayTitle, officeHours} = item
		const shortRoom = shortRoomText(campusLocations)

		const result = {
			...item,
			description: descriptionText(shortRoom, item),
			displayTitle: displayTitle && decode(displayTitle),
		}

		if (officeHours) {
{'fraction_non_alphanumeric': 0.1688888888888889, 'fraction_numerical': 0.0013333333333333333, 'mean_word_length': 4.584367245657568, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4312222', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1453, 'n_words': 331}