"use strict";var _constant=require("../../utils/constant"),_times=require("../../utils/times"),_reservationService=require("../../services/reservation-service"),_featureProcess=require("../../utils/feature-process"),_theme=require("../../utils/theme"),_utils=require("../../utils/utils"),pad=function(e){return e.toString().padStart(2,"0")};Component({options:{styleIsolation:"apply-shared"},properties:{sdkInstance:{type:Object,value:null},isLandscape:{type:Boolean,value:!1}},data:{show:!1,showReservationEntry:!1,isReserved:!1,modalVisible:!1,isReservationSmsEnable:0,countdown:null,isDarkTheme:!1},observers:{sdkInstance:function(e){if(e){var t=e.store,s=this;this._unsubscribe&&(this._unsubscribe(),this._unsubscribe=null),this._unsubscribe=t.get({liveInfo:function(e){if(null!=e&&e.Basic){var t=e.Basic,i=t.IsCountdownEnable,n=t.IsReservationEnable,o=t.Status,r=t.Countdown,a=1===i&&o===_constant.LIVE_STATUS.预告&&Number(r)>0,u={show:a,showReservationEntry:a&&1===n,isDarkTheme:(0,_theme.isUseDarkTheme)(e.Basic)};if(a){var l=(0,_times.getCurrentServerTimeSecond)()+Number(r);s._startCountdown(l)}else s._stopCountdown(),u.countdown=null;(0,_utils.setDataIfChanged)(s,u)}},"reservation.isReserved":function(e){(0,_utils.setDataIfChanged)(s,{isReserved:e||!1})},"reservation.modalVisible":function(e){(0,_utils.setDataIfChanged)(s,{modalVisible:e||!1})},"reservation.isReservationSmsEnable":function(e){(0,_utils.setDataIfChanged)(s,{isReservationSmsEnable:e||0})},"reservation.autoReservationWindowEnable":function(){s._tryAutoPopup(e)},"reservation.statusLoaded":function(t){t&&s._tryAutoPopup(e)}})}}},lifetimes:{detached:function(){this._unsubscribe&&(this._unsubscribe(),this._unsubscribe=null),this._stopCountdown()}},methods:{_timer:null,_targetTime:null,_finishEmitted:!1,_startCountdown:function(e){var t=this;if(e){var s=e;if(13===String(Math.floor(s)).length&&(s=Math.floor(s/1e3)),!(this._timer&&this._targetTime&&Math.abs(this._targetTime-s)<=1)){this._targetTime=s,this._finishEmitted=!1,this._stopCountdown();var i=function(){var e=Math.ceil(t._targetTime-(0,_times.getCurrentServerTimeSecond)());if(e<=0)return t.setData({countdown:null,show:!1}),t._stopCountdown(),void t._emitCountdownFinish();var s={d:Math.floor(e/86400),h:pad(Math.floor(e%86400/3600)),m:pad(Math.floor(e%3600/60)),s:pad(e%60)};t.data.countdown&&s.d===t.data.countdown.d&&s.h===t.data.countdown.h&&s.m===t.data.countdown.m&&s.s===t.data.countdown.s||t.setData({countdown:s})};i(),this._timer=setInterval(i,1e3)}}else this._stopCountdown()},_stopCountdown:function(){this._timer&&(clearInterval(this._timer),this._timer=null)},_emitCountdownFinish:function(){var e,t;if(!this._finishEmitted){this._finishEmitted=!0;var s=this.properties.sdkInstance;null!=s&&s.emitEvent&&null!==(e=s.EVENTS)&&void 0!==e&&null!==(t=e.countdown)&&void 0!==t&&t.finish&&s.emitEvent(s.EVENTS.countdown.finish,{})}},_tryAutoPopup:function(e){var t,s;if(this.data.showReservationEntry){var i,n=e.store.get("reservation")||{},o=e.store.get("mainInfo")||{};n.statusLoaded&&(1!==n.autoReservationWindowEnable||n.isReserved||null!==(t=o.options)&&void 0!==t&&t.disableReservationCell||null!==(s=o.options)&&void 0!==s&&s.isReserved||(e.store.set("reservation.modalVisible",!0),null===(i=e.reportTea)||void 0===i||i.call(e,"appointment_click",{isAuto:!0,evModule:"RESERVATION"})))}},onReservationTap:function(){var e=this.properties.sdkInstance;e&&this.data.showReservationEntry&&(this.data.isReserved||(0,_featureProcess.lockFeatureProcess)(e,_featureProcess.LockFeatureMap.Reservation)||(e.emitEvent(e.EVENTS.reservation.click,{}),this._openReservation()))},_openReservation:function(){var e=this,t=this.properties.sdkInstance;if(t&&this.data.showReservationEntry){var s=this.data.isReservationSmsEnable,i=(0,_reservationService.getReservationService)(t);1===s?null==i||i.showReservationModal():(t.store.get("userInfo")||{}).userId?null==i||i.submitReservationLogin(function(t){t&&e.setData({isReserved:!0})}):this.triggerEvent("commentCheck")}},onReservationSuccess:function(){this.setData({isReserved:!0})},onModalClose:function(){var e,t=this.properties.sdkInstance;null===(e=(0,_reservationService.getReservationService)(t))||void 0===e||e.hideReservationModal()}}});