"use strict";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)}var _utils=require("../../../utils/utils"),_constant=require("../../../utils/constant"),_socket=require("../../../utils/socket"),_times=require("../../../utils/times"),_storage=require("../../../utils/storage"),_theme=require("../../../utils/theme"),_singleLogin=require("../../../utils/singleLogin"),_questionnaireManager=require("../../../utils/questionnaire-manager");function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _objectSpread(e){for(var t=1;t=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(c)throw i}}}}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(c&&s){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),x(n),l}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;x(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:w(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),l}},e}function asyncGeneratorStep(e,t,n,r,o,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(r,o)}function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){asyncGeneratorStep(i,r,o,a,c,"next",e)}function c(e){asyncGeneratorStep(i,r,o,a,c,"throw",e)}a(void 0)})}}Component({options:{styleIsolation:"shared"},properties:{sdkInstance:{type:Object,value:null}},data:{visible:!1,loading:!1,data:null,checkValue:"",checkedCheckIn:[],useDarkTheme:!1,isDeadline:!1,errMsg:"",isSubmitSuccess:!1,openedCheckInId:[]},lifetimes:{detached:function(){"function"==typeof this.unsub&&this.unsub(),this.unsub=null}},observers:{sdkInstance:function(e){var t=this;if(e){this.store=e.store,this.sdkInstance=e;var n=this;e.on(_constant.EVENTS.INNER.socket.init,function(e){n.socket=e,n.bindSocketEvents()});var r=1,o=0;"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this.unsub=this.store.get({CheckInInfo:function(e){var r=e||{},o=r.visible,i=r.currentId;o&&i&&n.openCheckIn(i),o||n.selectComponent("#check-in-drawer").hideFrame({silent:!0}),(0,_utils.setDataIfChanged)(t,{visible:!!o})},liveInfo:function(e){(0,_utils.setDataIfChanged)(t,{useDarkTheme:(0,_theme.isUseDarkTheme)(null==e?void 0:e.Basic)})},mainInfo:function(e){2===(e||{}).mode&&n.setCheckedCheckIn()},userInfo:function(e){(e||{}).userId&&n.setCheckedCheckIn()},imageTextInfo:function(e){var t=((null==e?void 0:e.imageText)||[]).length;t&&1===r&&(r++,n.imageTextUpdateList()),t!==o&&(o=t,setTimeout(function(){n.checkInAutoOpen()},500))}})}}},methods:{openCheckInDrawer:function(){this.selectComponent("#check-in-drawer").showFrame()},closeCheckInDrawer:function(){this.selectComponent("#check-in-drawer").hideFrame(),this.myCancel()},myCancel:function(){var e=this;(this.store.get("CheckInInfo")||{}).visible&&(this.store.set("CheckInInfo",{visible:!1,currentId:null}),this.setData({isSubmitSuccess:!1}),setTimeout(function(){e.checkInAutoOpen()},500))},valueChange:function(e){this.setData({checkValue:e.detail.value||"",errMsg:""})},onCountDown:function(){this.setData({isDeadline:!0,errMsg:""})},isLogin:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return 2===this.store.get("mainInfo").mode||(e&&this.triggerEvent("commentCheck"),!1)},setCurrentData:function(e){var t=e.IsChecked,n=e.CheckInInfo,r=e.CheckInName,o=e.StartTime,i=e.DeadLine,a=e.DeadlineSecond,c=e.NeedPersonInfo,s=e.CannotWatchLiveWhenNotCheckIn;this.setData({data:{CheckInName:(0,_utils.getBySplit)(r),CheckInInfo:(0,_utils.getBySplit)(n),NeedPersonInfo:c,StartTime:o,Deadline:i,DeadlineSecond:a,IsChecked:t,ShowKickoutTip:!t&&(0,_questionnaireManager.isYesFlag)(s)}})},setCheckedIn:function(e,t){var n=this,r=this.data.checkedCheckIn;this.setData({checkedCheckIn:r.concat([e])},function(){n.imageTextUpdate({CheckInID:e,CheckInStatus:t})});var o=this.store.get("userInfo").userId,i=this.store.get("mainInfo").activityId+"_"+o;this.localCacheCheckIn(i,e)},updateNewStatus:function(e){var t=e.IsChecked,n=e.CheckInConfig||{},r=n.Status,o=n.CheckInId,i=n.CheckInName,a=n.StartTime,c=n.Deadline,s=n.DeadlineSecond,u=n.NeedPersonInfo,h=n.CheckInInfo,l=n.CannotWatchLiveWhenNotCheckIn;t&&this.setCheckedIn(o,r),this.setCurrentData({IsChecked:t,CheckInName:i,StartTime:a,DeadLine:c,DeadlineSecond:s,NeedPersonInfo:u,CheckInInfo:h,CannotWatchLiveWhenNotCheckIn:l})},openCheckIn:function(e){var t=this;return _asyncToGenerator(_regeneratorRuntime().mark(function n(){var r,o,i,a,c,s,u,h;return _regeneratorRuntime().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(t.setData({isDeadline:!1,checkValue:"",errMsg:""}),r=t.store.get("imageTextInfo")||{},o=r.imageText,i=null,null==o||o.forEach(function(t){null==t||t.Context.forEach(function(t){var n;t.ImageTextType===_constant.ImageTextTypes.CHECKIN&&(null===(n=t.CheckInContext)||void 0===n?void 0:n.CheckInId)===e&&(i=t.CheckInContext)})}),i){n.next=7;break}return t.sdkInstance.reportLogger("mini_sdk_check_in_no_current_data",{imageText:o,CheckInId:e}),n.abrupt("return");case 7:if(t.setCurrentData(i),t.openCheckInDrawer(),t.isLogin()){n.next=12;break}return t.sdkInstance.reportLogger("mini_sdk_check_in_no_login",{CheckInId:e}),n.abrupt("return");case 12:return a=t.store.get("userInfo"),c=a.userId,s=t.store.get("mainInfo"),u=s.activityId,t.setData({loading:!0}),n.next=17,t.sdkInstance.request(_constant.REQUEST_URL_MAP.GET_CHECK_IN_DETAIL,{method:"GET",data:{CheckInId:e,ActivityId:u,UserId:c}});case 17:if(h=n.sent,t.setData({loading:!1}),h){n.next=22;break}return t.sdkInstance.reportLogger("mini_sdk_check_in_get_detail_fail",{ActivityId:u,CheckInId:e,UserId:c}),n.abrupt("return");case 22:t.updateNewStatus(h);case 23:case"end":return n.stop()}},n)}))()},formSubmit:function(){var e=this;return _asyncToGenerator(_regeneratorRuntime().mark(function t(){var n,r,o,i,a,c,s,u;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e.isLogin(!0)){t.next=2;break}return t.abrupt("return");case 2:if(!e.data.data.NeedPersonInfo||e.data.checkValue.trim()){t.next=5;break}return e.setData({errMsg:"empty"}),t.abrupt("return");case 5:return e.setData({isSubmitting:!0}),n=e.store.get("mainInfo"),r=n.activityId,o=e.store.get("CheckInInfo"),i=o.currentId,a=e.store.get("userInfo"),c=a.userId,s={CheckInId:i,ActivityId:r,UserId:Number(c),PersonInfo:e.data.checkValue},t.next=12,e.sdkInstance.request(_constant.REQUEST_URL_MAP.CHECK_IN_SUBMIT,{method:"POST",data:s});case 12:if(u=t.sent,e.setData({isSubmitting:!1}),u){t.next=18;break}return wx.showToast({title:"提交失败",icon:"none"}),e.sdkInstance.reportLogger("mini_sdk_check_in_join_error",s),t.abrupt("return");case 18:e.sdkInstance.reportLogger("mini_sdk_check_in_join_success",s),e.setCheckedIn(i),e.setData({isSubmitSuccess:!0});case 21:case"end":return t.stop()}},t)}))()},imageTextUpdate:function(e){var t,n=e.CheckInID,r=e.CheckInStatus,o=this.data.checkedCheckIn.includes(n),i=this.store.get("CheckInInfo")||{},a=i.visible,c=i.currentId,s=this.store.get("imageTextInfo")||{},u=s.imageText,h=void 0===u?[]:u,l=_createForOfIteratorHelper(h);try{for(l.s();!(t=l.n()).done;){var f,d=_createForOfIteratorHelper(t.value.Context);try{for(d.s();!(f=d.n()).done;){var p=f.value;if((null==p?void 0:p.ImageTextType)===_constant.ImageTextTypes.CHECKIN){var I=p.CheckInContext;if(I&&I.CheckInId===n)return r&&(I.Status=r),I.IsChecked=null!=o?o:I.IsChecked,this.handleCheckInKickout(I,n,r),this.store.set("imageTextInfo",_objectSpread(_objectSpread({},s),{},{imageText:h})),void(a&&c===n&&r&&"Export"!==r&&this.setData({isDeadline:!0,errMsg:""}))}}}catch(e){d.e(e)}finally{d.f()}}}catch(e){l.e(e)}finally{l.f()}},handleCheckInKickout:function(e,t,n){if("Deadline"===n&&(0,_questionnaireManager.isYesFlag)(null==e?void 0:e.CannotWatchLiveWhenNotCheckIn)&&!this.data.checkedCheckIn.includes(t)){var r=(this.store.get("mainInfo")||{}).activityId,o=(this.store.get("userInfo")||{}).userId;if(r&&o){var i=(0,_storage.safeGetStorageJSON)("checkedId",{}),a=r+"_"+o;Array.isArray(i[a])&&i[a].includes(t)||(this.store.set("CheckInInfo",{visible:!1,currentId:null}),this.setData({isSubmitSuccess:!1}),(0,_singleLogin.updateBanStatus)(this.store,{isBanned:!0,banType:_constant.BAN_TYPE.CHECK_IN,banTips:(null==e?void 0:e.CannotWatchLivePrompt)||"",isSoftBan:!1}))}}},imageTextUpdateList:function(){var e=this.store.get("imageTextInfo")||{},t=e.imageText,n=void 0===t?[]:t;if(n.length){var r,o=_createForOfIteratorHelper(n);try{for(o.s();!(r=o.n()).done;){var i,a=_createForOfIteratorHelper(r.value.Context);try{for(a.s();!(i=a.n()).done;){var c=i.value;if((null==c?void 0:c.ImageTextType)===_constant.ImageTextTypes.CHECKIN){var s=c.CheckInContext,u=s.CheckInId,h=this.data.checkedCheckIn.includes(u);s&&h&&(s.IsChecked=!0)}}}catch(e){a.e(e)}finally{a.f()}}}catch(e){o.e(e)}finally{o.f()}this.store.set("imageTextInfo",_objectSpread(_objectSpread({},e),{},{imageText:n}))}},bindSocketEvents:function(){var e,t=this;null===(e=this.socket)||void 0===e||e.on(_socket.WsMethod.imageTextLotteryOrCheckInUpdate,function(e){e.SendType===_constant.ImageTextTypes.CHECKIN&&(t.sdkInstance.reportLogger("mini_sdk_check_in_update",{data:e}),t.imageTextUpdate(e))})},setCheckedCheckIn:function(){var e=(this.store.get("mainInfo")||{}).activityId,t=(this.store.get("userInfo")||{}).userId;if(e&&t){var n=(0,_storage.safeGetStorageJSON)("checkedId",{})[e+"_"+t];if(t&&Array.isArray(n)){var r=n.slice(1);this.setData({checkedCheckIn:r})}}},localCacheCheckIn:function(e,t){var n=(0,_storage.safeGetStorageJSON)("checkedId",{});Array.isArray(n[e])?(n[e].includes(t)||n[e].push(t),n[e][0]=Date.now()):n[e]=[Date.now(),t];var r=Object.keys(n);if(r.length>10){var o=r.sort(function(e,t){return(Array.isArray(n[e])?n[e][0]:0)-(Array.isArray(n[t])?n[t][0]:0)}),i=r.length-10;o.slice(0,i).forEach(function(e){delete n[e]})}(0,_storage.safeSetStorageJSON)("checkedId",n)},open:function(e,t){var n=this.data.openedCheckInId;n.push(e),this.store.set("CheckInInfo",{visible:!0,currentId:e}),this.setData({openedCheckInId:_toConsumableArray(n)}),this.sdkInstance.reportTea("mini_sdk_auto_open_check_in_modal",{CheckInId:e,param:t})},checkInAutoOpen:function(){var e=this;return _asyncToGenerator(_regeneratorRuntime().mark(function t(){var n,r,o,i,a,c,s,u,h,l,f,d,p,I,y,v,g,m,k,_,b,C,x,T;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=e.store.get("CheckInInfo")||{},r=n.visible,o=e.store.get("imageTextInfo")||{},i=o.imageText,a=void 0===i?[]:i,c=e.data,s=c.openedCheckInId,u=c.checkedCheckIn,h=e.store.get("mainInfo")||{},l=h.activityId,f=e.store.get("userInfo"),d=(f||{}).userId,l){t.next=9;break}return t.abrupt("return");case 9:if(r||!a.length){t.next=45;break}p=0;case 11:if(!(p