import{r as registerInstance,c as createEvent,h,H as Host}from"./index-55faf181.js";import{I as InvalidationAction}from"./actions-b9a0f808.js";import"./kimlikApi-7350588e.js";import"./data-transfer-field-918730a3.js";import"./filter-cbaa3d7d.js";import{c as createMentornityApiInstance}from"./instance-46ab1e99.js";import{g as getSessionDetails,m as mentornityApiEndpoint}from"./session-3ec0aa4c.js";import"./BaseField-461b6d0c.js";import"./FieldModelGenerator-1ee7fda2.js";import"./index-6a1cf9c1.js";import"./index-403e215e.js";import"./date-ce777316.js";import"./index-083a6906.js";import"./index-fa1db470.js";import"./membership-61c4a2f7.js";import"./data-model-f5160369.js";import"./membership-config-a51a5232.js";import"./table-config-5c917348.js";import"./string-3065a411.js";import"./User-d2ee8b71.js";import"./UserSettings-7b80b841.js";import"./cookie-93ea205f.js";import"./_commonjsHelpers-27f122dd.js";import"./index-d3bd30bd.js";var MentornityFollowButton=function(){function i(i){var t=this;registerInstance(this,i);this.action=createEvent(this,"action",7);this.invalidation=createEvent(this,"invalidation",7);this.isProgressing=false;this.toggleFollowStatus=function(){var i=t.item.subscription;var e=(i===null||i===void 0?void 0:i.isFollowing)||false;t.isProgressing=true;if(i){createMentornityApiInstance(mentornityApiEndpoint,getSessionDetails().headers).followUnfollowSubscription(i._id,e?"unfollow":"follow").then((function(){t.invalidation.emit(new InvalidationAction("mentornity-follow-button","mentornity-user-detail-page"))})).finally((function(){return t.isProgressing=false}))}else{var n=t.data.mentornityCookieContext,o=n.groupId,s=n.userId;var r=!!o;var a=t.item.mentorship;var l=a.organisation;createMentornityApiInstance(mentornityApiEndpoint,getSessionDetails().headers).createSubscription({organisation:{_type:"reference",_class:"organisations",_id:l._id},subscribed:{_type:"reference",_class:"users",_id:s},subscriber:{_type:"reference",_class:r?"groups":"users",_id:r?o:s},createdBy:{_type:"reference",_class:"users",_id:s},mentorship:{_type:"reference",_class:"mentorships",_id:a._id},status:"active",isFollowing:true}).then((function(){t.invalidation.emit(new InvalidationAction("mentornity-follow-button","mentornity-user-detail-page"))})).finally((function(){return t.isProgressing=false}))}}}i.prototype.render=function(){var i;var t=((i=this.item.subscription)===null||i===void 0?void 0:i.isFollowing)||false;return h(Host,{class:"d-flex"},h("dvn-button",{disabled:this.isProgressing,onClick:this.toggleFollowStatus,tint:"primary",view:"flat"},t?"Unfollow":"Follow"))};return i}();export{MentornityFollowButton as mentornity_follow_button};