define("discourse/plugins/discourse-narrative-bot/initializers/new-user-narrative",["exports","discourse/lib/ajax","discourse-common/lib/debounce","discourse/lib/offset-calculator","discourse/lib/is-element-in-viewport","discourse/lib/plugin-api"],(function(e,t,i,r,s,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n="new-user-narrative";function a(e){var o=e.container.lookup("message-bus:main"),a=e.getCurrentUser(),c=e.container.lookup("service:app-events");e.modifyClass("component:site-header",{pluginId:n,didInsertElement:function(){this._super.apply(this,arguments),this.dispatch("header:search-context-trigger","header")}}),e.modifyClass("controller:topic",{pluginId:n,_modifyBookmark:function(e,i){var r=this;return i&&-2===i.user_id&&!i.bookmarked?(0,t.ajax)("/bookmarks",{type:"POST",data:{post_id:i.id}}).then((function(e){i.setProperties({"topic.bookmarked":!0,bookmarked:!0,bookmark_id:e.id}),i.appEvents.trigger("post-stream:refresh",{id:r.id})})):this._super(e,i)},subscribe:function(){var e=this;this._super.apply(this,arguments),this.messageBus.subscribe("/topic/".concat(this.get("model.id")),(function(t){var i=e.model;if(i.get("isPrivateMessage")&&e.currentUser&&e.currentUser.get("id")!==t.user_id&&-2===t.user_id&&"created"===t.type){var r=t.post_number,s=i.get("highest_post_number")<=r,o=r-i.get("currentPost");s&&o>0&&o<7&&e._scrollToDiscobotPost(t.post_number)}}))},_scrollToDiscobotPost:function(e){(0,i.default)(this,(function(){var t=document.querySelector(".topic-post article#post_".concat(e));if(t&&!(0,s.default)(t)){var i=t.getBoundingClientRect();window.scrollTo({top:window.scrollY+i.top-(0,r.headerOffset)(),behavior:"smooth"})}}),e,500)}}),e.attachWidgetAction("header","headerSearchContextTrigger",(function(){this.site.mobileView?this.state.skipSearchContext=!1:(this.state.contextEnabled=!0,this.state.searchContextType="topic")})),o&&a&&o.subscribe("/new_user_narrative/tutorial_search",(function(){c.trigger("header:search-context-trigger")}))}var c={name:"new-user-narratve",initialize:function(e){e.lookup("site-settings:main").discourse_narrative_bot_enabled&&(0,o.withPluginApi)("0.8.7",a)}};e.default=c}));
//# sourceMappingURL=https://doy2mn9upadnk.cloudfront.net/assets/plugins/discourse-narrative-bot-7648c8e9699610bc9a41dc34d627f0227a7501feb863a8d84ec0ab1bdc745e3d.js.map