"use strict";var _constant=require("../../../utils/constant"),_productCardUtils=require("../../../utils/product-card-utils"),_jump=require("../../../utils/jump"),_utils=require("../../../utils/utils");function _typeof(t){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(t)}function ownKeys(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,i)}return r}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(r),!0).forEach(function(e){_defineProperty(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function _defineProperty(t,e,r){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"===_typeof(e)?e:String(e)}function _toPrimitive(t,e){if("object"!==_typeof(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!==_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}Component({properties:{sdkInstance:{type:Object,value:null},productIndex:{type:Number,value:void 0},mode:{type:String,value:"portrait"},themeColor:{type:Object,value:null},listHeight:{type:Number,value:420}},data:{cardList:[],recycleHeight:420,showShoppingCart:!1,productCardIconUrl:"https://p1-live.byteimg.com/tos-cn-i-gjr78lqtd0/8f27df3e7f134d77b683802fb7fecb18~tplv-gjr78lqtd0-z75.image"},observers:{sdkInstance:function(t){var e=this;if(t){this.sdkInstance=t,this.store=t.store;var r=this;"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this.unsub=this.store.get({liveInfo:function(t){if(t.Menus){var i=t.Menus.ProductV2;if(i[e.data.productIndex]){var n=i[e.data.productIndex],o=Array.isArray(n.Product)?n.Product.map(_productCardUtils.withProductReminderText):[],u=o.findIndex(function(t){return 1===t.FloatingStatus||1===t.ExplainStatus});if(u>-1){var c=o[u];o.splice(u,1),o.unshift(c)}JSON.stringify(r.data.cardList)!==JSON.stringify(o)&&r.setData({cardList:o},function(){r.updateRecycleHeight()})}}}})}}},lifetimes:{ready:function(){this.updateRecycleHeight()},detached:function(){"function"==typeof this.unsub&&this.unsub(),this.unsub=null}},methods:{updateRecycleHeight:function(){var t=this;"landscape"===this.data.mode&&this.createSelectorQuery().select(".cardListScroller").boundingClientRect(function(e){var r=Math.floor((null==e?void 0:e.height)||0);r>0&&(0,_utils.setDataIfChanged)(t,{recycleHeight:r})}).exec()},handleCardClick:function(t){var e,r,i,n,o,u,c=t.currentTarget.dataset.redirectUrl,s=t.currentTarget.dataset.index,l=this.data.cardList[s];if(l&&1!==Number(l.OutOfStock)&&1!==Number(l.PriceHidden)){var d=(null===(e=this.store)||void 0===e||null===(r=e.get)||void 0===r?void 0:r.call(e,"liveInfo"))||{},a=(null==d||null===(i=d.Menus)||void 0===i?void 0:i.ProductV2)||{},p=(null==a?void 0:a[this.data.productIndex])||{};null===(n=this.sdkInstance)||void 0===n||n.emitEvent(_constant.EVENTS.PUBLIC.card.click,_objectSpread(_objectSpread({},l||{}),{},{cardIndex:s,text:null==l?void 0:l.Title,url:c,UAInfos:(null==p?void 0:p.UAInfos)||[]})),null===(o=this.sdkInstance)||void 0===o||o.reportLogger("mini_sdk_product_card_click",_objectSpread({},l)),(0,_productCardUtils.reportProductMessage)(this.sdkInstance,null==l?void 0:l.Id),null===(u=this.sdkInstance)||void 0===u||u.reportBusiness("view_ad",{AdType:4,AdId:null==l?void 0:l.Id,AdTitle:null==l?void 0:l.Title,AdContent:null==l?void 0:l.RedirectImage,AdLink:c}),(0,_jump.navigateToConfiguredWebview)(this.sdkInstance,_jump.JUMP_FEATURES.CARD,c)}}}});