'use strict';

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

const index = require('./index-36b3af04.js');
require('./kimlikApi-85c6d3ac.js');
require('./data-transfer-field-0ce05c1a.js');
require('./filter-d5040f65.js');
const instance = require('./instance-79d61640.js');
const session = require('./session-3b788cd7.js');
require('./BaseField-d019ade6.js');
require('./FieldModelGenerator-205dd99c.js');
require('./index-74a00556.js');
require('./index-a8f1783c.js');
require('./date-25b104f6.js');
require('./index-fe19a98b.js');
require('./index-ae305bae.js');
require('./membership-dfbf512e.js');
require('./data-model-c51de090.js');
require('./membership-config-707b2c51.js');
require('./table-config-444a77e4.js');
require('./string-de672b69.js');
require('./User-286a0714.js');
require('./UserSettings-016122e8.js');
require('./cookie-370bc992.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;
};
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 _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(session.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-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;
