import React, { useMemo } from 'react';
import { Icon } from '@pisell/materials';
import "./index.less";
import { PREFIX, productCardDefault } from "../../status";
var PADDING = 4;
var Favorite = function Favorite(_ref) {
  var props = _ref.props;
  var skuExtraConfig = props.skuExtraConfig,
    className = props.className,
    dataSource = props.dataSource,
    onFavorite = props.onFavorite;
  var _ref2 = skuExtraConfig || (productCardDefault === null || productCardDefault === void 0 ? void 0 : productCardDefault.skuExtraConfig) || {},
    isOpen = _ref2.isOpen,
    favoritePosition = _ref2.favoritePosition,
    favoriteIcon = _ref2.favoriteIcon,
    favoriteBackground = _ref2.favoriteBackground,
    favoritePaddingY = _ref2.favoritePaddingY,
    favoritePaddingX = _ref2.favoritePaddingX,
    favoriteRadius = _ref2.favoriteRadius,
    isFavoriteBorder = _ref2.isFavoriteBorder,
    favoriteBorderWidth = _ref2.favoriteBorderWidth,
    favoriteBorderColor = _ref2.favoriteBorderColor,
    isFavorite = _ref2.isFavorite;

  // 不开启或不开启收藏按钮
  if (!isOpen || !isFavorite) return null;
  var finalStyle = useMemo(function () {
    var isLeft = favoritePosition === 'left_top' || favoritePosition === 'left_bottom';
    var isRight = favoritePosition === 'right_top' || favoritePosition === 'right_bottom';
    var isTop = favoritePosition === 'left_top' || favoritePosition === 'right_top';
    var isBottom = favoritePosition === 'left_bottom' || favoritePosition === 'right_bottom';
    return {
      background: favoriteBackground,
      padding: "".concat(favoritePaddingY, "px ").concat(favoritePaddingX, "px"),
      border: isFavoriteBorder ? "".concat(favoriteBorderWidth, "px solid ").concat(favoriteBorderColor) : 'none',
      borderRadius: "".concat(favoriteRadius, "px"),
      top: isTop ? PADDING : 'auto',
      bottom: isBottom ? PADDING : 'auto',
      left: isLeft ? PADDING : 'auto',
      right: isRight ? PADDING : 'auto'
    };
  }, [favoriteBackground, favoritePaddingX, favoritePaddingY, isFavoriteBorder, favoriteBorderWidth, favoriteBorderColor, favoriteRadius, favoritePosition]);
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__card-favorite  ").concat(className),
    style: finalStyle,
    onClick: function onClick(e) {
      e.stopPropagation();
      onFavorite === null || onFavorite === void 0 || onFavorite(dataSource);
    }
  }, favoriteIcon || /*#__PURE__*/React.createElement(Icon, {
    type: "HeartFilled",
    size: 20,
    rotate: 0,
    spin: false,
    color: "#DC6803"
  }));
};
export default Favorite;