import{r as registerInstance,c as createEvent,h,H as Host}from"./index-ecdfb761.js";import{I as InvalidationAction}from"./actions-b9a0f808.js";import"./apiBase-6015f41f.js";import"./data-transfer-field-2f305919.js";import"./filter-cbaa3d7d.js";import{c as createMentornityApiInstance,g as getSessionDetails,m as mentornityApiEndpoint}from"./session-2a491341.js";import{a as getEmbeddedTranslation}from"./mentorinty-bridge-api-5ca2d652.js";import"./BaseField-0b01dc2c.js";import"./membership-b6639471.js";import"./data-model-88af49fc.js";import"./table-config-d73a72ab.js";import"./FieldModelGenerator-378c8613.js";import"./reference-field-a5b414d1.js";import"./index-61dcd269.js";import"./FieldGenerator-3ae403b2.js";import"./date-1bc489bd.js";import"./index-4e451db4.js";import"./index-23baeeef.js";import"./index-09efdc01.js";import"./index-150b6a59.js";import"./string-3065a411.js";import"./User-72c4643a.js";import"./UserSettings-7e4170a7.js";import"./cookie-5d9f5819.js";import"./kimlik-api-fddeac81.js";import"./_commonjsHelpers-27f122dd.js";import"./index-d3bd30bd.js";import"./index-3bf9b308.js";import"./sozluk-entries-1e8f5234.js";import"./i18n-09a07b97.js";import"./i18n-0e757ca5.js";import"./calendar-470c802a.js";import"./index-a3ca021c.js";import"./moment-65eca6b3.js";import"./index-e66e8eca.js";import"./attachment-961dd228.js";import"./CalendarConfig-412d1b0f.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.isFollowing=false;this.subscription=undefined;this.toggleFollowStatus=function(){var i=t.subscription;t.isProgressing=true;if(i){createMentornityApiInstance(mentornityApiEndpoint,getSessionDetails().headers).followUnfollowSubscription(i._id,(t===null||t===void 0?void 0:t.isFollowing)?"unfollow":"follow").then((function(){t.isFollowing=!t.isFollowing;t.invalidation.emit(new InvalidationAction("mentornity-follow-button","mentornity-user-detail-page"))})).finally((function(){return t.isProgressing=false}))}else{var e=t.data.mentornityCookieContext,n=e.groupId,o=e.userId;var s=!!n;var r=t.item.mentorship;var a=r.organisation;var l={organisation:{_type:"reference",_class:"organisations",_id:a._id},subscribed:{_type:"reference",_class:"users",_id:o},subscriber:{_type:"reference",_class:s?"groups":"users",_id:s?n:o},createdBy:{_type:"reference",_class:"users",_id:o},mentorship:{_type:"reference",_class:"mentorships",_id:r._id},status:"active",isFollowing:true};createMentornityApiInstance(mentornityApiEndpoint,getSessionDetails().headers).createSubscription(l).then((function(i){t.subscription=Object.assign(Object.assign({},l),i);t.isFollowing=true;t.invalidation.emit(new InvalidationAction("mentornity-follow-button","mentornity-user-detail-page"))})).finally((function(){return t.isProgressing=false}))}}}i.prototype.componentWillLoad=function(){var i;this.subscription=this.item.subscription;this.isFollowing=((i=this.item.subscription)===null||i===void 0?void 0:i.isFollowing)||false};i.prototype.render=function(){var i,t;var e=((i=this.data)===null||i===void 0?void 0:i.isOnUserList)||false;var n=((t=this.data)===null||t===void 0?void 0:t.language)||"en";return h(Host,{class:e?"d-inline":"d-flex"},h("dvn-button",{disabled:this.isProgressing,onClick:this.toggleFollowStatus,tint:"primary",view:this.isFollowing?"outline":"solid",scale:e?"small":undefined,leaned:true},getEmbeddedTranslation(n,this.isFollowing?"unfollow":"follow")))};return i}();export{MentornityFollowButton as mentornity_follow_button};