const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./index.less");
//#region src/components/booking/components/collapsibleList/index.tsx
const MAX_LIMIT = 3;
const CollapsibleList = (props) => {
	const { list = [], renderItem, className, style, border } = props;
	const [maxLimit, setMaxLimit] = (0, react.useState)(MAX_LIMIT);
	/**
	* @title: 展开和收起
	* @description:
	* @param {any} d
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 17:08
	*/
	const handlePreviewAll = () => {
		let _maxLimit = maxLimit;
		if (_maxLimit === MAX_LIMIT) _maxLimit = 99;
		else _maxLimit = MAX_LIMIT;
		setMaxLimit(_maxLimit);
	};
	/**
	* @title: 是否展开全部
	* @description:
	* @param {*} useMemo
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 17:08
	*/
	const showAll = (0, react.useMemo)(() => {
		return list.length > MAX_LIMIT;
	}, [list]);
	/**
	* @title: 展开文案
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 17:08
	*/
	const viewAllText = (0, react.useMemo)(() => {
		if (maxLimit === MAX_LIMIT) return _pisell_utils.locales.getText("pisell2.text.view-all");
		return _pisell_utils.locales.getText("pisell2.text.view-less");
	}, [maxLimit]);
	const _list = (0, react.useMemo)(() => {
		let arr = [...list];
		let _maxLimit = maxLimit;
		if (list.length > _maxLimit) arr = arr.slice(0, _maxLimit);
		return arr;
	}, [list, maxLimit]);
	return /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("pisell2-collapsible-list-wrap", className),
		style
	}, border ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell2-collapsible-list-top-border" }) : null, /* @__PURE__ */ react.default.createElement("div", { className: "pisell2-collapsible-list" }, _list.map((d, i) => {
		return renderItem(d, i);
	})), showAll ? /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell2-collapsible-list-view-all",
		onClick: (e) => {
			e.preventDefault();
			e.stopPropagation();
			handlePreviewAll();
		}
	}, viewAllText) : null);
};
//#endregion
exports.default = CollapsibleList;
