"use strict";

const thumbnailImageBrowser = require("../thumbnail-image-browser");
const getThumbnail = require("../get-thumbnail");

module.exports = function thumbnailImage({ session, mxc, maximumWidth, maximumHeight, file, mimetype }) {
	// TODO: localOnly option for encrypted images
	if (typeof window !== "undefined" && window.HTMLImageElement != null) {
		// Browser environments
		return thumbnailImageBrowser({
			file: file,
			mimetype: mimetype,
			maximumWidth: maximumWidth,
			maximumHeight: maximumHeight,
		});
	} else {
		// Server environments
		return getThumbnail({
			session: session,
			url: mxc,
			method: "fit",
			minimumWidth: maximumWidth,
			minimumHeight: maximumHeight,
			stream: false
		});
	}
};
