"use strict";var _constant=require("../../utils/constant"),_jump=require("../../utils/jump"),_productCardUtils=require("../../utils/product-card-utils");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;t1?"".concat(n,"等").concat(i,"人正在买").concat(s,"号商品"):"".concat(n,"正在买").concat(s,"号商品"):i>1?"".concat(n,"等").concat(i,"人已下单").concat(s,"号商品"):"".concat(n,"已下单").concat(s,"号商品")},buildMessage=function(e,t){var r;if(!e)return null;var n=unwrapOrderMessage(e),i=(null==t?void 0:t.CommentConfig)||{},s=normalizeType(n.MsgType),o=findProductFromProductInfo(n.ProductInfo||e.ProductInfo)||findProduct(null==t||null===(r=t.Menus)||void 0===r?void 0:r.ProductV2,n.ProductId);return[MESSAGE_TYPE.BUY,MESSAGE_TYPE.ORDER].includes(s)&&o&&0!==Number(o.EnableStatus)&&1!==Number(o.OutOfStock)?1===Number(o.PriceHidden)||!isSwitchOpen(o.IsOrderMsgEnable)||s===MESSAGE_TYPE.BUY&&!isSwitchOpen(i.IsViewInPurchaseEnable)||s===MESSAGE_TYPE.ORDER&&!isSwitchOpen(i.IsViewOrderEnable)?null:_objectSpread(_objectSpread({},n),{},{product:o,type:s,tagText:s===MESSAGE_TYPE.BUY?"正在买":"已下单",title:o.Title||"商品消息",text:buildMessageText(n,o,s),image:o.IntroduceImage||o.RedirectImage||""}):null};Component({properties:{sdkInstance:{type:Object,value:null}},data:{visible:!1,message:null},observers:{sdkInstance:function(e){var t=this;e&&(this.sdkInstance=e,this.store=e.store,"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this.unsub=this.store.get({"chat.orderMsg":function(e){t.handleOrderMessage(e)},liveInfo:function(e){t.syncVisibleMessage(e||{})}}))}},lifetimes:{attached:function(){this.handledMessageKeys={},this.currentOrderMsg=null,this.currentOrderMsgKey=""},detached:function(){"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this.clearHideTimer()}},methods:{handleOrderMessage:function(e){var t,r;if(e){var n,i,s=getOrderMessageKey(e);this.handledMessageKeys[s]?null===(n=this.store)||void 0===n||null===(i=n.set)||void 0===i||i.call(n,"chat.orderMsg",null):(this.handledMessageKeys[s]=!0,this.syncMessage(e,this.store.get("liveInfo")||{},s),null===(t=this.store)||void 0===t||null===(r=t.set)||void 0===r||r.call(t,"chat.orderMsg",null))}},syncVisibleMessage:function(e){var t,r;if(this.data.visible&&this.currentOrderMsg){var n=buildMessage(this.currentOrderMsg,e);if(!n)return this.clearHideTimer(),this.currentOrderMsg=null,this.currentOrderMsgKey="",void this.setData({visible:!1,message:null});(null===(t=this.data.message)||void 0===t?void 0:t.text)===n.text&&(null===(r=this.data.message)||void 0===r?void 0:r.title)===n.title||this.setData({message:n})}},syncMessage:function(e,t){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=buildMessage(e,t);if(this.clearHideTimer(),!i)return this.data.visible&&this.setData({visible:!1,message:null}),this.currentOrderMsg=null,void(this.currentOrderMsgKey="");this.currentOrderMsg=e,this.currentOrderMsgKey=n,this.setData({visible:!0,message:i}),this.hideTimer=setTimeout(function(){r.setData({visible:!1,message:null}),r.currentOrderMsg=null,r.currentOrderMsgKey=""},5e3)},clearHideTimer:function(){this.hideTimer&&(clearTimeout(this.hideTimer),this.hideTimer=null)},handleTap:function(){var e,t,r,n,i=this.data.message||{},s=i.product;if(s){var o=s.RedirectUrl;null===(e=this.sdkInstance)||void 0===e||e.reportLogger("mini_sdk_order_message_click",_objectSpread(_objectSpread({},s),{},{message:i})),null===(t=this.sdkInstance)||void 0===t||t.emitEvent(_constant.EVENTS.PUBLIC.card.click,_objectSpread(_objectSpread({},s||{}),{},{cardIndex:s.Index,text:s.Title,url:o,UAInfos:s.UAInfos||[]})),null===(r=this.sdkInstance)||void 0===r||r.reportLogger("mini_sdk_product_card_click",_objectSpread({},s)),(0,_productCardUtils.reportProductMessage)(this.sdkInstance,s.Id),null===(n=this.sdkInstance)||void 0===n||n.reportBusiness("view_ad",{AdType:4,AdId:s.Id,AdTitle:s.Title,AdContent:s.RedirectImage,AdLink:o}),(0,_jump.navigateToConfiguredWebview)(this.sdkInstance,_jump.JUMP_FEATURES.CARD,o),this.clearHideTimer(),this.currentOrderMsg=null,this.currentOrderMsgKey="",this.setData({visible:!1,message:null})}}}});