import{r as s,c as t,h as i,H as o}from"./p-a0569a5f.js";import{I as r}from"./p-6cf8ecf7.js";import"./p-e476a838.js";import"./p-944da115.js";import"./p-d343a062.js";import{c as e}from"./p-2cf91d8b.js";import{g as p}from"./p-924483bf.js";import{m as n}from"./p-d4bb09bf.js";import{g as a}from"./p-6fb74cfc.js";import"./p-eebad85b.js";import"./p-8fd375f7.js";import"./p-8e1b37ed.js";import"./p-429e49d9.js";import"./p-b7a1e5c3.js";import"./p-3b35e507.js";import"./p-c67a5881.js";import"./p-cc3f853d.js";import"./p-40e6d149.js";import"./p-cd9003fd.js";import"./p-0bd6e3b1.js";import"./p-234c1f97.js";import"./p-7737f905.js";import"./p-da9525c7.js";import"./p-9224a4e9.js";import"./p-d27cb594.js";import"./p-a4d551dd.js";import"./p-6ccb7ef7.js";import"./p-74e6e642.js";import"./p-1bea6126.js";import"./p-31309282.js";import"./p-814af281.js";import"./p-e929429b.js";let m=class{constructor(i){s(this,i),this.action=t(this,"action",7),this.invalidation=t(this,"invalidation",7),this.isProgressing=!1,this.toggleFollowStatus=()=>{const{subscription:s}=this.item,t=(null==s?void 0:s.isFollowing)||!1;if(this.isProgressing=!0,s)e(n,a().headers).followUnfollowSubscription(s._id,t?"unfollow":"follow").then((()=>{this.invalidation.emit(new r("mentornity-follow-button","mentornity-user-detail-page"))})).finally((()=>this.isProgressing=!1));else{const{mentornityCookieContext:{groupId:s,userId:t}}=this.data,i=!!s,{mentorship:o}=this.item,{organisation:p}=o;e(n,a().headers).createSubscription({organisation:{_type:"reference",_class:"organisations",_id:p._id},subscribed:{_type:"reference",_class:"users",_id:t},subscriber:{_type:"reference",_class:i?"groups":"users",_id:i?s:t},createdBy:{_type:"reference",_class:"users",_id:t},mentorship:{_type:"reference",_class:"mentorships",_id:o._id},status:"active",isFollowing:!0}).then((()=>{this.invalidation.emit(new r("mentornity-follow-button","mentornity-user-detail-page"))})).finally((()=>this.isProgressing=!1))}}}render(){var s,t;const r=(null===(s=this.item.subscription)||void 0===s?void 0:s.isFollowing)||!1,e=(null===(t=this.data)||void 0===t?void 0:t.language)||"en";return i(o,{class:"d-flex"},i("dvn-button",{disabled:this.isProgressing,onClick:this.toggleFollowStatus,tint:"primary",view:"flat"},p(e,r?"unfollow":"follow")))}};export{m as mentornity_follow_button}