// https://gist.github.com/dropfen/4a2209d7274788027f782e8655be198f
import Ionicons from 'react-native-vector-icons/Ionicons';
import { color } from './variables';

const defaultIconProvider = Ionicons;

const replaceSuffixPattern = /--(active|xs|sm|lg|xl)/g;
const icons = {
	'ios-menu': [30, color.blue],
	'ios-close': [50, color.blue],
	'ios-arrow-back': [50, color.blue],
};

const iconsMap = {};
const iconsLoaded = new Promise((resolve, reject) => {
	Promise.all(Object.keys(icons).map(iconName => {
		const Provider = icons[iconName][2] || defaultIconProvider; // Ionicons
		return Provider.getImageSource(
			iconName.replace(replaceSuffixPattern, ''),
			icons[iconName][0],
			icons[iconName][1],
		);
	})).then(sources => {
		Object.keys(icons)
			.forEach((iconName, idx) => {
				iconsMap[iconName] = sources[idx];
			});
		resolve(true);
	}).catch((error) => {
		reject(error);
	});
});

export {
	iconsMap,
	iconsLoaded,
};
