function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useState, useRef, useEffect } from 'react';
import { PisellCard } from '@pisell/materials';
import { PisellText } from '@pisell/materials';
import { locales } from '@pisell/utils';
import classNames from 'classnames';
import { mock } from "../../mock";
import "./index.less";
var EventCard = function EventCard(_ref) {
  var data = _ref.data,
    _ref$showTitle = _ref.showTitle,
    showTitle = _ref$showTitle === void 0 ? true : _ref$showTitle,
    _ref$showSubtitle = _ref.showSubtitle,
    showSubtitle = _ref$showSubtitle === void 0 ? true : _ref$showSubtitle,
    _ref$showDescription = _ref.showDescription,
    showDescription = _ref$showDescription === void 0 ? true : _ref$showDescription,
    _ref$showPrice = _ref.showPrice,
    showPrice = _ref$showPrice === void 0 ? true : _ref$showPrice,
    _ref$showOriginalPric = _ref.showOriginalPrice,
    showOriginalPrice = _ref$showOriginalPric === void 0 ? true : _ref$showOriginalPric,
    className = _ref.className,
    style = _ref.style;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    expanded = _useState2[0],
    setExpanded = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    showToggle = _useState4[0],
    setShowToggle = _useState4[1];
  var descriptionRef = useRef(null);
  var event_card = mock.event_card;
  var _ref2 = data || event_card,
    title = _ref2.title,
    subtitle = _ref2.subtitle,
    description = _ref2.description,
    price = _ref2.price,
    origin_price = _ref2.origin_price;

  /**
   * @title: 检查文本是否超过两行
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-09 16:43
   */
  useEffect(function () {
    var element = descriptionRef.current;
    var checkLineCount = function checkLineCount() {
      if (element) {
        var _window$getComputedSt;
        var lineHeight = parseInt((_window$getComputedSt = window.getComputedStyle(element)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.lineHeight);
        var height = element === null || element === void 0 ? void 0 : element.scrollHeight;
        var lines = Math.floor(height / lineHeight);
        setShowToggle(lines > 2);
      }
    };
    checkLineCount();
    window.addEventListener('resize', checkLineCount);
    return function () {
      return window.removeEventListener('resize', checkLineCount);
    };
  }, [description]);
  return /*#__PURE__*/React.createElement(PisellCard, {
    className: classNames('pisell-event-card', className),
    style: 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: function onClick() {
      return setExpanded(!expanded);
    }
  }, expanded ? locales.getText('pisell2.event.view.less') : locales.getText('pisell2.event.view.more'))))));
};
export default EventCard;