import{r as registerInstance,c as createEvent,h,H as Host}from"./index-102043e0.js";import{I as InvalidationAction}from"./actions-b9a0f808.js";import"./kimlikApi-ac700c81.js";import"./data-transfer-field-918730a3.js";import"./filter-cbaa3d7d.js";import{c as createMentornityApiInstance}from"./instance-fe40f49f.js";import{g as getEmbeddedTranslation}from"./mentorinty-bridge-api-fc8ad2d8.js";import{m as mentornityApiEndpoint}from"./env-4ec3c807.js";import{g as getSessionDetails}from"./session-4127c2a1.js";import"./BaseField-461b6d0c.js";import"./FieldModelGenerator-ee438a53.js";import"./index-ef734a5e.js";import"./index-336ef773.js";import"./date-ce777316.js";import"./index-0e8b9ea2.js";import"./index-c3eacf05.js";import"./index-a1675f50.js";import"./attachment-32decf79.js";import"./data-model-f5160369.js";import"./membership-821de3c5.js";import"./membership-config-68ed7772.js";import"./table-config-720f8ea0.js";import"./string-3065a411.js";import"./User-d2ee8b71.js";import"./CalendarConfig-cc1e3a80.js";import"./UserSettings-7b80b841.js";import"./cookie-647f9dc7.js";import"./_commonjsHelpers-27f122dd.js";import"./index-d3bd30bd.js";var MentornityFollowButton=function(){function t(t){var i=this;registerInstance(this,t);this.action=createEvent(this,"action",7);this.invalidation=createEvent(this,"invalidation",7);this.isProgressing=false;this.toggleFollowStatus=function(){var t=i.item.subscription;var e=(t===null||t===void 0?void 0:t.isFollowing)||false;i.isProgressing=true;if(t){createMentornityApiInstance(mentornityApiEndpoint,getSessionDetails().headers).followUnfollowSubscription(t._id,e?"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}))}}}t.prototype.render=function(){var t,i;var e=((t=this.item.subscription)===null||t===void 0?void 0:t.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,e?"unfollow":"follow")))};return t}();export{MentornityFollowButton as mentornity_follow_button};