const calcAutoZoom = (containerWidth: number, resolution: string): string => {
	const resolutionWidth = parseInt(resolution);
	if (!containerWidth || !resolutionWidth) return "100";
	return String(Math.min(100, Math.floor((containerWidth / resolutionWidth) * 100)));
};

const calcDefaultResolution = (containerWidth: number, options: Array<{ value: string }>): string => {
	const sorted = [...options].sort((a, b) => parseInt(a.value) - parseInt(b.value));
	const best = sorted.find((opt) => parseInt(opt.value) >= containerWidth);
	return best ? best.value : sorted[sorted.length - 1].value;
};

export { calcAutoZoom, calcDefaultResolution };
