import { fetchTagsById } from '#/src/tags.js';

const tagSlugs = {
	popular: [
		'anal',
		'lesbian',
		// 'interracial',
		'mff',
		'mfm',
		// 'teen',
		'milf',
		'blowjob',
		'gay',
		'transsexual',
		'dp',
		'gangbang',
		'facial',
		'creampie',
		'squirting',
	],
	appearance: [
		'asian',
		'black',
		'latina',
		'white',
		'natural-boobs',
		'enhanced-boobs',
		'blonde',
		'brunette',
		'redhead',
		'tattoos',
		'piercings',
	],
	sexuality: [
		'gay',
		'bisexual',
		'transsexual',
	],
	oral: [
		'blowjob',
		'deepthroat',
		'facefucking',
		'pussy-eating',
		'ass-eating',
		'69',
		'atm',
	],
	group: [
		'mfm',
		'mff',
		'orgy',
		'gangbang',
		'blowbang',
	],
	cumshot: [
		'facial',
		'bukkake',
		'creampie',
		'anal-creampie',
		'oral-creampie',
		'cum-in-mouth',
		'cum-on-boobs',
		'cum-on-butt',
		'cum-on-pussy',
		'fake-cum',
	],
	roleplay: [
		'family',
		'parody',
		'schoolgirl',
		'nurse',
		'maid',
	],
	extreme: [
		'dp',
		'airtight',
		'dap',
		'dvp',
		'triple-penetration',
		'tap',
		'tvp',
	],
	fetish: [
		'bdsm',
		'femdom',
		'bondage',
		'free-use',
		'latex',
		'blindfold',
	],
	manual: [
		'handjob',
		'fingering',
		'anal-fingering',
		'titty-fucking',
		'fisting',
		'anal-fisting',
	],
	toys: [
		'toys',
		'toy-anal',
		'toy-dp',
		'double-dildo',
		'double-dildo-blowjob',
		'double-dildo-kiss',
		'double-dildo-anal',
		'double-dildo-dp',
	],
	misc: [
		'gaping',
		'squirting',
		'oil',
		'vr',
		'bts',
	],
};

export async function onBeforeRender(_pageContext) {
	const tags = await fetchTagsById(Object.values(tagSlugs).flat());
	const tagsBySlug = Object.fromEntries(tags.map((tag) => [tag.slug, tag]));

	const tagShowcase = Object.fromEntries(Object.entries(tagSlugs).map(([category, categorySlugs]) => [
		category,
		categorySlugs.map((slug) => tagsBySlug[slug]).filter(Boolean),
	]));

	return {
		pageContext: {
			title: 'Tags',
			pageProps: {
				tagShowcase,
			},
		},
	};
}
