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); }
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, { useCallback, useMemo } from 'react';
import { PisellTags } from '@pisell/materials';
import { PREFIX, productCardDefault, promotionTagDefault } from "../../status";
import "./index.less";
var Promotions = function Promotions(_ref) {
  var _productCardDefault$s;
  var props = _ref.props;
  var dataSource = props.dataSource,
    skuTextConfig = props.skuTextConfig;
  var _ref2 = (skuTextConfig === null || skuTextConfig === void 0 ? void 0 : skuTextConfig.skuPromotionsConfig) || (productCardDefault === null || productCardDefault === void 0 || (_productCardDefault$s = productCardDefault.skuTextConfig) === null || _productCardDefault$s === void 0 ? void 0 : _productCardDefault$s.skuPromotionsConfig) || {},
    isOpen = _ref2.isOpen,
    marginX = _ref2.marginX,
    isShowAll = _ref2.isShowAll,
    maxCount = _ref2.maxCount,
    lists = _ref2.lists;
  if (!isOpen) return null;
  var listsData = useMemo(function () {
    var _dataSource$promotion;
    var _lists = dataSource !== null && dataSource !== void 0 && (_dataSource$promotion = dataSource.promotions) !== null && _dataSource$promotion !== void 0 && _dataSource$promotion.length ? dataSource === null || dataSource === void 0 ? void 0 : dataSource.promotions : lists;
    return _lists || [];
  }, [dataSource === null || dataSource === void 0 ? void 0 : dataSource.promotions, lists]);

  /**
   * @title: 文本样式
   * @description:
   * @param {*} useCallback
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-09-10 11:27
   */
  var textStyle = useCallback(function (tag) {
    return {
      fontSize: tag.fontSize,
      fontWeight: tag.fontWeight,
      color: tag.color
    };
  }, []);

  /**
   * @title: 促销信息样式
   * @description:
   * @param {*} useCallback
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-09-10 11:27
   */
  var tagStyle = useCallback(function (tag) {
    return {
      background: tag.background,
      padding: "".concat(tag.paddingY, "px ").concat(tag.paddingX, "px"),
      borderRadius: tag.radius,
      border: tag.isBorder ? "".concat(tag.borderWidth, "px solid ").concat(tag.borderColor) : 'none',
      margin: 0,
      lineHeight: '18px'
    };
  }, [marginX]);

  /**
   * @title: 处理促销信息数据
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-09-11 10:59
   */
  var listsResult = useMemo(function () {
    if (isShowAll) {
      return listsData;
    }
    return listsData.slice(0, maxCount);
  }, [listsData, isShowAll, maxCount]);
  if (listsData.length === 0) return null;
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__card-promotions"),
    style: {
      gap: "".concat(marginX, "px")
    }
  }, listsResult.map(function (tag, tagIndex) {
    return /*#__PURE__*/React.createElement(PisellTags, _extends({
      key: tagIndex,
      style: _objectSpread(_objectSpread({}, (tag === null || tag === void 0 ? void 0 : tag.style) || {}), promotionTagDefault)
    }, tag.props), /*#__PURE__*/React.createElement("span", {
      style: textStyle(tag)
    }, tag === null || tag === void 0 ? void 0 : tag.title));
  }), (listsData === null || listsData === void 0 ? void 0 : listsData.length) > listsResult.length && /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__card-tags-remaining")
  }, "+", (listsData === null || listsData === void 0 ? void 0 : listsData.length) - listsResult.length));
};
export default Promotions;