import{r as s,c as t,h as i,H as o}from"./p-1ea36ff3.js";import{I as r}from"./p-6cf8ecf7.js";import"./p-7e860896.js";import"./p-944da115.js";import"./p-d343a062.js";import{c as e}from"./p-d49099be.js";import{g as p}from"./p-214632d0.js";import{m as n}from"./p-d4bb09bf.js";import{g as a}from"./p-8dfe8365.js";import"./p-eebad85b.js";import"./p-28c66a78.js";import"./p-6eb29778.js";import"./p-681f800a.js";import"./p-3b35e507.js";import"./p-240d1ae7.js";import"./p-35267d98.js";import"./p-cd1b0e39.js";import"./p-234c1f97.js";import"./p-d50d0ec8.js";import"./p-70e54631.js";import"./p-fac8edcc.js";import"./p-48f43f2a.js";import"./p-d27cb594.js";import"./p-56d4255d.js";import"./p-814c9d06.js";import"./p-73aa5f56.js";import"./p-7957afd8.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}