import { FRAME_ORIENTATION } from '~/store/frameConstants';

export const FRAME_STATUS_BUFFER = 60 * 1000;

export const isOnline = ({ connected, lastConnected, lastSeen }) => {
	if (connected) {
		return { online: true, lastSeen };
	} else if (!lastConnected && !lastSeen) {
		return { online: false };
	} else if (lastSeen && lastSeen > lastConnected) {
		const timeDiff = Date.now() - lastSeen;
		if (timeDiff >= FRAME_STATUS_BUFFER) {
			return { online: false, lastSeen };
		}
		return { online: true, lastSeen, timeout: FRAME_STATUS_BUFFER - timeDiff };
	}
	return { online: true, lastSeen };
};

export const getDimensions = ({
	width, height, orientation, dimensions,
}) => {
	const ratio = dimensions.height / dimensions.width;
	if (orientation === 'landscape') {
		if (ratio < 0.65) {
			return { width: width * 0.80, height: height * 0.45 };
		}
		return { width: width * 0.7, height: height * 0.53 };
	} else if (ratio < 0.65) {
		return { width: width * 0.45, height: height * 0.75 };
	}
	return { width: width * 0.53, height: height * 0.7 };
};

export const getFrameWhiteSpace = ({
	orientation, dimensions, model,
}) => {
	const ratio = dimensions.height / dimensions.width;
	if (orientation === FRAME_ORIENTATION.LANDSCAPE) {
		if (model.includes('W08E')) { return 0; }
		if (ratio < 0.65) { return 0.12; }
		return 0.09;
	}
	return 0;
};
