'use strict';

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

const index = require('./index-ce58ddc5.js');
require('./apiBase-b14a8285.js');
require('./data-transfer-field-0ce05c1a.js');
require('./filter-d5040f65.js');
const instance = require('./instance-fba77445.js');
const env = require('./env-56a21d68.js');
const session = require('./session-fe19e012.js');
require('./BaseField-d019ade6.js');
require('./FieldModelGenerator-1af8e5c3.js');
require('./reference-field-dda66f2e.js');
require('./index-f92537c9.js');
require('./index-7e3bc620.js');
require('./date-25b104f6.js');
require('./index-9ea6c7b1.js');
require('./index-93271b8c.js');
require('./index-29b7cb16.js');
require('./index-792d710c.js');
require('./membership-310dd68e.js');
require('./data-model-9afb7f54.js');
require('./table-config-73a193be.js');
require('./string-de672b69.js');
require('./User-e15e0b6d.js');
require('./UserSettings-fc04eb54.js');
require('./cookie-ea977378.js');
require('./kimlikApi-f4f62100.js');
require('./_commonjsHelpers-206db00d.js');
require('./index-33e96540.js');

var __rest = (undefined && undefined.__rest) || function (s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
let 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 _a = this.item, { role, firstName, lastName, email, language, // profile fields
      _id, applicationStatus, createdAt } = _a, // fields to be ignored
      metadataData = __rest(_a, ["role", "firstName", "lastName", "email", "language", "_id", "applicationStatus", "createdAt"]) // metadata fields
      ;
      this.isProgressing = true;
      const api = instance.createMentornityApiInstance(env.mentornityApiEndpoint, headers);
      const importUserResponse = await api.importUser(organisationId, role, { email, firstName, lastName, metadata: { data: metadataData } }).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-flex align-items-center", style: { height: '30px' } }, 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;
