var __awaiter=this&&this.__awaiter||function(t,e,i,n){function r(t){return t instanceof i?t:new i((function(e){e(t)}))}return new(i||(i=Promise))((function(i,a){function s(t){try{c(n.next(t))}catch(t){a(t)}}function o(t){try{c(n["throw"](t))}catch(t){a(t)}}function c(t){t.done?i(t.value):r(t.value).then(s,o)}c((n=n.apply(t,e||[])).next())}))};var __generator=this&&this.__generator||function(t,e){var i={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},n,r,a,s;return s={next:o(0),throw:o(1),return:o(2)},typeof Symbol==="function"&&(s[Symbol.iterator]=function(){return this}),s;function o(t){return function(e){return c([t,e])}}function c(s){if(n)throw new TypeError("Generator is already executing.");while(i)try{if(n=1,r&&(a=s[0]&2?r["return"]:s[0]?r["throw"]||((a=r["return"])&&a.call(r),0):r.next)&&!(a=a.call(r,s[1])).done)return a;if(r=0,a)s=[s[0]&2,a.value];switch(s[0]){case 0:case 1:a=s;break;case 4:i.label++;return{value:s[1],done:false};case 5:i.label++;r=s[1];s=[0];continue;case 7:s=i.ops.pop();i.trys.pop();continue;default:if(!(a=i.trys,a=a.length>0&&a[a.length-1])&&(s[0]===6||s[0]===2)){i=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){i.label=s[1];break}if(s[0]===6&&i.label<a[1]){i.label=a[1];a=s;break}if(a&&i.label<a[2]){i.label=a[2];i.ops.push(s);break}if(a[2])i.ops.pop();i.trys.pop();continue}s=e.call(t,i)}catch(t){s=[6,t];r=0}finally{n=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};import{r as registerInstance,c as createEvent,h,H as Host}from"./index-b7735e0d.js";import"./apiBase-d573f009.js";import"./data-transfer-field-918730a3.js";import"./filter-cbaa3d7d.js";import{c as createMentornityApiInstance,I as Invitation,M as ModelReference,C as Collection,a as InvitationStatus}from"./instance-7b02ef1d.js";import{m as mentornityApiEndpoint}from"./env-4ec3c807.js";import{g as getSessionDetails}from"./session-b16a440c.js";import"./BaseField-461b6d0c.js";import"./FieldModelGenerator-020f4a04.js";import"./reference-field-0e7cd534.js";import"./index-7b119e61.js";import"./index-403101cb.js";import"./date-ce777316.js";import"./index-1d3efe49.js";import"./index-eb14fd2d.js";import"./index-80ec23ef.js";import"./index-4c39b6a6.js";import"./membership-e92743d1.js";import"./data-model-f7ccf826.js";import"./table-config-0c06fb1f.js";import"./string-3065a411.js";import"./User-1ef5a482.js";import"./UserSettings-27df01e6.js";import"./cookie-1686830b.js";import"./kimlikApi-0d7e6ce7.js";import"./_commonjsHelpers-27f122dd.js";import"./index-d3bd30bd.js";var __rest=undefined&&undefined.__rest||function(t,e){var i={};for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0)i[n]=t[n];if(t!=null&&typeof Object.getOwnPropertySymbols==="function")for(var r=0,n=Object.getOwnPropertySymbols(t);r<n.length;r++){if(e.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(t,n[r]))i[n[r]]=t[n[r]]}return i};var MentornityAcceptApplicationButton=function(){function t(t){var e=this;registerInstance(this,t);this.acceptApplication=createEvent(this,"acceptApplication",7);this.isProgressing=false;this.isInvitationSent=false;this.onInviteClick=function(){return __awaiter(e,void 0,void 0,(function(){var t,e,i,n,r,a,s,o,c,l,p,f,u,d,m,h;var g=this;return __generator(this,(function(b){switch(b.label){case 0:t=getSessionDetails(),e=t.context.organisationId,i=t.headers;n=this.item,r=n.role,a=n.firstName,s=n.lastName,o=n.email,c=n.language,l=n._id,p=n.applicationStatus,f=n.createdAt,u=__rest(n,["role","firstName","lastName","email","language","_id","applicationStatus","createdAt"]);this.isProgressing=true;d=createMentornityApiInstance(mentornityApiEndpoint,i);return[4,d.importUser(e,r,{email:o,firstName:a,lastName:s,metadata:{data:u}}).catch((function(t){g.error=t;g.isProgressing=false}))];case 1:m=b.sent();if(!m)return[2];return[4,d.createInvitation(new Invitation({accountType:r,firstName:a,invitee:new ModelReference(m._id,Collection.Users),issuedFor:o,language:c,lastName:s,organisation:new ModelReference(e,Collection.Organisations),skills:[],status:InvitationStatus.Pending})).catch((function(t){g.error=t;g.isProgressing=false}))];case 2:h=b.sent();if(!h)return[2];this.isInvitationSent=true;this.isProgressing=false;this.acceptApplication.emit();return[2]}}))}))}}t.prototype.render=function(){var t=this.item.applicationStatus==="invited"||this.isInvitationSent;return h(Host,{class:"d-flex align-items-center",style:{height:"30px"}},h("dvn-button",{leaned:true,scale:"small",tagMode:t,tint:t?"secondary":"primary",view:t?"ghost":"solid",onClick:this.onInviteClick,progressing:this.isProgressing,disabled:this.isProgressing},t?"Invited":"Accept & Invite"))};return t}();export{MentornityAcceptApplicationButton as mentornity_accept_application_button};