import{r as s,c as t,h as i,H as o}from"./p-9f21f85f.js";import{I as p}from"./p-6cf8ecf7.js";import"./p-e78d5616.js";import"./p-3968aca6.js";import"./p-d343a062.js";import{c as r}from"./p-a3d5ad34.js";import{a as e}from"./p-2c9430cc.js";import{g as a,a as n}from"./p-f88474bf.js";import"./p-105f7627.js";import"./p-62d6b6a7.js";import"./p-0563ceba.js";import"./p-1e47e7bd.js";import"./p-31e77e7b.js";import"./p-825ab276.js";import"./p-6c8be41c.js";import"./p-9f31253b.js";import"./p-1187cc7c.js";import"./p-881a2bb8.js";import"./p-968ee2ec.js";import"./p-5209de98.js";import"./p-19efc983.js";import"./p-7737f905.js";import"./p-3c7a3a90.js";import"./p-0ff0ee91.js";import"./p-d27cb594.js";import"./p-902ec37a.js";import"./p-e7d62c6a.js";import"./p-74e6e642.js";import"./p-84876749.js";import"./p-03b520ca.js";import"./p-814af281.js";import"./p-e929429b.js";import"./p-c2c9e896.js";import"./p-67d3bdb0.js";import"./p-1ba76ce7.js";import"./p-0988b316.js";import"./p-65eb3f89.js";import"./p-42939000.js";const 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)r(n,a().headers).followUnfollowSubscription(s._id,t?"unfollow":"follow").then((()=>{this.invalidation.emit(new p("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:e}=o;r(n,a().headers).createSubscription({organisation:{_type:"reference",_class:"organisations",_id:e._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 p("mentornity-follow-button","mentornity-user-detail-page"))})).finally((()=>this.isProgressing=!1))}}}render(){var s,t;const p=(null===(s=this.item.subscription)||void 0===s?void 0:s.isFollowing)||!1,r=(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"},e(r,p?"unfollow":"follow")))}};export{m as mentornity_follow_button}