'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-a1121663.js');
require('./index-16c91445.js');
require('./BaseField-f50bb8f0.js');
require('./FieldModelGenerator-61c1111e.js');
require('./date-8e8ca89a.js');
require('./index-21b225d5.js');
require('./_commonjsHelpers-206db00d.js');
require('./index-13fb62eb.js');
require('./kimlikApi-6a581864.js');
require('./data-transfer-field-025bce2f.js');
require('./filter-52876f3c.js');
require('./cookie-8a49bf23.js');
const instance = require('./instance-fbedf46d.js');
const session = require('./session-a266bfc2.js');

const MentornityAcceptApplicationButton = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.acceptApplication = index.createEvent(this, "acceptApplication", 7);
    this.isProgressing = false;
    this.isInvitationSent = false;
    this.onInviteClick = async () => {
      const { context: { organisationId }, headers } = session.getSessionDetails();
      const { role, firstName, lastName, email, language } = this.item;
      this.isProgressing = true;
      const api = instance.createMentornityApiInstance(session.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 instance.Invitation({
        accountType: role,
        firstName,
        invitee: new instance.ModelReference(importUserResponse._id, instance.Collection.Users),
        issuedFor: email,
        language,
        lastName,
        organisation: new instance.ModelReference(organisationId, instance.Collection.Organisations),
        skills: [],
        status: instance.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 (index.h(index.Host, { class: "d-block" }, index.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')));
  }
};

exports.mentornity_accept_application_button = MentornityAcceptApplicationButton;
