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 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); }
import React, { useMemo } from 'react';
import classNames from 'classnames';
import "./index.less";
var stopPropagation = function stopPropagation(e) {
  e.stopPropagation();
};
var Card = function Card(_ref) {
  var _ref$variant = _ref.variant,
    variant = _ref$variant === void 0 ? 'outlined' : _ref$variant,
    _ref$layout = _ref.layout,
    layout = _ref$layout === void 0 ? 'horizontal' : _ref$layout,
    actions = _ref.actions,
    _ref$actionsPosition = _ref.actionsPosition,
    actionsPosition = _ref$actionsPosition === void 0 ? 'right' : _ref$actionsPosition,
    corner = _ref.corner,
    children = _ref.children,
    _ref$selected = _ref.selected,
    selected = _ref$selected === void 0 ? false : _ref$selected,
    _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    _ref$hoverable = _ref.hoverable,
    hoverable = _ref$hoverable === void 0 ? false : _ref$hoverable,
    onClick = _ref.onClick,
    styles = _ref.styles,
    _ref$selectedType = _ref.selectedType,
    selectedType = _ref$selectedType === void 0 ? 'outlined' : _ref$selectedType,
    className = _ref.className,
    style = _ref.style;
  // 样式属性对象，用于传递给样式函数
  var styleProps = useMemo(function () {
    return {
      selected: selected,
      disabled: disabled,
      hoverable: hoverable,
      variant: variant,
      layout: layout
    };
  }, [selected, disabled, hoverable, variant, layout]);

  // 计算容器样式
  var containerStyle = useMemo(function () {
    if (!(styles !== null && styles !== void 0 && styles.container)) return style;
    var customStyle = typeof styles.container === 'function' ? styles.container(styleProps) : styles.container;
    return _objectSpread(_objectSpread({}, customStyle), style);
  }, [styles === null || styles === void 0 ? void 0 : styles.container, style, styleProps]);

  // 计算内容样式
  var contentStyle = useMemo(function () {
    if (!(styles !== null && styles !== void 0 && styles.content)) return undefined;
    return typeof styles.content === 'function' ? styles.content(styleProps) : styles.content;
  }, [styles === null || styles === void 0 ? void 0 : styles.content, styleProps]);

  // 计算操作区样式
  var actionsStyle = useMemo(function () {
    if (!(styles !== null && styles !== void 0 && styles.actions)) return undefined;
    return typeof styles.actions === 'function' ? styles.actions(styleProps) : styles.actions;
  }, [styles === null || styles === void 0 ? void 0 : styles.actions, styleProps]);

  // 计算角标样式
  var cornerStyle = useMemo(function () {
    if (!(styles !== null && styles !== void 0 && styles.corner)) return undefined;
    return typeof styles.corner === 'function' ? styles.corner(styleProps) : styles.corner;
  }, [styles === null || styles === void 0 ? void 0 : styles.corner, styleProps]);

  // 渲染操作区域
  var renderActions = function renderActions() {
    if (!actions) return null;
    var _actions = Array.isArray(actions) ? actions.filter(Boolean) : [actions];
    if (_actions.length === 0) return null;
    return /*#__PURE__*/React.createElement("ul", {
      className: "pisell-pro-card_actions",
      style: actionsStyle
    }, actions.map(function (action, index) {
      return /*#__PURE__*/React.createElement("li", {
        key: index,
        className: "pisell-pro-card_actions-item",
        onClick: stopPropagation
      }, action);
    }));
  };

  // 渲染右上角组件
  var renderCorner = function renderCorner() {
    if (!corner || layout !== 'vertical') return null;
    return /*#__PURE__*/React.createElement("div", {
      className: "pisell-pro-card_corner",
      style: cornerStyle,
      onClick: stopPropagation
    }, corner);
  };

  // 处理卡片点击
  var handleClick = function handleClick(e) {
    if (disabled) return;
    onClick === null || onClick === void 0 || onClick(e);
  };
  return /*#__PURE__*/React.createElement("div", {
    className: classNames('pisell-pro-card', "pisell-pro-card-".concat(variant), "pisell-pro-card-".concat(layout), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
      'pisell-pro-card-selected': selected
    }, "pisell-pro-card-selected-".concat(selectedType), selected && selectedType !== 'none'), 'pisell-pro-card-disabled', disabled), 'pisell-pro-card-hoverable', hoverable && !disabled), 'pisell-pro-card-clickable', onClick && !disabled), "pisell-pro-card-actions-".concat(actionsPosition), layout === 'horizontal' && actions), className),
    style: containerStyle,
    onClick: handleClick
  }, layout === 'horizontal' && actionsPosition === 'left' && renderActions(), /*#__PURE__*/React.createElement("div", {
    className: "pisell-pro-card_content",
    style: contentStyle
  }, children), (layout === 'vertical' || actionsPosition === 'right') && renderActions(), renderCorner());
};
export default Card;