import{r as s,c as t,h as i,H as o}from"./p-cb5076d4.js";import{I as r}from"./p-6cf8ecf7.js";import"./p-06588791.js";import"./p-944da115.js";import"./p-d343a062.js";import{c as e}from"./p-c4bbdd1e.js";import{g as p,m as n}from"./p-3a5f9c0f.js";import"./p-eebad85b.js";import"./p-0e4ae084.js";import"./p-8a308033.js";import"./p-0db2169b.js";import"./p-3b35e507.js";import"./p-1c5c6afa.js";import"./p-97c18602.js";import"./p-ecbaf6d8.js";import"./p-d50d0ec8.js";import"./p-c705c477.js";import"./p-4f99fb23.js";import"./p-d27cb594.js";import"./p-56d4255d.js";import"./p-73aa5f56.js";import"./p-138d8bf9.js";import"./p-814af281.js";import"./p-e929429b.js";const a=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,p().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:a}=o;e(n,p().headers).createSubscription({organisation:{_type:"reference",_class:"organisations",_id:a._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;const t=(null===(s=this.item.subscription)||void 0===s?void 0:s.isFollowing)||!1;return i(o,{class:"d-flex"},i("dvn-button",{disabled:this.isProgressing,onClick:this.toggleFollowStatus,tint:"primary",view:"flat"},t?"Unfollow":"Follow"))}};export{a as mentornity_follow_button}