import { CircularProgress as CircularProgress$1 } from "../../loading/CircularProgress.mjs";
import { PaginationPlacement } from "./enum.mjs";
import { c } from "react-compiler-runtime";
import React, { useState } from "react";
import { makeStyles } from "@material-ui/core";
import clsx from "clsx";
import PropTypes from "prop-types";
import Pagination from "@material-ui/lab/Pagination";
//#region src/UI/dataDisplay/cardList/CardList.jsx
const useStyles = makeStyles(() => ({
	paginationWrapper: { display: "flex" },
	centerPagination: { justifyContent: "center" },
	rightPagination: { justifyContent: "flex-end" }
}));
const CardList = (t0) => {
	const $ = c(29);
	const { itemComponent: ItemComponent, data: t1, componentDataMap, pagination: t2, itemsPerPage: t3, isServerSide: t4, totalItems: t5, onPageChange: t6, currentPage: t7, isLoading: t8, paginationPlacement: t9 } = t0;
	let t10;
	if ($[0] !== t1) {
		t10 = t1 === void 0 ? [] : t1;
		$[0] = t1;
		$[1] = t10;
	} else t10 = $[1];
	const data = t10;
	const pagination = t2 === void 0 ? false : t2;
	const itemsPerPage = t3 === void 0 ? 10 : t3;
	const isServerSide = t4 === void 0 ? false : t4;
	const totalItems = t5 === void 0 ? 0 : t5;
	const onPageChange = t6 === void 0 ? null : t6;
	const currentPage = t7 === void 0 ? 1 : t7;
	const isLoading = t8 === void 0 ? false : t8;
	const paginationPlacement = t9 === void 0 ? PaginationPlacement.LEFT : t9;
	const [clientPage, setClientPage] = useState(1);
	const classes = useStyles();
	const page = isServerSide ? currentPage : clientPage;
	let t11;
	if ($[2] !== data) {
		t11 = Array.isArray(data) ? data : [];
		$[2] = data;
		$[3] = t11;
	} else t11 = $[3];
	const safeData = t11;
	let t12;
	if ($[4] !== isServerSide || $[5] !== itemsPerPage || $[6] !== page || $[7] !== pagination || $[8] !== safeData) {
		t12 = pagination && !isServerSide ? safeData.slice((page - 1) * itemsPerPage, page * itemsPerPage) : safeData;
		$[4] = isServerSide;
		$[5] = itemsPerPage;
		$[6] = page;
		$[7] = pagination;
		$[8] = safeData;
		$[9] = t12;
	} else t12 = $[9];
	const paginatedData = t12;
	let t13;
	if ($[10] !== isServerSide || $[11] !== onPageChange) {
		t13 = (event, value) => {
			if (isServerSide) onPageChange(value);
			else setClientPage(value);
		};
		$[10] = isServerSide;
		$[11] = onPageChange;
		$[12] = t13;
	} else t13 = $[12];
	const handlePageChange = t13;
	let t14;
	if ($[13] !== componentDataMap) {
		t14 = (item) => {
			const props = {};
			for (const [key, value_0] of Object.entries(componentDataMap)) props[value_0] = item[key];
			return props;
		};
		$[13] = componentDataMap;
		$[14] = t14;
	} else t14 = $[14];
	const mappedData = t14;
	let t15;
	if ($[15] !== ItemComponent || $[16] !== classes || $[17] !== handlePageChange || $[18] !== isLoading || $[19] !== isServerSide || $[20] !== itemsPerPage || $[21] !== mappedData || $[22] !== page || $[23] !== paginatedData || $[24] !== pagination || $[25] !== paginationPlacement || $[26] !== safeData || $[27] !== totalItems) {
		t15 = /* @__PURE__ */ React.createElement("div", null, isLoading ? /* @__PURE__ */ React.createElement(CircularProgress$1, null) : /* @__PURE__ */ React.createElement(React.Fragment, null, paginatedData.map((item_0, index) => /* @__PURE__ */ React.createElement(ItemComponent, {
			key: index,
			...mappedData(item_0)
		})), pagination && /* @__PURE__ */ React.createElement("div", { className: clsx(classes.paginationWrapper, {
			[classes.centerPagination]: paginationPlacement === PaginationPlacement.CENTER,
			[classes.rightPagination]: paginationPlacement === PaginationPlacement.RIGHT
		}) }, /* @__PURE__ */ React.createElement(Pagination, {
			count: Math.ceil(isServerSide ? totalItems / itemsPerPage : safeData.length / itemsPerPage),
			page,
			onChange: handlePageChange,
			disabled: isLoading
		}))));
		$[15] = ItemComponent;
		$[16] = classes;
		$[17] = handlePageChange;
		$[18] = isLoading;
		$[19] = isServerSide;
		$[20] = itemsPerPage;
		$[21] = mappedData;
		$[22] = page;
		$[23] = paginatedData;
		$[24] = pagination;
		$[25] = paginationPlacement;
		$[26] = safeData;
		$[27] = totalItems;
		$[28] = t15;
	} else t15 = $[28];
	return t15;
};
CardList.propTypes = {
	itemComponent: PropTypes.elementType.isRequired,
	data: PropTypes.arrayOf(PropTypes.object),
	componentDataMap: PropTypes.objectOf(PropTypes.string).isRequired,
	pagination: PropTypes.bool,
	itemsPerPage: PropTypes.number,
	isServerSide: PropTypes.bool,
	totalItems: PropTypes.number,
	onPageChange: PropTypes.func,
	currentPage: PropTypes.number,
	isLoading: PropTypes.bool,
	paginationPlacement: PropTypes.string
};
CardList.defaultProps = {
	data: [],
	pagination: false,
	itemsPerPage: 10,
	isServerSide: false,
	totalItems: 0,
	onPageChange: null,
	currentPage: 1,
	isLoading: false,
	paginationPlacement: PaginationPlacement.LEFT
};
//#endregion
export { CardList };

//# sourceMappingURL=CardList.mjs.map