import React from 'react';
import { GiftOutlined } from '@ant-design/icons';
import { image as imageAli, locales } from '@pisell/utils';
import { PREFIX } from "../constants";
import { toDisplayText } from "../utils/display";
import { stopPropagation } from "../utils/render";
var GiftRow = function GiftRow(_ref) {
  var product = _ref.product,
    onGift = _ref.onGift;
  var giftData = product.giftData;
  if (!(giftData !== null && giftData !== void 0 && giftData.isShow)) return null;
  var selectedGifts = giftData.selectedGifts || [];
  var displayGifts = selectedGifts.slice(0, 5);
  return /*#__PURE__*/React.createElement("button", {
    className: "".concat(PREFIX, "__gift"),
    type: "button",
    onClick: function onClick(event) {
      stopPropagation(event);
      onGift === null || onGift === void 0 || onGift(product);
    }
  }, /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__gift-label")
  }, /*#__PURE__*/React.createElement(GiftOutlined, null), locales.getText('pisell2.sale-cart.line-item.gift')), /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__gift-content")
  }, displayGifts.length ? /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__gift-images")
  }, displayGifts.map(function (gift, index) {
    return /*#__PURE__*/React.createElement("span", {
      className: "".concat(PREFIX, "__gift-image"),
      key: gift.id || index
    }, gift.image ? /*#__PURE__*/React.createElement("img", {
      src: imageAli.ali(gift.image, 40),
      alt: ""
    }) : /*#__PURE__*/React.createElement("span", null, toDisplayText(gift.title).slice(0, 2)));
  })) : /*#__PURE__*/React.createElement("span", null, locales.getText('pisell2.sale-cart.line-item.select-gift'))), /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__gift-total")
  }, locales.getText('pisell2.sale-cart.line-item.gift-total')(giftData.totalCount)));
};
export default GiftRow;