import React from 'react';
import { getClassName } from '@appbaseio/reactivecore/lib/utils/helper';
import types from '@appbaseio/reactivecore/lib/utils/types';
import ImpressionTracker from './ImpressionTracker';

const Results = ({
	filteredResults,
	hasCustomRender,
	listClass,
	innerClass,
	renderItem,
	getComponent,
	triggerClickAnalytics,
	base,
	analytics,
}) => {
	const resultElement = () =>
		(hasCustomRender ? (
			getComponent()
		) : (
			<div className={`${listClass} ${getClassName(innerClass, 'list')}`}>
				{filteredResults.map((item, index) => (
					// Add document id to track the `impressions`
					<span id={item._id}>
						{renderItem(item, () => {
							triggerClickAnalytics(base + index);
						})}
					</span>
				))}
			</div>
		));
	// If analytics is set to true then render with impression tracker
	if (analytics) {
		return <ImpressionTracker hits={filteredResults}>{resultElement()}</ImpressionTracker>;
	}
	return resultElement();
};

Results.propTypes = {
	hasCustomRender: types.boolRequired,
	innerClass: types.style,
	renderItem: types.func,
	base: types.number,
	getComponent: types.func,
	listClass: types.string,
	filteredResults: types.hits,
	triggerClickAnalytics: types.func,
	analytics: types.bool,
};

export default Results;

@@ -563,94 +563,8 @@
  =%3E 
-(%0A%09%09%09%09%09// Add document id to track the %60impressions%60%0A%09%09%09%09%09%3Cspan id=%7Bitem._id%7D%3E%0A%09%09%09%09%09%09%7B
 rend
@@ -584,18 +584,16 @@
 () =%3E %7B%0A
-%09%09
 %09%09%09%09%09tri
@@ -634,31 +634,9 @@
 %09%09%09%09
-%09%09%7D)%7D%0A%09%09%09%09%09%3C/span%3E%0A%09%09%09%09
+%7D
 ))%7D%0A

remove additonal span element from renderItem #1547