"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.withProductReminderText=exports.splitSellingPointTags=exports.reportProductMessage=exports.checkCardConfigChange=exports.buildProductReminderText=void 0;var _constant=require("./constant");function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach(function(t){_defineProperty(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function _defineProperty(e,t,r){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var checkCardConfigChange=function(e){var t,r,n,o,i=e.oldLiveInfo,l=e.newLiveInfo,u=(null==i||null===(t=i.Menus)||void 0===t?void 0:t.Menus)||[],c=(null==i||null===(r=i.Menus)||void 0===r?void 0:r.ProductV2)||{},d=(null==l||null===(n=l.Menus)||void 0===n?void 0:n.Menus)||[],a=(null==l||null===(o=l.Menus)||void 0===o?void 0:o.ProductV2)||{};return{menusChanged:JSON.stringify(u)!==JSON.stringify(d),productChanged:JSON.stringify(c)!==JSON.stringify(a)}};exports.checkCardConfigChange=checkCardConfigChange;var buildProductReminderText=function(e){var t=Number((null==e?void 0:e.ReminderType)||0);return 1===t&&null!=e&&e.HotSale?"热卖 x ".concat(e.HotSale):2===t&&null!=e&&e.Stock?"库存仅剩 x ".concat(e.Stock):""};exports.buildProductReminderText=buildProductReminderText;var splitSellingPointTags=function(e){return String(e||"").split(/[;；]/).map(function(e){return e.trim()}).filter(Boolean)};exports.splitSellingPointTags=splitSellingPointTags;var PROMOTION_TAG_TEXT={2:"超值购",3:"惊喜特惠",4:"低价秒杀"},buildPromotionTag=function(e){var t=Number((null==e?void 0:e.PromotionTagType)||0);if(!t)return null;if(1===t&&null!=e&&e.PromotionTagUrl)return{isCustom:!0,image:e.PromotionTagUrl,text:""};var r=PROMOTION_TAG_TEXT[t];return r?{isCustom:!1,image:"",text:r,type:t}:null},withProductReminderText=function(e){return _objectSpread(_objectSpread({},e),{},{_reminderText_:buildProductReminderText(e),_reminderType_:Number((null==e?void 0:e.ReminderType)||0),_reminderValue_:1===Number((null==e?void 0:e.ReminderType)||0)?null==e?void 0:e.HotSale:null==e?void 0:e.Stock,_promotionTag_:buildPromotionTag(e),_sellingPointTags_:splitSellingPointTags(null==e?void 0:e.SellingPointTag),_memberPriceText_:null!=e&&e.MemberPrice&&1!==Number(null==e?void 0:e.PriceHidden)?"会员价 ".concat(e.MemberPrice):""})};exports.withProductReminderText=withProductReminderText;var isProductMessageEnabled=function(e){return!!(null!=e&&e.IsViewOrderEnable||null!=e&&e.IsViewInPurchaseEnable)},reportProductMessage=function(e,t){var r,n,o=(null==e||null===(r=e.store)||void 0===r||null===(n=r.get)||void 0===n?void 0:n.call(r,"liveInfo"))||{},i=o.ActivityId,l=Number(t);i&&l&&isProductMessageEnabled(o.CommentConfig||{})&&e.request(_constant.REQUEST_URL_MAP.PRODUCT_MESSAGE_SEND,{method:"POST",data:{ActivityId:i,ProductId:l}}).catch(function(t){var r,n;null==e||null===(r=e.reportTea)||void 0===r||r.call(e,"mini_sdk_product_message_send_fail",{ProductId:l,message:(null==t?void 0:t.message)||(null==t||null===(n=t.raw)||void 0===n?void 0:n.errMsg)||""})})};exports.reportProductMessage=reportProductMessage;