import workExperienceData from "@/src/portfolio/data/workExperienceData";
import { WorkExperienceArgs } from "@/src/portfolio/helpers/WorkExperience";

export interface ICityGroup {
	city: string;
	jobs: WorkExperienceArgs[];
	visibleJobs: WorkExperienceArgs[];
	hasMore: boolean;
	hiddenCount: number;
	imageUrl: string;
	offsetDirection: "left" | "right";
	description?: string;
}

const CITY_IMAGES: Record<string, string> = {
	"Manchester": "/portfolio/cities/Manchester.png",
	"Edinburgh": "/portfolio/cities/Edinburgh.png",
	"London": "/portfolio/cities/London.png",
	"Warsaw": "/portfolio/cities/Warsaw.png"
};

const createCityGroup = (
	city: string,
	jobs: WorkExperienceArgs[],
	offset: "left" | "right",
	description?: string
): ICityGroup => {
	const importantJobs = jobs.filter(job => job.isImportant);
	const nonImportantJobs = jobs.filter(job => !job.isImportant);

	const needToFill = Math.max(0, 2 - importantJobs.length);
	const fillerJobs = nonImportantJobs.slice(0, needToFill);
	const remainingNonImportant = nonImportantJobs.slice(needToFill);

	return {
		city,
		jobs,
		visibleJobs: [...importantJobs, ...fillerJobs],
		hasMore: remainingNonImportant.length > 0,
		hiddenCount: remainingNonImportant.length,
		imageUrl: CITY_IMAGES[city] || "",
		offsetDirection: offset,
		description
	};
};

export const getCityGroups = (): ICityGroup[] => {
	const manchesterJobs = workExperienceData.filter(job => job.city === "Manchester");
	const edinburghJobs = workExperienceData.filter(job => job.city === "Edinburgh");
	const londonJobs = workExperienceData.filter(job => job.city === "London" || job.city === "Upminster");
	const warsawJobs = workExperienceData.filter(job => job.city === "Warsaw");

	return [
		createCityGroup(
			"Manchester",
			manchesterJobs,
			"right",
			"After finishing my master's degree, I moved to Manchester because I really liked the culture and the city."
		),
		createCityGroup(
			"Edinburgh",
			edinburghJobs,
			"left",
			"I moved to Edinburgh to pursue my Master's in Artificial Intelligence at the University of Edinburgh."
		),
		createCityGroup(
			"London",
			londonJobs,
			"right",
			"After Warsaw, I moved to London for my bachelor's education at Queen Mary University."
		),
		createCityGroup(
			"Warsaw",
			warsawJobs,
			"left",
			"Where my journey began - my first job experience in the hospitality industry."
		)
	];
};
