import{r as registerInstance,c as createEvent,h,H as Host}from"./index-b7735e0d.js";import{I as InvalidationAction}from"./actions-b9a0f808.js";import"./apiBase-d573f009.js";import"./data-transfer-field-918730a3.js";import"./filter-cbaa3d7d.js";import{c as createMentornityApiInstance}from"./instance-7b02ef1d.js";import{g as getEmbeddedTranslation}from"./mentorinty-bridge-api-78ab1153.js";import{m as mentornityApiEndpoint}from"./env-4ec3c807.js";import{g as getSessionDetails}from"./session-b16a440c.js";import"./BaseField-461b6d0c.js";import"./FieldModelGenerator-020f4a04.js";import"./reference-field-0e7cd534.js";import"./index-7b119e61.js";import"./index-403101cb.js";import"./date-ce777316.js";import"./index-1d3efe49.js";import"./index-eb14fd2d.js";import"./index-80ec23ef.js";import"./index-4c39b6a6.js";import"./index-774783ee.js";import"./attachment-32decf79.js";import"./data-model-f7ccf826.js";import"./membership-e92743d1.js";import"./table-config-0c06fb1f.js";import"./string-3065a411.js";import"./User-1ef5a482.js";import"./CalendarConfig-88c2213e.js";import"./UserSettings-27df01e6.js";import"./cookie-1686830b.js";import"./kimlikApi-0d7e6ce7.js";import"./_commonjsHelpers-27f122dd.js";import"./index-d3bd30bd.js";var MentornityFollowButton=function(){function e(e){var i=this;registerInstance(this,e);this.action=createEvent(this,"action",7);this.invalidation=createEvent(this,"invalidation",7);this.isProgressing=false;this.toggleFollowStatus=function(){var e=i.item.subscription;var t=(e===null||e===void 0?void 0:e.isFollowing)||false;i.isProgressing=true;if(e){createMentornityApiInstance(mentornityApiEndpoint,getSessionDetails().headers).followUnfollowSubscription(e._id,t?"unfollow":"follow").then((function(){i.invalidation.emit(new InvalidationAction("mentornity-follow-button","mentornity-user-detail-page"))})).finally((function(){return i.isProgressing=false}))}else{var n=i.data.mentornityCookieContext,o=n.groupId,s=n.userId;var r=!!o;var a=i.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(){i.invalidation.emit(new InvalidationAction("mentornity-follow-button","mentornity-user-detail-page"))})).finally((function(){return i.isProgressing=false}))}}}e.prototype.render=function(){var e,i;var t=((e=this.item.subscription)===null||e===void 0?void 0:e.isFollowing)||false;var n=((i=this.data)===null||i===void 0?void 0:i.language)||"en";return h(Host,{class:"d-flex"},h("dvn-button",{disabled:this.isProgressing,onClick:this.toggleFollowStatus,tint:"primary",view:"flat"},getEmbeddedTranslation(n,t?"unfollow":"follow")))};return e}();export{MentornityFollowButton as mentornity_follow_button};