import React, { useMemo, useState } from "react";
import { locales } from "@pisell/utils";
import classNames from "classnames";
import "./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] = 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 = useMemo(() => {
		return list.length > MAX_LIMIT;
	}, [list]);
	/**
	* @title: 展开文案
	* @description:
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-01-30 17:08
	*/
	const viewAllText = useMemo(() => {
		if (maxLimit === MAX_LIMIT) return locales.getText("pisell2.text.view-all");
		return locales.getText("pisell2.text.view-less");
	}, [maxLimit]);
	const _list = useMemo(() => {
		let arr = [...list];
		let _maxLimit = maxLimit;
		if (list.length > _maxLimit) arr = arr.slice(0, _maxLimit);
		return arr;
	}, [list, maxLimit]);
	return /* @__PURE__ */ React.createElement("div", {
		className: classNames("pisell2-collapsible-list-wrap", className),
		style
	}, border ? /* @__PURE__ */ React.createElement("div", { className: "pisell2-collapsible-list-top-border" }) : null, /* @__PURE__ */ React.createElement("div", { className: "pisell2-collapsible-list" }, _list.map((d, i) => {
		return renderItem(d, i);
	})), showAll ? /* @__PURE__ */ React.createElement("div", {
		className: "pisell2-collapsible-list-view-all",
		onClick: (e) => {
			e.preventDefault();
			e.stopPropagation();
			handlePreviewAll();
		}
	}, viewAllText) : null);
};
//#endregion
export { CollapsibleList as default };
