import{r as s,c as t,h as i,H as o}from"./p-9f21f85f.js";import{I as e}from"./p-6cf8ecf7.js";import"./p-25d382ec.js";import"./p-3968aca6.js";import"./p-d343a062.js";import{c as p,g as r,m as a}from"./p-c44f96b9.js";import{a as n}from"./p-905285ef.js";import"./p-105f7627.js";import"./p-6a6f355f.js";import"./p-aa5ffe14.js";import"./p-293acc32.js";import"./p-f2965a61.js";import"./p-0563ceba.js";import"./p-1e47e7bd.js";import"./p-31e77e7b.js";import"./p-825ab276.js";import"./p-6c8be41c.js";import"./p-1187cc7c.js";import"./p-881a2bb8.js";import"./p-968ee2ec.js";import"./p-d27cb594.js";import"./p-9c82afa0.js";import"./p-d6c479ab.js";import"./p-10cfccbb.js";import"./p-8d2ddf16.js";import"./p-814af281.js";import"./p-e929429b.js";import"./p-c2c9e896.js";import"./p-cb585cde.js";import"./p-3d141e05.js";import"./p-d59ffc5b.js";import"./p-0988b316.js";import"./p-65eb3f89.js";import"./p-42939000.js";import"./p-a86d8cf2.js";import"./p-3ccedaa0.js";import"./p-9aa2fafd.js";const c=class{constructor(i){s(this,i),this.action=t(this,"action",7),this.invalidation=t(this,"invalidation",7),this.isProgressing=!1,this.isFollowing=!1,this.subscription=void 0,this.toggleFollowStatus=()=>{const{subscription:s}=this;if(this.isProgressing=!0,s)p(a,r().headers).followUnfollowSubscription(s._id,(null==this?void 0:this.isFollowing)?"unfollow":"follow").then((()=>{this.isFollowing=!this.isFollowing,this.invalidation.emit(new e("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:n}=o,c={organisation:{_type:"reference",_class:"organisations",_id:n._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};p(a,r().headers).createSubscription(c).then((s=>{this.subscription=Object.assign(Object.assign({},c),s),this.isFollowing=!0,this.invalidation.emit(new e("mentornity-follow-button","mentornity-user-detail-page"))})).finally((()=>this.isProgressing=!1))}}}componentWillLoad(){var s;this.subscription=this.item.subscription,this.isFollowing=(null===(s=this.item.subscription)||void 0===s?void 0:s.isFollowing)||!1}render(){var s,t;const e=(null===(s=this.data)||void 0===s?void 0:s.isOnUserList)||!1,p=(null===(t=this.data)||void 0===t?void 0:t.language)||"en";return i(o,{class:e?"d-inline":"d-flex"},i("dvn-button",{disabled:this.isProgressing,onClick:this.toggleFollowStatus,tint:"primary",view:this.isFollowing?"outline":"solid",scale:e?"small":void 0,leaned:!0},n(p,this.isFollowing?"unfollow":"follow")))}};export{c as mentornity_follow_button}