//#region src/components/pagination/index.ts
function e(e) {
	if (typeof e == "string") {
		let t = document.querySelector(e);
		if (!t) throw Error(`Pagination: container not found for selector "${e}"`);
		return t;
	}
	return e;
}
var t = class {
	config;
	containerEl;
	rootEl;
	prevBtn;
	nextBtn;
	infoEl;
	currentPage;
	hasMore;
	destroyed = !1;
	constructor(t) {
		this.config = t, this.containerEl = e(t.container), this.currentPage = t.page ?? 1, this.hasMore = t.hasMore === !0, this.rootEl = document.createElement("div"), this.rootEl.className = "cmm-pagination", this.prevBtn = document.createElement("button"), this.prevBtn.className = "cmm-pagination__button", this.prevBtn.textContent = "Previous", this.prevBtn.addEventListener("click", this.handlePrev), this.infoEl = document.createElement("span"), this.infoEl.className = "cmm-pagination__info", this.nextBtn = document.createElement("button"), this.nextBtn.className = "cmm-pagination__button", this.nextBtn.textContent = "Next", this.nextBtn.addEventListener("click", this.handleNext), this.rootEl.appendChild(this.prevBtn), this.rootEl.appendChild(this.infoEl), this.rootEl.appendChild(this.nextBtn), this.containerEl.appendChild(this.rootEl), this.render();
	}
	setPage(e, t) {
		this.currentPage = e, t !== void 0 && (this.hasMore = t), this.render();
	}
	getPage() {
		return this.currentPage;
	}
	destroy() {
		this.destroyed || (this.destroyed = !0, this.prevBtn.removeEventListener("click", this.handlePrev), this.nextBtn.removeEventListener("click", this.handleNext), this.rootEl.parentNode && this.rootEl.parentNode.removeChild(this.rootEl));
	}
	render() {
		this.infoEl.textContent = `Page ${String(this.currentPage)}`, this.currentPage <= 1 ? (this.prevBtn.disabled = !0, this.prevBtn.classList.add("cmm-pagination__button--disabled")) : (this.prevBtn.disabled = !1, this.prevBtn.classList.remove("cmm-pagination__button--disabled")), this.hasMore ? (this.nextBtn.disabled = !1, this.nextBtn.classList.remove("cmm-pagination__button--disabled")) : (this.nextBtn.disabled = !0, this.nextBtn.classList.add("cmm-pagination__button--disabled"));
	}
	handlePrev = () => {
		this.currentPage > 1 && (--this.currentPage, this.render(), this.config.onPageChange && this.config.onPageChange(this.currentPage));
	};
	handleNext = () => {
		this.hasMore && (this.currentPage += 1, this.render(), this.config.onPageChange && this.config.onPageChange(this.currentPage));
	};
};
//#endregion
export { t as Pagination };

//# sourceMappingURL=index.js.map