"use strict";var _constant=require("../../../utils/constant"),_productCardUtils=require("../../../utils/product-card-utils"),_jump=require("../../../utils/jump");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 n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}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 n=r.call(t,e||"default");if("object"!==_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}Component({properties:{sdkInstance:{type:Object,value:null}},data:{showFloatCard:!1,closedByUser:!1,card:{},lastExplainCardIds:[]},observers:{sdkInstance:function(t){if(t){this.sdkInstance=t,this.store=t.store;var e=this;"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this.unsub=this.store.get({liveInfo:function(t){if(null!=t&&t.Menus){var r=t.Menus.ProductV2,n=[];Object.values(r).forEach(function(t){n=n.concat(t.Product?t.Product.map(function(e){return _objectSpread(_objectSpread({},(0,_productCardUtils.withProductReminderText)(e)),{},{UAInfos:t.UAInfos})}):[])});var i=n.filter(function(t){return 1===t.FloatingStatus||1===t.ExplainStatus}),o=i.map(function(t){return t.Id}).sort(),s=JSON.stringify(o)!==JSON.stringify(e.data.lastExplainCardIds);if(i.length){var a,d,l=i[0],u=l.Id!==(null===(a=e.data.card)||void 0===a?void 0:a.Id)||s,c=!!u||!e.data.closedByUser,p=e.data.showFloatCard;e.setData({card:l,showFloatCard:c,closedByUser:!u&&e.data.closedByUser,lastExplainCardIds:o}),p!==c&&(null===(d=e.sdkInstance)||void 0===d||d.emitEvent(e.sdkInstance.EVENTS.card.explainStatusChange,_objectSpread({displayStatus:c},c?l:{})),e.triggerEvent("visibilityChange",{visible:c}))}else{var f,y=e.data.showFloatCard;(y||e.data.lastExplainCardIds.length>0)&&(null===(f=e.sdkInstance)||void 0===f||f.emitEvent(e.sdkInstance.EVENTS.card.explainStatusChange,{displayStatus:!1})),e.setData({card:{},showFloatCard:!1,closedByUser:!1,lastExplainCardIds:[]}),y&&e.triggerEvent("visibilityChange",{visible:!1})}}}})}}},lifetimes:{detached:function(){"function"==typeof this.unsub&&this.unsub(),this.unsub=null}},methods:{handleCardClick:function(){var t,e,r,n=this.data.card||{};1!==Number(n.OutOfStock)&&1!==Number(n.PriceHidden)&&(null===(t=this.sdkInstance)||void 0===t||t.emitEvent(_constant.EVENTS.PUBLIC.floatingCard.click,_objectSpread(_objectSpread({},n||{}),{},{text:null==n?void 0:n.Title,url:null==n?void 0:n.RedirectUrl})),null===(e=this.sdkInstance)||void 0===e||e.reportLogger("mini_sdk_product_card_click",_objectSpread({},n)),(0,_productCardUtils.reportProductMessage)(this.sdkInstance,null==n?void 0:n.Id),null===(r=this.sdkInstance)||void 0===r||r.reportBusiness("view_ad",{AdType:4,AdId:null==n?void 0:n.Id,AdTitle:null==n?void 0:n.Title,AdContent:null==n?void 0:n.RedirectImage,AdLink:null==n?void 0:n.RedirectUrl}),(0,_jump.navigateToConfiguredWebview)(this.sdkInstance,_jump.JUMP_FEATURES.FLOATING_CARD,null==n?void 0:n.RedirectUrl))},hideFloatCard:function(){this.setData({showFloatCard:!1,closedByUser:!0}),this.triggerEvent("visibilityChange",{visible:!1})}}});