import * as shops from '@lib/redux/actions/shops-actions';
import * as ads from '@lib/redux/actions/ads-actions';
import * as classifieds from '@lib/redux/actions/classifieds-actions';
import * as paginator from '@lib/redux/actions/paginator-actions';
import * as auth from '@lib/redux/actions/auth-actions';
import * as ratings from '@lib/redux/actions/ratings-actions';
import * as districts from '@lib/redux/actions/districts-actions';
import * as directories from '@lib/redux/actions/directories-actions';
import * as subdirectories from '@lib/redux/actions/subdirectories-actions';
import * as directory_listings from '@lib/redux/actions/directory-listings-actions';
import * as magicTemp from '@lib/redux/actions/magic-temp-actions';
import * as follows from '@lib/redux/actions/follows-actions';
import * as search from '@lib/redux/actions/search-actions';
import * as globalHelpers from '@lib/redux/actions/global-helpers-actions';
import * as flags from '@lib/redux/actions/flags-actions';
import * as users from '@lib/redux/actions/users-actions';
import * as news from '@lib/redux/actions/news-actions';
import * as comments from '@lib/redux/actions/comments-actions';
import * as messages from '@lib/redux/actions/messages-actions';
import * as lifestyles from '@lib/redux/actions/lifestyles-actions';
import * as managedContent from '@lib/redux/actions/managed-content-actions';
import * as rankings from '@lib/redux/actions/rankings-actions';
import * as ashantis_abroad from '@lib/redux/actions/ashantis-abroad-actions';
import * as liveRadio from '@lib/redux/actions/live-radio-actions';
import * as invoices from '@lib/redux/actions/invoices-actions';
import * as notifications from '@lib/redux/actions/notifications-actions';
import * as vlogs from '@lib/redux/actions/vlogs-actions';
import * as humans from '@lib/redux/actions/humans-actions';
import * as sha from '@lib/redux/actions/sha-actions';
import * as cms from '@lib/redux/actions/cms-actions';
import * as external_api from '@lib/redux/actions/external-api-actions';
import * as eha from '@lib/redux/actions/eha-actions';
import {reducer as notificationsReducer} from 'reapop';


import { subdomain } from '@routes/routes';

let metrics;

const
	fetchTrue = {
		fetching: true,
		error: null
	},
	fetchFalse = {
		fetching: false,
		error: null
	},
	deleteFalse = {
		deleting: false,
		error: null
	},
	downloadFalse = {
		downloading: false,
		error: null
	},
	postTrue = {
		posting: true,
		error: null
	},
	postFalse = {
		posting: false,
		error: null
	},
	initialState = {
		shop_activity: [],
		unread_messages: [],
		ads: [],
		classifieds: [],
		districts: [],
		district: {},
		district_classified: {},
		directories: [],
		notifications: [],
		live_radios: [],
		directory: {},
		subdirectory: {},
		directory_listings: {},
		lifestyles: [],
		lifestyle: {},
		invoices: [],
		lifestyle_categories: [],
		managed_content: [],
		ashantis_abroad: [],
		ashanti_abroad: {},
		rankings_categories: [],
		rankings_ta_cat: {},
		ranking: {},
		ad: null,
		data: [],
		status: {
			fetching: true,
			error: null,
			shop: { ...fetchTrue, ...postFalse },
			ad: { ...fetchTrue, ...postFalse },
			ads: { ...fetchTrue },
			live_radios: { ...fetchTrue },
			invoices: { ...fetchTrue, ...postFalse, ...deleteFalse, downloadFalse },
			rankings_categories: { ...fetchTrue },
			rankings_ta_cat: {},
			ashantis_abroad: { ...fetchTrue },
			ashanti_abroad: { ...fetchTrue },
			classifieds: { ...fetchTrue },
			ranking: { ...fetchTrue },
			districts: { ...fetchTrue },
			district: { ...fetchTrue },
			district_classified: { ...fetchTrue },
			magic_temp: { ...postFalse },
			shop_none_members: { ...fetchFalse },
			managed_content: { ...fetchTrue },
			lifestyles: { ...fetchTrue },
			lifestyle: { ...fetchTrue },
			lifestyle_categories: { ...fetchTrue },
			notifications: { ...fetchTrue },
		}
	};

export { initialState };

