Source: components/filter/filter-result/collection/collection-list.js

import jQ from 'jquery';
import BaseComponent from "../../../base-component";
import SearchResultPanelItem from "../filter-result-element/search-result-panel-item";
import Selector from '../../../../helpers/selector';
import SearchResultPanels from '../filter-result-element/search-result-panels';
import CollectionItemList from './collection-item-list';

/**
 * Search page display: Collection list
 * @extends BaseComponent
 */
class CollectionList extends BaseComponent {
	constructor() {
		super();
		this.$element = jQ(Selector.collections);
		this.data = null;
		this.totalCollection = 0;
		this.settings = {
			searchPanelBlocks: Settings.getSettingValue('search.searchPanelBlocks')
		};
		this.panelData = {};
		if (this.settings.searchPanelBlocks.hasOwnProperty(SearchResultPanelItem.Enum.COLLECTION)) {
			this.panelData = this.settings.searchPanelBlocks[SearchResultPanelItem.Enum.COLLECTION];
		}
	}

	isRender() {
		return this.data != null && SearchResultPanels.isPanelActive(SearchResultPanelItem.Enum.COLLECTION);
	}

	render() {
		var collectionEls = [];
		// Get all collection item
		this.collectionItems.forEach((collectionItem) => {
			collectionEls.push(collectionItem.$element);
		});

		this.$element.html('');
		this.$element.append(collectionEls);
	}

	setData(data) {
		if (data && data.collections && data.collections.length) {
			this.data = data.collections;
			this.totalCollection = data.total_collection? data.total_collection : 0;
			this.collectionItems = [];
			this.data.forEach((collectionData, index) => {
				var collectionItem = new CollectionItemList();
				this.addComponent(collectionItem);
				collectionItem.setData(collectionData);
				this.collectionItems.push(collectionItem);
			});
		}
	}
}

export default CollectionList;