import { mock } from "../../mock.js";
import React, { useEffect, useRef, useState } from "react";
import { locales } from "@pisell/utils";
import { PisellCard, PisellText } from "@pisell/materials";
import classNames from "classnames";
import "./index.less";
//#region src/components/eventBooking/components/eventCard/index.tsx
const EventCard = ({ data, showTitle = true, showSubtitle = true, showDescription = true, showPrice = true, showOriginalPrice = true, className, style }) => {
	const [expanded, setExpanded] = useState(false);
	const [showToggle, setShowToggle] = useState(false);
	const descriptionRef = useRef(null);
	const { event_card } = mock;
	const { title, subtitle, description, price, origin_price } = data || event_card;
	/**
	* @title: 检查文本是否超过两行
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-09 16:43
	*/
	useEffect(() => {
		const element = descriptionRef.current;
		const checkLineCount = () => {
			if (element) {
				var _window$getComputedSt;
				const lineHeight = parseInt((_window$getComputedSt = window.getComputedStyle(element)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.lineHeight);
				const height = element === null || element === void 0 ? void 0 : element.scrollHeight;
				setShowToggle(Math.floor(height / lineHeight) > 2);
			}
		};
		checkLineCount();
		window.addEventListener("resize", checkLineCount);
		return () => window.removeEventListener("resize", checkLineCount);
	}, [description]);
	return /* @__PURE__ */ React.createElement(PisellCard, {
		className: classNames("pisell-event-card", className),
		style,
		borderRadius: 10,
		isClickable: false
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell-event-card-content" }, /* @__PURE__ */ React.createElement("div", { className: "pisell-event-card-title-wrapper" }, showTitle && /* @__PURE__ */ React.createElement(PisellText, { className: "pisell-event-card-title" }, title), showSubtitle && /* @__PURE__ */ React.createElement(PisellText, { className: "pisell-event-card-subtitle" }, subtitle)), showPrice && /* @__PURE__ */ React.createElement("div", { className: "pisell-event-card-price-wrapper" }, /* @__PURE__ */ React.createElement(PisellText.Amount, {
		className: "pisell-event-card-price",
		value: price,
		precision: 2,
		showCurrencySymbol: true
	}), showOriginalPrice && origin_price && price !== origin_price && /* @__PURE__ */ React.createElement(PisellText.Amount, {
		className: "pisell-event-card-original-price",
		value: origin_price,
		precision: 2,
		showCurrencySymbol: true
	})), showDescription && description && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "pisell-event-card-line" }), /* @__PURE__ */ React.createElement("div", { className: "pisell-event-card-description" }, /* @__PURE__ */ React.createElement(PisellText, { className: "pisell-event-card-description-title" }, locales.getText("pisell2.event.description")), /* @__PURE__ */ React.createElement("div", {
		ref: descriptionRef,
		className: classNames("pisell-event-card-description-content", { "pisell-event-card-description-collapsed": !expanded && showToggle })
	}, /* @__PURE__ */ React.createElement("div", { dangerouslySetInnerHTML: { __html: description } })), showToggle && /* @__PURE__ */ React.createElement(PisellText, {
		className: "pisell-event-card-description-toggle",
		onClick: () => setExpanded(!expanded)
	}, expanded ? locales.getText("pisell2.event.view.less") : locales.getText("pisell2.event.view.more"))))));
};
//#endregion
export { EventCard as default };