export const reducer = (state: Record<string, any> = initialState, action: Record<string, any>): Record<string, any> => {

	switch (action.type) {

	// EHA
	case eha.embedAd().type:
		return { ...state, eha: state.eha, status: { ...state.status, eha: { fetching: true, error: null } } };
	case eha.embededAd().type:
		return { ...state, eha: action.data, status: { ...state.status, eha: { fetching: false, error: null } } };
	case eha.failedEmbedAd().type:
		return { ...state, eha: state.eha, status: { ...state.status, eha: { fetching: false, error: action.error } } };


		// LIFESTYLE_CATEGORIES
	case lifestyles.fetchLifestyleCategories().type:
		return { ...state, lifestyle_categories: state.lifestyle_categories, status: { ...state.status, lifestyle_categories: { fetching: true, error: null } } };
	case lifestyles.fetchedLifestyleCategories().type:
		return { ...state, lifestyle_categories: action.data, status: { ...state.status, lifestyle_categories: { fetching: false, error: null } } };
	case lifestyles.failedFetchLifestyleCategories().type:
		return { ...state, lifestyle_categories: state.lifestyle_categories, status: { ...state.status, lifestyle_categories: { fetching: false, error: action.error } } };


		// LIVE_RADIO
	case liveRadio.fetchLiveRadios().type:
		return { ...state, live_radios: state.live_radios, status: { ...state.status, live_radios: { fetching: true, error: null } } };
	case liveRadio.fetchedLiveRadios().type:
		return { ...state, live_radios: action.data, status: { ...state.status, live_radios: { fetching: false, error: null } } };
	case liveRadio.failedFetchLiveRadios().type:
		return { ...state, live_radios: state.live_radios, status: { ...state.status, live_radios: { fetching: false, error: action.error } } };


		// NOTIFICATIONS
	case notifications.fetchNotifications().type:
		return { ...state, notifications: state.notifications, status: { ...state.status, notifications: { fetching: true, error: null } } };
	case notifications.fetchedNotifications().type:
		return { ...state, notifications: action.data, status: { ...state.status, notifications: { fetching: false, error: null } } };
	case notifications.failedFetchNotifications().type:
		return { ...state, notifications: state.notifications, status: { ...state.status, notifications: { fetching: false, error: action.error } } };


		// VLOGS
	case vlogs.fetchVlogs().type:
		return { ...state, vlogs: state.vlogs, status: { ...state.status, vlogs: { fetching: true, error: null } } };
	case vlogs.fetchedVlogs().type:
		return { ...state, vlogs: action.data, status: { ...state.status, vlogs: { fetching: false, error: null } } };
	case vlogs.failedFetchVlogs().type:
		return { ...state, vlogs: state.vlogs, status: { ...state.status, vlogs: { fetching: false, error: action.error } } };


	case vlogs.fetchRandomVlog().type:
		return { ...state, vlog: state.vlog, status: { ...state.status, vlog: { fetching: true, error: null } } };
	case vlogs.fetchedRandomVlog().type:
		return { ...state, vlog: action.data, status: { ...state.status, vlog: { fetching: false, error: null } } };
	case vlogs.failedFetchRandomVlog().type:
		return { ...state, vlog: state.vlog, status: { ...state.status, vlog: { fetching: false, error: action.error } } };


		// EXTERNAL_API:COVID
	case external_api.fetchCovidStats().type:
		return { ...state, corona_metrics: state.corona_metrics, status: { ...state.status, corona_metrics: { fetching: true, error: null } } };
	case external_api.fetchedCovidStats().type:
		metrics = { ...state.corona_metrics };
		metrics[action.country] = action.data;
		return { ...state, corona_metrics: metrics, status: { ...state.status, corona_metrics: { fetching: false, error: null } } };
	case external_api.failedFetchCovidStats().type:
		return { ...state, corona_metrics: state.corona_metrics, status: { ...state.status, corona_metrics: { fetching: false, error: action.error } } };


		// CMS
	case cms.fetchCMS().type:
		return { ...state, cms: state.cms, status: { ...state.status, cms: { fetching: true, error: null } } };
	case cms.fetchedCMS().type:
		metrics = { ...state.cms };
		metrics[action.id] = action.data;
		return { ...state, cms: metrics, status: { ...state.status, cms: { fetching: false, error: null } } };
	case cms.failedFetchCMS().type:
		return { ...state, cms: state.cms, status: { ...state.status, cms: { fetching: false, error: action.error } } };


		// SHA
	case sha.fetchSHA().type:
		metrics = {};
		metrics[action.specs.id] = { fetching: true, error: null };
		return { ...state, sha: state.sha, status: { ...state.status, sha: metrics } };
	case sha.fetchedSHA().type:
		metrics = { ...state.sha };
		metrics[action.id] = action.data;
		return { ...state, sha: metrics, status: { ...state.status, sha: { fetching: false, error: null } } };
	case sha.failedFetchSHA().type:
		metrics = {};
		metrics[action.specs.id] = { fetching: false, error: action.error };
		return { ...state, sha: state.sha, status: { ...state.status, sha: metrics } };


		// Humans
	case humans.fetchHumans().type:
		return { ...state, humans: state.humans, status: { ...state.status, humans: { fetching: true, error: null } } };
	case humans.fetchedHumans().type:
		return { ...state, humans: action.data, status: { ...state.status, humans: { fetching: false, error: null } } };
	case humans.failedFetchHumans().type:
		return { ...state, humans: state.humans, status: { ...state.status, humans: { fetching: false, error: action.error } } };


		// Human
	case humans.fetchHuman().type:
		return { ...state, human: state.human, status: { ...state.status, humans: { fetching: true, error: null } } };
	case humans.fetchedHuman().type:
		return { ...state, human: action.data, status: { ...state.status, humans: { fetching: false, error: null } } };
	case humans.failedFetchHuman().type:
		return { ...state, human: state.human, status: { ...state.status, humans: { fetching: false, error: action.error } } };


		// GENERATE_INVOICE
	case invoices.generateInvoice().type:
		return { ...state, invoices: state.invoices, status: { ...state.status, invoices: { posting: true, error: null } } };
	case invoices.generatedInvoice().type:
		return { ...state, invoices: action.data, status: { ...state.status, invoices: { posting: false, error: null } } };
	case invoices.failedGenerateInvoice().type:
		return { ...state, invoices: state.invoices, status: { ...state.status, invoices: { posting: false, error: action.error } } };


		// DELETE_INVOICE
	case invoices.deleteInvoice().type:
		return { ...state, invoices: state.invoices, status: { ...state.status, invoices: { deleting: true, error: null } } };
	case invoices.deletedInvoice().type:
		return { ...state, invoices: action.data, status: { ...state.status, invoices: { deleting: false, error: null } } };
	case invoices.failedDeleteInvoice().type:
		return { ...state, invoices: state.invoices, status: { ...state.status, invoices: { deleting: false, error: action.error } } };


		// DOWNLOAD_INVOICE
	case invoices.downloadInvoice().type:
		return { ...state, download_invoice: state.download_invoice, status: { ...state.status, invoices: { downloading: true, error: null } } };
	case invoices.downloadedInvoice().type:
		return { ...state, download_invoice: action.data, status: { ...state.status, invoices: { downloading: false, error: null } } };
	case invoices.failedDownloadInvoice().type:
		return { ...state, download_invoice: state.download_invoice, status: { ...state.status, invoices: { downloading: false, error: action.error } } };


		// FETCH_INVOICE
	case invoices.fetchInvoices().type:
		return { ...state, invoices: state.invoices, status: { ...state.status, invoices: { fetching: true, error: null } } };
	case invoices.fetchedInvoices().type:
		return { ...state, invoices: action.data, status: { ...state.status, invoices: { fetching: false, error: null } } };
	case invoices.failedFetchInvoices().type:
		return { ...state, invoices: state.invoices, status: { ...state.status, invoices: { fetching: false, error: action.error } } };


		// ASHANTIS_ABROAD
	case ashantis_abroad.fetchAshantisAbroad().type:
		return { ...state, ashantis_abroad: state.ashantis_abroad, status: { ...state.status, ashantis_abroad: { fetching: true, error: null } } };
	case ashantis_abroad.fetchedAshantisAbroad().type:
		return { ...state, ashantis_abroad: action.data, status: { ...state.status, ashantis_abroad: { fetching: false, error: null } } };
	case ashantis_abroad.failedFetchAshantisAbroad().type:
		return { ...state, ashantis_abroad: state.ashantis_abroad, status: { ...state.status, ashantis_abroad: { fetching: false, error: action.error } } };


		// ASHANTIS_ABROAD
	case ashantis_abroad.fetchAshantiAbroad().type:
		return { ...state, ashanti_abroad: state.ashanti_abroad, status: { ...state.status, ashanti_abroad: { fetching: true, error: null } } };
	case ashantis_abroad.fetchedAshantiAbroad().type:
		return { ...state, ashanti_abroad: action.data, status: { ...state.status, ashanti_abroad: { fetching: false, error: null } } };
	case ashantis_abroad.failedFetchAshantiAbroad().type:
		return { ...state, ashanti_abroad: state.ashanti_abroad, status: { ...state.status, ashanti_abroad: { fetching: false, error: action.error } } };


		// RANKINGS
	case rankings.fetchRankings().type:
		return { ...state, rankings_categories: state.rankings_categories, status: { ...state.status, rankings_categories: { fetching: true, error: null } } };
	case rankings.fetchedRankings().type:
		return { ...state, rankings_categories: action.data, status: { ...state.status, rankings_categories: { fetching: false, error: null } } };
	case rankings.failedFetchRankings().type:
		return { ...state, rankings_categories: state.rankings_categories, status: { ...state.status, rankings_categories: { fetching: false, error: action.error } } };


		// RANKINGS_TA_CAT
	case rankings.fetchRankingsTaCat().type:
		return { ...state, rankings_ta_cat: state.rankings_ta_cat, status: { ...state.status, rankings_ta_cat: { fetching: true, error: null } } };
	case rankings.fetchedRankingsTaCat().type:
		return { ...state, rankings_ta_cat: action.data, status: { ...state.status, rankings_ta_cat: { fetching: false, error: null } } };
	case rankings.failedFetchRankingsTaCat().type:
		return { ...state, rankings_ta_cat: state.rankings_ta_cat, status: { ...state.status, rankings_ta_cat: { fetching: false, error: action.error } } };


		// RANKING
	case rankings.fetchRanking().type:
		return { ...state, ranking: state.ranking, status: { ...state.status, ranking: { fetching: true, error: null } } };
	case rankings.fetchedRanking().type:
		return { ...state, ranking: action.data, status: { ...state.status, ranking: { fetching: false, error: null } } };
	case rankings.failedFetchRanking().type:
		return { ...state, ranking: state.ranking, status: { ...state.status, ranking: { fetching: false, error: action.error } } };


		// MANAGED_CONTENT
	case managedContent.fetchManagedContent().type:
		return { ...state, managed_content: state.managed_content, status: { ...state.status, managed_content: { fetching: true, error: null } } };
	case managedContent.fetchedManagedContent().type:
		return { ...state, managed_content: action.data, status: { ...state.status, managed_content: { fetching: false, error: null } } };
	case managedContent.failedFetchManagedContent().type:
		return { ...state, managed_content: state.managed_content, status: { ...state.status, managed_content: { fetching: false, error: action.error } } };


		// FETCH_LIFESTYLES
	case lifestyles.fetchLifestyles().type:
		return { ...state, lifestyles: state.lifestyles, status: { ...state.status, lifestyles: { fetching: true, error: null } } };
	case lifestyles.fetchedLifestyles().type:
		return { ...state, lifestyles: action.data, status: { ...state.status, lifestyles: { fetching: false, error: null } } };
	case lifestyles.failedFetchLifestyles().type:
		return { ...state, lifestyles: state.lifestyles, status: { ...state.status, lifestyles: { fetching: false, error: action.error } } };


		// FETCH_LIFESTYLE
	case lifestyles.fetchLifestyle().type:
		return { ...state, lifestyle: state.lifestyle, status: { ...state.status, lifestyle: { fetching: true, error: null } } };
	case lifestyles.fetchedLifestyle().type:
		return { ...state, lifestyle: action.data, status: { ...state.status, lifestyle: { fetching: false, error: null } } };
	case lifestyles.failedFetchLifestyle().type:
		return { ...state, lifestyle: state.lifestyle, status: { ...state.status, lifestyle: { fetching: false, error: action.error } } };

		// MAGIC_TEMP
	case magicTemp.magicTemp().type:
		return { ...state, magic_temp: state.data, status: { ...state.status, magic_temp: { posting: true, error: null } } };
	case magicTemp.magicTempSuccess().type:
		return { ...state, magic_temp: action.data, status: { ...state.status, magic_temp: { posting: false, error: null } }, rating: action.data['my_rating'] };
	case magicTemp.failedMagicTemp().type:
		return { ...state, magic_temp: state.data, status: { ...state.status, magic_temp: { posting: false, error: action.error } } };

		// GLOBAL_HELPERS
	case globalHelpers.showedGlobalLogin().type:
		return { ...state, globalLogin: { show: true } };
	case globalHelpers.hidGlobalLogin().type:
		return { ...state, globalLogin: { show: false } };



		// USER
	case users.fetchUser().type:
		return { ...state, public_user: state.public_user, status: { ...state.status, public_user: { fetching: true, error: null } } };
	case users.fetchedUser().type:
		return { ...state, public_user: action.data, status: { ...state.status, public_user: { fetching: false, error: null } } };
	case users.failedFetchUser().type:
		return { ...state, public_user: state.public_user, status: { ...state.status, public_user: { fetching: false, error: action.error } } };



		// SUBSCRIBE_TO_EMAIL
	case auth.subscribeToEmail().type:
		return { ...state, userState: state.userState, status: { ...state.status, userState: { fetching: true, error: null } } };
	case auth.subscribedToEmail().type:
		return { ...state, userState: action.data, status: { ...state.status, userState: { fetching: false, error: null } } };
	case auth.failedSubscribeToEmail().type:
		return { ...state, userState: state.userState, status: { ...state.status, userState: { fetching: false, error: action.error } } };



		// UNSUBSCRIBE_FROM_EMAIL
	case auth.unsubscribeFromEmail().type:
		return { ...state, userState: state.userState, status: { ...state.status, userState: { fetching: true, error: null } } };
	case auth.unsubscribedFromEmail().type:
		return { ...state, userState: action.data, status: { ...state.status, userState: { fetching: false, error: null } } };
	case auth.failedUnsubscribeFromEmail().type:
		return { ...state, userState: state.userState, status: { ...state.status, userState: { fetching: false, error: action.error } } };



		// UPDATE_PROFILE
	case auth.updateProfile().type:
		return { ...state, userState: state.userState, status: { ...state.status, userState: { fetching: true, error: null } } };
	case auth.updatedProfile().type:
		return { ...state, userState: { ...state?.userState, ...action.data }, status: { ...state.status, userState: { fetching: false, error: null } } };
	case auth.failedUpdateProfile().type:
		return { ...state, userState: state.userState, status: { ...state.status, userState: { fetching: false, error: action.error } } };



		// FETCH_AUTH_USER
	case auth.fetchAuthUser().type:
		return { ...state, userState: state.userState, status: { ...state.status, userState: { fetching: true, error: null } } };
	case auth.fetchedAuthUser().type:
		return { ...state, userState: { ...state?.userState, ...action.data }, status: { ...state.status, userState: { fetching: false, error: null } } };
	case auth.failedFetchAuthUser().type:
		return { ...state, userState: state.userState, status: { ...state.status, userState: { fetching: false, error: action.error } } };



		// VERIFY_PHONE
	case auth.verifyPhone().type:
		return { ...state, userState: state.userState, status: { ...state.status, userState: { posting: true, error: null } } };
	case auth.verifiedPhone().type:
		return { ...state, userState: action.data, status: { ...state.status, userState: { posting: false, error: null } } };
	case auth.failedVerifyPhone().type:
		return { ...state, userState: state.userState, status: { ...state.status, userState: { posting: false, error: action.error } } };



		// RESEND_PHONE_VERIFICATION_CODE
	case auth.resendPhoneVerificationCode().type:
		return { ...state, phone_verification: state.phone_verification, status: { ...state.status, phone_verification: { posting: true, error: null } } };
	case auth.resentPhoneVerificationCode().type:
		return { ...state, phone_verification: action.data, status: { ...state.status, phone_verification: { posting: false, error: null } } };
	case auth.failedResendPhoneVerificationCode().type:
		return { ...state, phone_verification: state.phone_verification, status: { ...state.status, phone_verification: { posting: false, error: action.error } } };



		// CHANGE_PHONE_FOR_VERIFICATION
	case auth.changePhoneForVerification().type:
		return { ...state, change_phone_verification: state.change_phone_verification, status: { ...state.status, change_phone_verification: { posting: true, error: null } } };
	case auth.changedPhoneForVerification().type:
		return { ...state, change_phone_verification: action.data, status: { ...state.status, change_phone_verification: { posting: false, error: null } } };
	case auth.failedChangePhoneForVerification().type:
		return { ...state, change_phone_verification: state.change_phone_verification, status: { ...state.status, change_phone_verification: { posting: false, error: action.error } } };



		// FETCH_MESSAGES
	case messages.fetchMessages().type:
		return { ...state, messages: state.data, status: { ...state.status, messages: { fetching: true, error: null } } };
	case messages.fetchedMessages().type:
		return { ...state, messages: action.data, status: { ...state.status, messages: { fetching: false, error: null } } };
	case messages.failedFetchMessages().type:
		return { ...state, messages: state.data, status: { ...state.status, messages: { fetching: false, error: action.error } } };



		// SET_MESSAGES
	case messages.setUnreadMessages().type:
		return { ...state, unread_messages: action.data };



		// SEND_MESSAGE
	case messages.sendMessage().type:
		return { ...state, chats: state.chats, status: { ...state.status, chats: { posting: true, error: null } } };
	case messages.sentMessage().type:
		return { ...state, chats: action.data, status: { ...state.status, chats: { posting: false, completing: true, error: null } } };
	case messages.failedSendMessage().type:
		return { ...state, chats: state.chats, status: { ...state.status, chats: { posting: false, error: action.error } } };



		// CHAT
	case messages.fetchChat().type:
		return { ...state, chats: state.chats, status: { ...state.status, chats: { fetching: true, error: null } } };
	case messages.fetchedChat().type:
		return { ...state, chats: action.data, status: { ...state.status, chats: { fetching: false, error: null } } };
	case messages.failedFetchChat().type:
		return { ...state, chats: state.chats, status: { ...state.status, chats: { fetching: false, error: action.error } } };



		// MY_ADS
	case users.fetchMyAds().type:
		return { ...state, my_ads: state.my_ads, status: { ...state.status, my_ads: { fetching: true, error: null } } };
	case users.fetchedMyAds().type:
		return { ...state, my_ads: action.data, status: { ...state.status, my_ads: { fetching: false, error: null } } };
	case users.failedFetchMyAds().type:
		return { ...state, my_ads: state.my_ads, status: { ...state.status, my_ads: { fetching: false, error: action.error } } };



		// MY_SHOPS
	case users.fetchMyShops().type:
		return { ...state, my_shops: state.my_shops, status: { ...state.status, my_shops: { fetching: true, error: null } } };
	case users.fetchedMyShops().type:
		return { ...state, my_shops: action.data, status: { ...state.status, my_shops: { fetching: false, error: null } } };
	case users.failedFetchMyShops().type:
		return { ...state, my_shops: state.my_shops, status: { ...state.status, my_shops: { fetching: false, error: action.error } } };



		// MY_FAVORITES
	case users.fetchMyFavorites().type:
		return { ...state, my_favorites: state.my_favorites, status: { ...state.status, my_favorites: { fetching: true, error: null } } };
	case users.fetchedMyFavorites().type:
		return { ...state, my_favorites: action.data, status: { ...state.status, my_favorites: { fetching: false, error: null } } };
	case users.failedFetchMyFavorites().type:
		return { ...state, my_favorites: state.my_favorites, status: { ...state.status, my_favorites: { fetching: false, error: action.error } } };



		// POST_COMMENT
	case comments.postComment(null, null).type:
		return { ...state, comments: state.comments, status: { ...state.status, comments: { posting: true, error: null } } };
	case comments.postedComment().type:
		return { ...state, ...action.data };
	case comments.failedPostComment().type:
		return { ...state, comments: state.comments, status: { ...state.status, comments: { posting: false, error: action.error } } };



		// EDIT_COMMENT
	case comments.editComment(null, null).type:
		return { ...state, comments: state.comments, status: { ...state.status, comments: { posting: true, error: null } } };
	case comments.editedComment().type:
		return { ...state, ...action.data };
	case comments.failedEditComment().type:
		return { ...state, comments: state.comments, status: { ...state.status, comments: { posting: false, error: action.error } } };



		// DELETE_COMMENT
	case comments.deleteComment(null, null).type:
		return { ...state, comments: state.comments, status: { ...state.status, comments: { posting: true, error: null } } };
	case comments.deletedComment().type:
		return { ...state, ...action.data };
	case comments.failedDeleteComment().type:
		return { ...state, comments: state.comments, status: { ...state.status, comments: { posting: false, error: action.error } } };



		// FLAGS
	case flags.flagContent().type:
		return { ...state, flag: state.flag, status: { ...state.status, flag: { fetching: true, error: null } } };
	case flags.flaggedContent().type:
		return { ...state, flag: action.data, status: { ...state.status, flag: { fetching: false, error: null } } };
	case flags.failedFlagContent().type:
		return { ...state, flag: state.flag, status: { ...state.status, flag: { fetching: false, error: action.error } } };

		// FETCH_SEARCH_SUGGESTIONS
	case search.fetchSearchSuggestions().type:
		return { ...state, suggestions: null, status: { ...state.status, suggestions: { fetching: true, error: null } } };
	case search.fetchedSearchSuggestions().type:
		return { ...state, suggestions: action.data, status: { ...state.status, suggestions: { fetching: false, error: null } } };
	case search.failedFetchSearchSuggestions().type:
		return { ...state, suggestions: null, status: { ...state.status, suggestions: { fetching: false, error: action.error } } };


		// FETCH_PAGINATED_CONTENT
	case paginator.fetchPaginatedContent(null, null).type:
		return { ...state, status: action.status };
	case paginator.fetchedPaginatedContent().type:
		return { ...state, ...action, status: action.status };
	case paginator.failedFetchPaginatedContent().type:
		return { ...state, status: action.status };


		// SUBMIT_RATING
	case ratings.submitRating(null, null).type:
		return { ...state, status: { ...state.status, ratings: { reviewing: true, error: null, posted: false } } };
	case ratings.submittedRating().type:
		return { ...state, status: { ...state.status, ratings: { reviewing: false, error: null, posted: true } }, rating: action.data };
	case ratings.failedSubmitRating().type:
		return { ...state, status: { ...state.status, ratings: { reviewing: false, error: action.error, posted: false } } };


		// DO_FOLLOW
	case follows.doFollow().type:
		return { ...state, follow: action.payload, status: { ...state.status, follow: { posting: true, error: null, posted: false } } };
	case follows.didFollow().type:
		return { ...state, follow: action.data, status: { ...state.status, follow: { posting: false, error: null, posted: true } }, rating: action.data };
	case follows.failedDoFollow().type:
		return { ...state, follow: null, status: { ...state.status, follow: { posting: false, error: action.error, posted: false } } };


		// UNDO_FOLLOW
	case follows.undoFollow().type:
		return { ...state, follow: action.payload, status: { ...state.status, follow: { posting: true, error: null, posted: false } } };
	case follows.undidFollow().type:
		return { ...state, follow: action.data, status: { ...state.status, follow: { posting: false, error: null, posted: true } }, rating: action.data };
	case follows.failedUndoFollow().type:
		return { ...state, follow: null, status: { ...state.status, follow: { posting: false, error: action.error, posted: false } } };


		// DELETE_AD
	case ads.deleteAd().type:
		return { ...state, ...action.data };
	case ads.deletedAd().type:
		return { ...state, ...action.data };
	case ads.failedDeleteAd().type:
		return { ...state, ...action.data };


		// FETCH_SINGLE_AD
	case ads.fetchAd().type:
		return { ...state, ad: state.ad, status: { ...state.status, fetching: true, error: null } };
	case ads.fetchedAd().type:
		return { ...state, ad: action.data, status: { ...state.status, fetching: false, error: null }, rating: action.data['my_rating'] };
	case ads.failedFetchAd().type:
		return { ...state, ad: state.ad, status: { ...state.status, fetching: false, error: action.error } };


		// FETCH_MULTIPLE_ADS
	case ads.fetchMultipleAds().type:
		return { ...state, ads: state.ads, status: { ...state.status, ads: { fetching: true, error: null } } };
	case ads.fetchedMultipleAds().type:
		return { ...state, ads: action.data, status: { ...state.status, ads: { fetching: false, error: null } } };
	case ads.failedFetchMultipleAds().type:
		return { ...state, ads: state.ads, status: { ...state.status, ads: { fetching: false, error: action.error } } };


		// CREATE_AD
	case ads.createAd().type:
		return { ...state, status: { ...state.status, ad: { posting: true, error: null, posted: false } } };
	case ads.createdAd().type:
		return { ...state, ad: action.data, status: { ...state.status, ad: { posting: false, error: null, posted: true } } };
	case ads.failedCreateAd().type:
		return { ...state, status: { ...state.status, ad: { posting: false, error: action.error, posted: false } } };


		// UPDATE_AD
	case ads.updateAd(null, null).type:
		return { ...state, ...action.data, status: { ...state.status, ad: { posting: true, error: null, posted: false } } };
	case ads.updatedAd().type:
		return { ...state, ...action.data, status: { ...state.status, ad: { posting: false, error: null, posted: true } } };
	case ads.failedUpdateAd().type:
		return { ...state, ...action.error, status: { ...state.status, ad: { posting: false, error: action.error, posted: false } } };


		// FETCH_DISTRICTS
	case districts.fetchDistricts().type:
		return { ...state, districts: state.districts, currentDistrict: state.districts?.find(ds => ds?.slug == subdomain), status: { ...state.status, districts: { fetching: true, error: null } } };
	case districts.fetchedDistricts().type:
		return { ...state, districts: action.data, currentDistrict: action.data?.find(ds => ds?.slug == subdomain), status: { ...state.status, districts: { fetching: false, error: null } } };
	case districts.failedFetchDistricts().type:
		return { ...state, districts: state.districts, currentDistrict: state.districts?.find(ds => ds?.slug == subdomain), status: { ...state.status, districts: { fetching: false, error: action.error } } };


		// FETCH_DISTRICT_CLASSIFIED_ADS
	case districts.fetchDistrictClassifiedAds().type:
		return { ...state, ads: state.ads, status: { ...state.status, ads: { fetching: true, error: null } } };
	case districts.fetchedDistrictClassifiedAds().type:
		return { ...state, ads: action.data, status: { ...state.status, ads: { fetching: false, error: null } } };
	case districts.failedFetchDistrictClassifiedAds().type:
		return { ...state, ads: state.ads, status: { ...state.status, ads: { fetching: false, error: action.error } } };


		// FETCH_DISTRICT
	case districts.fetchDistrict().type:
		return { ...state, district: state.district, status: { ...state.status, district: { fetching: true, error: null } } };
	case districts.fetchedDistrict().type:
		return { ...state, district: action.data, status: { ...state.status, district: { fetching: false, error: null } } };
	case districts.failedFetchDistrict().type:
		return { ...state, district: state.district, status: { ...state.status, district: { fetching: false, error: action.error } } };


		// FETCH_SUBDIRECTORIES
	case directories.fetchSubDirectories().type:
		return { ...state, directory: state.directory, status: { ...state.status, directory: { fetching: true, error: null } } };
	case directories.fetchedSubDirectories().type:
		return { ...state, directory: action.data, status: { ...state.status, directory: { fetching: false, error: null } } };
	case directories.failedFetchSubDirectories().type:
		return { ...state, directory: state.directory, status: { ...state.status, directory: { fetching: false, error: action.error } } };


		// FETCH_SUBDIRECTORY
	case subdirectories.fetchSubDirectory().type:
		return { ...state, subdirectory: state.subdirectory, status: { ...state.status, subdirectory: { fetching: true, error: null } } };
	case subdirectories.fetchedSubDirectory().type:
		return { ...state, subdirectory: action.data, status: { ...state.status, subdirectory: { fetching: false, error: null } } };
	case subdirectories.failedFetchSubDirectory().type:
		return { ...state, subdirectory: state.subdirectory, status: { ...state.status, subdirectory: { fetching: false, error: action.error } } };


		// FETCH_SUBDIRECTORY_LISTINGS
	case directory_listings.fetchDirectoryListing().type:
		return { ...state, directory_listing: state.directory_listings, status: { ...state.status, directory_listing: { fetching: true, error: null } } };
	case directory_listings.fetchedDirectoryListing().type:
		return { ...state, directory_listing: action.data, status: { ...state.status, directory_listing: { fetching: false, error: null } } };
	case directory_listings.failedFetchDirectoryListing().type:
		return { ...state, directory_listing: state.directory_listings, status: { ...state.status, directory_listing: { fetching: false, error: action.error } } };


		// FETCH_DIRECTORIES
	case directories.fetchDirectories().type:
		return { ...state, directories: state.directories, status: { ...state.status, directories: { fetching: true, error: null } } };
	case directories.fetchedDirectories().type:
		return { ...state, directories: action.data, status: { ...state.status, directories: { fetching: false, error: null } } };
	case directories.failedFetchDirectories().type:
		return { ...state, directories: state.directories, status: { ...state.status, directories: { fetching: false, error: action.error } } };


		// FETCH_SINGLE_CLASSIFIED
	case classifieds.fetchClassify().type:
		return { ...state, single_classified: state.data, status: { ...state.status, fetching: true, error: null } };
	case classifieds.fetchedClassify().type:
		return { ...state, single_classified: action.data, status: { ...state.status, fetching: false, error: null } };
	case classifieds.failedFetchClassify().type:
		return { ...state, single_classified: state.data, status: { ...state.status, fetching: false, error: action.error } };


		// FETCH_CLASSIFIEDS
	case classifieds.fetchClassifieds().type:
		return { ...state, classifieds: state.data, status: { ...state.status, classifieds: { fetching: true, error: null } } };
	case classifieds.fetchedClassifieds().type:
		return { ...state, classifieds: [].concat(...action.data), status: { ...state.status, classifieds: { fetching: false, error: null } } };
	case classifieds.failedFetchClassifieds().type:
		return { ...state, classifieds: state.data, status: { ...state.status, classifieds: { fetching: false, error: action.error } } };


		// CREATE_CLASSIFIED
	case classifieds.createClassified().type:
		return { ...state, status: { ...state.status, posting: true, error: null, posted: false } };
	case classifieds.createdClassified().type:
		return { ...state, status: { ...state.status, posting: false, error: null, posted: true } };
	case classifieds.failedCreateClassified().type:
		return { ...state, status: { ...state.status, posting: false, error: action.error, posted: false } };


		// FETCH_SUBCLASSIFY
	case 'API_FETCH_SUBCLASSIFY':
		return { ...state, subclassifieds: state.data, status: { ...state.status, fetching: true, error: null } };
	case 'API_FETCHED_SUBCLASSIFY':
		return { ...state, subclassifieds: [].concat(...action.data), status: { ...state.status, fetching: false, error: null } };
	case 'API_FAILED_FETCH_SUBCLASSIFY':
		return { ...state, subclassifieds: state.data, status: { ...state.status, fetching: false, error: action.error } };


		// FETCH_SUBCLASSIFIEDS
	case 'API_FETCH_SUBCLASSIFIEDS':
		return { ...state, subclassifieds: state.data, status: { ...state.status, fetching: true, error: null } };
	case 'API_FETCHED_SUBCLASSIFIEDS':
		return { ...state, subclassifieds: [].concat(...action.data), status: { ...state.status, fetching: false, error: null } };
	case 'API_FAILED_FETCH_SUBCLASSIFIEDS':
		return { ...state, subclassifieds: state.data, status: { ...state.status, fetching: false, error: action.error } };


		// CREATE_SUBCLASSIFIED
	case 'API_CREATE_SUBCLASSIFIED':
		return { ...state, status: { ...state.status, posting: true, error: null, posted: false } };
	case 'API_CREATED_SUBCLASSIFIED':
		return { ...state, status: { ...state.status, posting: false, error: null, posted: true } };
	case 'API_FAILED_CREATE_SUBCLASSIFIED':
		return { ...state, status: { ...state.status, posting: false, error: action.error, posted: false } };


		// FETCH_NEWS_CATEGORIES
	case news.fetchNewsCategories().type:
		return { ...state, news_categories: state.data, status: { ...state.status, news_categories: { fetching: true, error: null } } };
	case news.fetchedNewsCategories().type:
		return { ...state, news_categories: action.data, status: { ...state.status, news_categories: { fetching: false, error: null } } };
	case news.failedFetchNewsCategories().type:
		return { ...state, news_categories: state.data, status: { ...state.status, news_categories: { fetching: false, error: action.error } } };


		// FETCH_SINGLE_NEWS
	case news.fetchSingleNews().type:
		return { ...state, news_item: state.data, status: { ...state.status, news_item: { fetching: true, error: null } } };
	case news.fetchedSingleNews().type:
		return { ...state, news_item: action.data, status: { ...state.status, news_item: { fetching: false, error: null } } };
	case news.failedFetchSingleNews().type:
		return { ...state, news_item: state.data, status: { ...state.status, news_item: { fetching: false, error: action.error } } };


		// FETCH_MULTIPLE_NEWS
	case news.fetchMultipleNews().type:
		return { ...state, news: state.data, status: { ...state.status, news: { fetching: true, error: null } } };
	case news.fetchedMultipleNews().type:
		return { ...state, news: action.data, status: { ...state.status, news: { fetching: false, error: null } } };
	case news.failedFetchMultipleNews().type:
		return { ...state, news: state.data, status: { ...state.status, news: { fetching: false, error: action.error } } };


		// FETCH_SHOP
	case shops.fetchShop().type:
		return { ...state, shop: state.data, status: { ...state.status, shop: { fetching: true, error: null } } };
	case shops.fetchedShop().type:
		return { ...state, shop: action.data, status: { ...state.status, shop: { fetching: false, error: null } } };
	case shops.failedFetchShop().type:
		return { ...state, shop: state.data, status: { ...state.status, shop: { fetching: false, error: action.error } } };


		// FETCH_SHOP_ACTIVITY
	case shops.fetchShopActivity().type:
		return { ...state, shop_activity: state.shop_activity, status: { ...state.status, shop_activity: { fetching: true, error: null } } };
	case shops.fetchedShopActivity().type:
		return { ...state, shop_activity: action.data, status: { ...state.status, shop_activity: { fetching: false, error: null } } };
	case shops.failedFetchShopActivity().type:
		return { ...state, shop_activity: state.shop_activity, status: { ...state.status, shop_activity: { fetching: false, error: action.error } } };


		// FETCH_MULTIPLE_SHOPS
	case shops.fetchMultipleShops().type:
		return { ...state, shops: state.data, status: { ...state.status, shops: { fetching: true, error: null } } };
	case shops.fetchedMultipleShops().type:
		return { ...state, shops: action.data, status: { ...state.status, shops: { fetching: false, error: null } } };
	case shops.failedFetchMultipleShops().type:
		return { ...state, shops: state.data, status: { ...state.status, shops: { fetching: false, error: action.error } } };


		// CREATE_SHOP
	case shops.createShop().type:
		return { ...state, shops: state.data, status: { ...state.status, shop: { posting: true, error: null } } };
	case shops.createdShop().type:
		return { ...state, shops: action.data, status: { ...state.status, shop: { posting: false, error: null } } };
	case shops.failedCreateShop().type:
		return { ...state, shops: state.data, status: { ...state.status, shop: { posting: false, error: action.error } } };


		// UPDATE_SHOP
	case shops.updateShop().type:
		return { ...state, shops: state.data, status: { ...state.status, shop: { posting: true, error: null } } };
	case shops.updatedShop().type:
		return { ...state, shops: action.data, status: { ...state.status, shop: { posting: false, error: null } } };
	case shops.failedUpdateShop().type:
		return { ...state, shops: state.data, status: { ...state.status, shop: { posting: false, error: action.error } } };


		// ASSIGN_MEMBER_ROLE
	case shops.assignRole().type:
		return { ...state, shop_member: state.shop, status: { ...state.status, shop_member: { fetching: true, error: null } } };
	case shops.assignedRole().type:
		return { ...state, shop_member: action.data, status: { ...state.status, shop_member: { fetching: false, error: null } } };
	case shops.failedAssignRole().type:
		return { ...state, shop_member: state.shop, status: { ...state.status, shop_member: { fetching: false, error: action.error } } };


		// REMOVE_MEMBER_ROLE
	case shops.removeRole().type:
		return { ...state, shop_member: state.shop, status: { ...state.status, shop_member: { fetching: true, error: null } } };
	case shops.removedRole().type:
		return { ...state, shop_member: action.data, status: { ...state.status, shop_member: { fetching: false, error: null } } };
	case shops.failedRemoveRole().type:
		return { ...state, shop_member: state.shop, status: { ...state.status, shop_member: { fetching: false, error: action.error } } };


		// CHANGE_MEMBER_ROLE
	case shops.changeRole().type:
		return { ...state, shop_member: state.shop, status: { ...state.status, shop_member: { fetching: true, error: null } } };
	case shops.changedRole().type:
		return { ...state, shop_member: action.data, status: { ...state.status, shop_member: { fetching: false, error: null } } };
	case shops.failedChangeRole().type:
		return { ...state, shop_member: state.shop, status: { ...state.status, shop_member: { fetching: false, error: action.error } } };


		// FETCH_NONE_MEMBERS
	case shops.fetchNoneMembers().type:
		return { ...state, shop_none_members: state.shop_none_members, status: { ...state.status, shop_none_members: { fetching: true, error: null } } };
	case shops.fetchedNoneMembers().type:
		return { ...state, shop_none_members: action.data, status: { ...state.status, shop_none_members: { fetching: false, error: null } } };
	case shops.failedFetchNoneMembers().type:
		return { ...state, shop_none_members: state.shop_none_members, status: { ...state.status, shop_none_members: { fetching: false, error: action.error } } };


		// ADD_SHOP_MEMBER
	case shops.addShopMember().type:
		return { ...state, new_shop_member: state.new_shop_member, status: { ...state.status, new_shop_member: { posting: true, error: null } } };
	case shops.addedShopMember().type:
		return { ...state, new_shop_member: action.data, status: { ...state.status, new_shop_member: { posting: false, error: null } } };
	case shops.failedAddShopMember().type:
		return { ...state, new_shop_member: state.new_shop_member, status: { ...state.status, new_shop_member: { posting: false, error: action.error } } };


		// AUTH_LOGIN
	case auth.logIn().type:
		return { ...state, userState: state.data, status: { ...state.status, isloggingin: true, isloggedin: false, error: null } };
	case auth.loggedIn().type:
		return { ...state, userState: action.data, status: { ...state.status, isloggingin: false, isloggedin: true, error: null }, globalLogin: { show: false } };
	case auth.afterLoggedIn().type:
		return { ...state, status: { ...state.status, isloggingin: false, isloggedin: null, error: null } };
	case auth.failedLogIn().type:
		return { ...state, userState: state.data, status: { ...state.status, isloggingin: false, isloggedin: false, error: action.error } };


		// AUTH_LOGOUT
	case auth.logOut().type:
		return { ...state, userState: state.data, status: { ...state.status, isloggingout: true, isloggedout: false, error: null } };
	case auth.loggedOut().type:
		return { ...state, userState: null, status: { ...state.status, isloggingout: false, isloggedout: true, error: null } };
	case auth.failedLogOut().type:
		return { ...state, userState: state.data, status: { ...state.status, isloggingout: false, isloggedout: false, error: action.error } };


		// SIGNUP
	case auth.signUp().type:
		return { ...state, data: state.data, status: { ...state.status, issigningup: true, issignedup: false, error: null } };
	case auth.signedUp().type:
		return { ...state, ...action.data };
	case auth.failedSignUp().type:
		return { ...state, data: state.data, status: { ...state.status, issigningup: false, issignedup: false, error: action.error } };


		// RESET_PASSWORD
	case auth.resetPassword().type:
		return { ...state, forgot_password: state.data, status: { ...state.status, forgot_password: { posting: true, error: null } } };
	case auth.didResetPassword().type:
		return { ...state, forgot_password: action.data, status: { ...state.status, forgot_password: { posting: false, error: null } } };
	case auth.failedResetPassword().type:
		return { ...state, forgot_password: state.data, status: { ...state.status, forgot_password: { posting: false, error: action.error } } };


		// CHANGE_PASSWORD
	case auth.changePassword().type:
		return { ...state, change_password: false, status: { ...state.status, change_password: { posting: true, error: null } } };
	case auth.changedPassword().type:
		return { ...state, change_password: action.data, status: { ...state.status, change_password: { posting: false, error: null } } };
	case auth.failedChangePassword().type:
		return { ...state, change_password: false, status: { ...state.status, change_password: { posting: false, error: action.error } } };


		// AUTHORIZE_RESET_PASSWORD
	case auth.authorizePasswordResetRequest().type:
		return { ...state, password_reset_request_authorized: false, status: { ...state.status, password_reset_request_authorized: { fetching: true, error: null } } };
	case auth.authorizedPasswordResetRequest().type:
		return { ...state, password_reset_request_authorized: action.data, status: { ...state.status, password_reset_request_authorized: { fetching: false, error: null } } };
	case auth.failedAuthorizePasswordResetRequest().type:
		return { ...state, password_reset_request_authorized: false, status: { ...state.status, password_reset_request_authorized: { fetching: false, error: action.error } } };


		// COMPLETE_RESET_PASSWORD
	case auth.completeResetPassword().type:
		return { ...state, complete_password_reset_request: state.data, status: { ...state.status, complete_password_reset_request: { posting: true, error: null } } };
	case auth.completedResetPassword().type:
		return { ...state, complete_password_reset_request: action.data, status: { ...state.status, complete_password_reset_request: { posting: false, error: null } } };
	case auth.failedCompleteResetPassword().type:
		return { ...state, complete_password_reset_request: state.data, status: { ...state.status, complete_password_reset_request: { posting: false, error: action.error } } };


		// SEND_EMAIL_CONFIRMATION_REQUEST
	case auth.sendConfirmEmailRequest().type:
		return { ...state, email_confirmed: false, status: { ...state.status, email_confirmed: { posting: true, error: null } } };
	case auth.sentConfirmEmailRequest().type:
		return { ...state, email_confirmed: action.data, status: { ...state.status, email_confirmed: { posting: false, error: null } } };
	case auth.failedSendConfirmEmailRequest().type:
		return { ...state, email_confirmed: false, status: { ...state.status, email_confirmed: { posting: false, error: action.error } } };


		// EMAIL_CONFIRMED
	case auth.emailConfirmed().type:
		return { ...state, email_confirmed: action.data };


		// DEFAULT!
	default:
		return state;
	}
};
