Source: components/filter/filter-result/filter-result-element/pagination/product-pagination-default.js

import jQ from 'jquery';
import ProductPagination from "./product-pagination";
import Selector from "../../../../../helpers/selector";
import FilterApi from "../../../../../api/filter-api";
import Globals from "../../../../../helpers/globals";
import SearchResultPanelItem from '../search-result-panel-item';
import SearchResultPanels from '../search-result-panels';

/**
 * Product pagination default
 * @extends ProductPagination
 */
class ProductPaginationDefault extends ProductPagination {
	/**
	 * @constructs
	 */
	constructor() {
		super();
		this.$element = jQ(Selector.pagination);
		this.$buttomElement = jQ(Selector.bottomPagination);
		this.$productList = jQ(Selector.products);
	}

	/**
	 * Override this method in theme lib to build html for pagination default
	 */
	compileTemplate() {
		return '';
	}

	/**
	 * Return whether or not the pagination default is rendered
	 */
	isRender() {
		return this.data !== null; // SearchResultPanels.isPanelActive(SearchResultPanelItem.Enum.PRODUCT)
	}

	/**
	 * Render pagination - default type
	 */
	render() {
		jQ(Selector.pagination).html(this.compileTemplate());
	}

	/**
	 * Bind the events on the parination - default
	 */
	bindEvents() {
		// Display the pagination block
		this.$element.show();
		// Unbind default event on pagination
		this.$element.find('a').unbind('click');
		this.$element.find('a').on('click', this._onClickEvent.bind(this));
	}

	/**
	 * Bind the click event on the pagination link
	 */
	_onClickEvent(event) {
		event.preventDefault();
		Globals.internalClick = true;
		// Get the pagination link
		var pageUrl = jQ(event.currentTarget).attr('href');
		// Apply filter
		FilterApi.updateParamsFromUrl(pageUrl);
		FilterApi.applyFilter('page');
		// Scroll to top of product list
		jQ('body,html').animate({
			scrollTop: this.$productList.offset().top - 50
		}, 600);
	}
}

export default ProductPaginationDefault;