function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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); }
import React, { useMemo } from 'react';
import classNames from 'classnames';
import { Tag } from 'antd';
import { PisellAvatar } from '@pisell/materials';
import ClientName from "../../clientName";
import { getAvatarText } from "../utils";
import "./index.less";
import { PREFIX } from "../../clientCard";

/**
 * 客户卡片组件 - 行内布局
 * 所有信息在一行展示：头像、客户名、联系方式（电话优先于邮箱）、标签
 */
var LineCard = function LineCard(_ref) {
  var dataSource = _ref.dataSource,
    isShowName = _ref.isShowName,
    _ref$isShowAvatar = _ref.isShowAvatar,
    isShowAvatar = _ref$isShowAvatar === void 0 ? true : _ref$isShowAvatar,
    _ref$isShowPhone = _ref.isShowPhone,
    isShowPhone = _ref$isShowPhone === void 0 ? true : _ref$isShowPhone,
    _ref$isShowEmail = _ref.isShowEmail,
    isShowEmail = _ref$isShowEmail === void 0 ? true : _ref$isShowEmail,
    _ref$isShowStatus = _ref.isShowStatus,
    isShowStatus = _ref$isShowStatus === void 0 ? false : _ref$isShowStatus,
    _ref$style = _ref.style,
    customStyle = _ref$style === void 0 ? {} : _ref$style,
    horizontalGap = _ref.horizontalGap,
    _ref$avatar = _ref.avatar,
    avatar = _ref$avatar === void 0 ? {} : _ref$avatar,
    _ref$status = _ref.status,
    status = _ref$status === void 0 ? {} : _ref$status,
    _ref$nameStyle = _ref.nameStyle,
    nameStyle = _ref$nameStyle === void 0 ? {} : _ref$nameStyle,
    _ref$tags = _ref.tags,
    tags = _ref$tags === void 0 ? [] : _ref$tags,
    _ref$tag = _ref.tag,
    tag = _ref$tag === void 0 ? {} : _ref$tag,
    slots = _ref.slots,
    onViewClient = _ref.onViewClient;
  // 获取联系方式（电话优先于邮箱）
  var contactText = useMemo(function () {
    if (!dataSource) return '';
    var phone = dataSource.phone,
      email = dataSource.email;
    if (isShowPhone && phone) return phone;
    if (isShowEmail && email) return email;
    return '';
  }, [dataSource, isShowPhone, isShowEmail]);

  // 渲染头像
  var renderAvatar = function renderAvatar() {
    if (!isShowAvatar || !dataSource) return null;
    var icon = avatar.icon,
      _avatar$shape = avatar.shape,
      shape = _avatar$shape === void 0 ? 'circle' : _avatar$shape,
      _avatar$borderRadius = avatar.borderRadius,
      borderRadius = _avatar$borderRadius === void 0 ? 4 : _avatar$borderRadius,
      _avatar$size = avatar.size,
      size = _avatar$size === void 0 ? 'sm' : _avatar$size,
      _avatar$useTextAvatar = avatar.useTextAvatar,
      useTextAvatar = _avatar$useTextAvatar === void 0 ? false : _avatar$useTextAvatar,
      children = avatar.children;
    var avatarProps = {
      shape: shape,
      size: size,
      className: "".concat(PREFIX, "__avatar")
    };
    if (shape === 'square') {
      avatarProps.style = {
        borderRadius: borderRadius
      };
    }

    // 状态指示器
    var statusIndicator = isShowStatus && /*#__PURE__*/React.createElement("div", {
      className: "".concat(PREFIX, "__status-indicator"),
      style: {
        backgroundColor: status.color || '#17B26A'
      }
    });
    if (useTextAvatar) {
      var text = children || getAvatarText(dataSource.display_name || dataSource.nickname || '');
      return /*#__PURE__*/React.createElement("div", {
        className: "".concat(PREFIX, "__avatar-wrapper")
      }, /*#__PURE__*/React.createElement(PisellAvatar, avatarProps, text), statusIndicator);
    }
    if (icon) {
      return /*#__PURE__*/React.createElement("div", {
        className: "".concat(PREFIX, "__avatar-wrapper")
      }, /*#__PURE__*/React.createElement(PisellAvatar, _extends({}, avatarProps, {
        icon: icon
      })), statusIndicator);
    }
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(PREFIX, "__avatar-wrapper")
    }, /*#__PURE__*/React.createElement(PisellAvatar, _extends({}, avatarProps, {
      src: dataSource.cover
    })), statusIndicator);
  };

  // 渲染标签
  var renderTags = function renderTags() {
    var tagsToShow = tags.length > 0 ? tags : (dataSource === null || dataSource === void 0 ? void 0 : dataSource.tags) || [];
    if (!tagsToShow.length) return null;
    var _tag$gap = tag.gap,
      gap = _tag$gap === void 0 ? 6 : _tag$gap,
      _tag$flexWrap = tag.flexWrap,
      flexWrap = _tag$flexWrap === void 0 ? 'nowrap' : _tag$flexWrap;
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(PREFIX, "__tags ").concat(PREFIX, "__tags--line"),
      style: {
        gap: gap,
        flexWrap: flexWrap
      }
    }, tagsToShow.map(function (tagItem, index) {
      var content = typeof tagItem === 'string' ? tagItem : tagItem.children || tagItem.label;
      var tagProps = {
        key: index,
        color: _typeof(tagItem) === 'object' ? tagItem.color : undefined,
        className: "".concat(PREFIX, "__tag")
      };
      return /*#__PURE__*/React.createElement(Tag, tagProps, content);
    }));
  };

  // 卡片样式
  var cardStyle = _objectSpread(_objectSpread({}, customStyle), {}, {
    gap: horizontalGap
  });
  return /*#__PURE__*/React.createElement("div", {
    className: classNames(PREFIX, "".concat(PREFIX, "--line")),
    style: cardStyle,
    onClick: function onClick() {
      return dataSource && (onViewClient === null || onViewClient === void 0 ? void 0 : onViewClient(dataSource));
    }
  }, slots === null || slots === void 0 ? void 0 : slots.top, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__content")
  }, (slots === null || slots === void 0 ? void 0 : slots.left) && /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__slot-left")
  }, slots === null || slots === void 0 ? void 0 : slots.left), renderAvatar(), isShowName && /*#__PURE__*/React.createElement(ClientName, {
    dataSource: dataSource,
    style: nameStyle,
    className: "pisell-client-card__name--line"
  }), contactText && /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__contact ").concat(PREFIX, "__contact--line")
  }, contactText), renderTags(), (slots === null || slots === void 0 ? void 0 : slots.right) && /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__slot-right")
  }, slots === null || slots === void 0 ? void 0 : slots.right)), slots === null || slots === void 0 ? void 0 : slots.bottom);
};
export default LineCard;