import _ from 'lodash';
import DeviceInfo from 'react-native-device-info';

const getFreeDiskStorage = (done) => {
	if (_.has(DeviceInfo, 'getFreeDiskStorage') && _.isFunction(DeviceInfo.getFreeDiskStorage)) {
		const result = DeviceInfo.getFreeDiskStorage();
		if (_.isNumber(result)) return done(result);
		if (_.has(result, 'then')) return result.then(done);
	}
	return done(NaN);
};

export default getFreeDiskStorage;
