var _excluded = ["dataSource", "mode", "showImage", "showTitle", "showSubtitle", "showLocation", "showContact", "direction", "shape", "size", "useTextAvatar", "className", "style", "onClick"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import { PisellCard, PisellText, PisellAvatar, Image } from '@pisell/materials';
import classNames from 'classnames';
import defaultImage from "../../assets/image.svg";
import calendarHeartSvg from "../../assets/calendar-heart.svg";
import compassSvg from "../../assets/compass.svg";
import phoneSvg from "../../assets/phone.svg";
import { mock } from "../../mock";
import "./index.less";
var PisellResourceCard = function PisellResourceCard(_ref) {
  var dataSource = _ref.dataSource,
    _ref$mode = _ref.mode,
    mode = _ref$mode === void 0 ? 'normal' : _ref$mode,
    _ref$showImage = _ref.showImage,
    showImage = _ref$showImage === void 0 ? true : _ref$showImage,
    _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$showLocation = _ref.showLocation,
    showLocation = _ref$showLocation === void 0 ? true : _ref$showLocation,
    _ref$showContact = _ref.showContact,
    showContact = _ref$showContact === void 0 ? true : _ref$showContact,
    _ref$direction = _ref.direction,
    direction = _ref$direction === void 0 ? 'horizontal' : _ref$direction,
    _ref$shape = _ref.shape,
    shape = _ref$shape === void 0 ? 'circle' : _ref$shape,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? 'xxl' : _ref$size,
    _ref$useTextAvatar = _ref.useTextAvatar,
    useTextAvatar = _ref$useTextAvatar === void 0 ? false : _ref$useTextAvatar,
    className = _ref.className,
    style = _ref.style,
    onClick = _ref.onClick,
    rest = _objectWithoutProperties(_ref, _excluded);
  var resource_display = mock.resource_display;
  var _ref2 = dataSource || resource_display,
    image = _ref2.image,
    title = _ref2.title,
    subtitle = _ref2.subtitle,
    location = _ref2.location,
    contact = _ref2.contact;

  /**
   * @title: 渲染头像
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-09 20:57
   */
  var renderAvatar = function renderAvatar() {
    if (!showImage) return null;
    return /*#__PURE__*/React.createElement(PisellAvatar, {
      src: image || undefined,
      shape: shape,
      size: size,
      useTextAvatar: !image,
      children: (rest === null || rest === void 0 ? void 0 : rest.children) || /*#__PURE__*/React.createElement(Image, {
        src: defaultImage,
        preview: false
      }),
      className: classNames({
        'pisell-resource-card-campus-avatar': mode === 'campus',
        'pisell-resource-card-empty-avatar': !image
      })
    });
  };

  /**
   * @title: 校区列表
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-09 21:22
   */
  var campusLists = function campusLists() {
    var lists = [];
    if (showTitle && title) {
      lists.push({
        key: 'title',
        value: title,
        icon: calendarHeartSvg
      });
    }
    if (showLocation && location) {
      lists.push({
        key: 'location',
        value: location,
        icon: compassSvg
      });
    }
    if (showContact && contact) {
      lists.push({
        key: 'contact',
        value: contact,
        icon: phoneSvg
      });
    }
    return lists;
  };

  /**
   * @title: 渲染内容
   * @description:
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-09 21:02
   */
  var renderContent = function renderContent() {
    if (mode !== 'campus') {
      return /*#__PURE__*/React.createElement(React.Fragment, null, showTitle && title && /*#__PURE__*/React.createElement(PisellText, {
        className: "pisell-resource-card-name"
      }, title), showSubtitle && subtitle && /*#__PURE__*/React.createElement(PisellText, {
        className: "pisell-resource-card-subtitle"
      }, subtitle));
    }

    // 校区
    return /*#__PURE__*/React.createElement("div", {
      className: "pisell-resource-card-campus-wrap"
    }, campusLists().map(function (_ref3) {
      var key = _ref3.key,
        value = _ref3.value,
        icon = _ref3.icon;
      return /*#__PURE__*/React.createElement("div", {
        className: "pisell-resource-card-campus-item",
        key: key
      }, /*#__PURE__*/React.createElement(Image, {
        src: icon,
        preview: false
      }), /*#__PURE__*/React.createElement(PisellText, null, value));
    }));
  };
  return /*#__PURE__*/React.createElement(PisellCard, _extends({
    className: classNames('pisell-resource-card', "pisell-resource-card-".concat(direction), className),
    style: style,
    onClick: onClick
  }, rest), /*#__PURE__*/React.createElement("div", {
    className: "pisell-resource-card-content"
  }, renderAvatar(), /*#__PURE__*/React.createElement("div", {
    className: "pisell-resource-card-info"
  }, renderContent())));
};
export default PisellResourceCard;