import {
	SYNC_ALBUM_NOT_FOUND,
	SYNC_ACCOUNT_DISCONNECTED,
	SYNC_SUCCESS,
	SYNC_IN_PROGRESS,
	SYNC_INIT,
	GOOGLE_PHOTOS_ERRORS,
} from '~/store/dynamicPlaylistStates';
import { GOOGLE_PHOTOS } from '~/store/contentTypes';

export const getDynamicPlaylistState = (playlist, googleId) => {
	if (playlist.type === GOOGLE_PHOTOS
		&& playlist.errorMsg === GOOGLE_PHOTOS_ERRORS.ALBUM_NOT_FOUND) {
		return SYNC_ALBUM_NOT_FOUND;
	} else if ((playlist.type === GOOGLE_PHOTOS && googleId !== playlist.googleId)
		&& playlist.errorMsg === GOOGLE_PHOTOS_ERRORS.ACCOUNT_UNMATCH) {
		return SYNC_ACCOUNT_DISCONNECTED;
	} else if (playlist.type === GOOGLE_PHOTOS && playlist.active && !playlist.sync) {
		return SYNC_SUCCESS;
	} else if (playlist.type === GOOGLE_PHOTOS && playlist.sync && playlist.count > 0) {
		return SYNC_IN_PROGRESS;
	} else if (playlist.type === GOOGLE_PHOTOS && !playlist.active
			&& playlist.errorMsg === GOOGLE_PHOTOS_ERRORS.ACCOUNT_UNMATCH) {
		return SYNC_IN_PROGRESS;
	} else if (playlist.type === GOOGLE_PHOTOS && playlist.sync && playlist.count === 0) {
		return SYNC_INIT;
	} else if (playlist.type === GOOGLE_PHOTOS && !playlist.active) {
		return SYNC_ACCOUNT_DISCONNECTED;
	}
	return '';
};
