import { r as registerInstance, c as createEvent, h, H as Host } from './index-b6f10a81.js';
import './index-ec7dc2ad.js';
import './BaseField-d94c5b14.js';
import './FieldModelGenerator-6ec60042.js';
import './date-b270be76.js';
import './index-94c1d7bf.js';
import './_commonjsHelpers-63c253cd.js';
import './index-fd2b14ae.js';
import './kimlikApi-81acfec6.js';
import './data-transfer-field-1ad95e08.js';
import './filter-cbaa3d7d.js';
import './cookie-d9098150.js';
import { c as createMentornityApiInstance, I as Invitation, M as ModelReference, C as Collection, a as InvitationStatus } from './instance-f50cdfd9.js';
import { g as getSessionDetails, m as mentornityApiEndpoint } from './session-78c3c986.js';

const MentornityAcceptApplicationButton = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.acceptApplication = createEvent(this, "acceptApplication", 7);
    this.isProgressing = false;
    this.isInvitationSent = false;
    this.onInviteClick = async () => {
      const { context: { organisationId }, headers } = getSessionDetails();
      const { role, firstName, lastName, email, language } = this.item;
      this.isProgressing = true;
      const api = createMentornityApiInstance(mentornityApiEndpoint, headers);
      const importUserResponse = await api.importUser(organisationId, role, { email, firstName, lastName, metadata: {} }).catch(error => {
        this.error = error;
        this.isProgressing = false;
      });
      if (!importUserResponse)
        return;
      const createInvitationResponse = await api.createInvitation(new Invitation({
        accountType: role,
        firstName,
        invitee: new ModelReference(importUserResponse._id, Collection.Users),
        issuedFor: email,
        language,
        lastName,
        organisation: new ModelReference(organisationId, Collection.Organisations),
        skills: [],
        status: InvitationStatus.Pending,
      })).catch(error => {
        this.error = error;
        this.isProgressing = false;
      });
      if (!createInvitationResponse)
        return;
      this.isInvitationSent = true;
      this.isProgressing = false;
      this.acceptApplication.emit();
    };
  }
  render() {
    const isInvited = this.item.applicationStatus === 'invited' || this.isInvitationSent;
    return (h(Host, { class: "d-block" }, h("dvn-button", { leaned: true, scale: "small", tagMode: isInvited, tint: isInvited ? 'secondary' : 'primary', view: isInvited ? 'ghost' : 'solid', onClick: this.onInviteClick, progressing: this.isProgressing, disabled: this.isProgressing }, isInvited ? 'Invited' : 'Accept & Invite')));
  }
};

export { MentornityAcceptApplicationButton as mentornity_accept_application_button };
