const DEFAULT_FILE_EXT_ICON = 'document-text';

const DEFAULT_FILE_EXT_ICON_CONFIG = {
	// documents
	pdf: 'pdf',
	xls: 'grid-row-alt',
	xlsx: 'grid-row-alt',
	xlsm: 'grid-row-alt',
	ods: 'grid-row-alt',
	numbers: 'grid-row-alt',

	// audio
	mp3: 'play',
	wav: 'play',
	ogg: 'play',
	flac: 'play',
	aac: 'play',
	m4a: 'play',
	aiff: 'play',
	wma: 'play',
	opus: 'play',

	// video
	mp4: 'play',
	mov: 'play',
	avi: 'play',
	mkv: 'play',
	webm: 'play',
	wmv: 'play',
	flv: 'play',
	m4v: 'play',

	// images
	jpg: 'photograph',
	jpeg: 'photograph',
	png: 'photograph',
	gif: 'photograph',
	bmp: 'photograph',
	webp: 'photograph',
	svg: 'photograph',
	tiff: 'photograph',
	tif: 'photograph',
	heic: 'photograph',
	heif: 'photograph',
};

/**
 * @function getFileIcon
 * @description Gets the icon name for a file based on its extension.
 *
 * @since 5.9.0
 *
 * @param {object} file The file object with name property.
 *
 * @return {string} The icon name.
 */
export const getFileIcon = ( file ) => {
	if ( ! file?.name ) {
		return DEFAULT_FILE_EXT_ICON;
	}

	const ext = file.name.split( '.' ).pop().toLowerCase();
	return DEFAULT_FILE_EXT_ICON_CONFIG[ ext ] || DEFAULT_FILE_EXT_ICON;
};
