'use strict';

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

const index = require('./index-1141a245.js');
const index$1 = require('./index-a2e99c85.js');
require('./apiBase-e4ebaf8b.js');
require('./data-transfer-field-e8417d5f.js');
require('./filter-d5040f65.js');
const instance = require('./instance-36d7564f.js');
const session = require('./session-b6f20e12.js');
require('./BaseField-381327a9.js');
require('./FieldModelGenerator-1900d81a.js');
require('./reference-field-1239b0c3.js');
require('./index-2eea69a0.js');
require('./FieldGenerator-279a646b.js');
require('./date-a24d7714.js');
require('./index-0783d14f.js');
require('./index-e8e4d80b.js');
require('./index-9d3d3d15.js');
require('./index-9fd84b93.js');
require('./index-61f9621a.js');
require('./membership-ed8d3277.js');
require('./data-model-9afb7f54.js');
require('./table-config-8b14c7d3.js');
require('./string-de672b69.js');
require('./User-e889279b.js');
require('./UserSettings-fc04eb54.js');
require('./cookie-135bf612.js');
require('./kimlik-api-d3c479a3.js');
require('./_commonjsHelpers-206db00d.js');
require('./index-33e96540.js');
require('./mentorinty-bridge-api-0534712d.js');
require('./index-e751cab0.js');
require('./attachment-b0acc4c1.js');
require('./CalendarConfig-ee7bb722.js');
require('./i18n-49870fc9.js');
require('./i18n-5585a319.js');
require('./calendar-e4b7baeb.js');
require('./index-b776fc14.js');
require('./moment-7a3433f2.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.setDictionaryLanguage = async () => {
      const apiSozluk = new index$1.SozlukApi().setLanguage(this.item.language).setContents(session.sozlukEntries);
      this.strings = await apiSozluk.getContent(session.MentornityMembershipAppListWrapperI18nKey, session.mentornityMembershipAppListWrapperI18nDefault);
    };
    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();
    };
  }
  componentWillLoad() {
    this.setDictionaryLanguage();
  }
  render() {
    const isInvited = this.item.applicationStatus === 'invited' || this.isInvitationSent;
    if (!this.strings)
      return;
    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 ? this.strings.invited : this.strings.acceptAndInvite)));
  }
};

exports.mentornity_accept_application_button = MentornityAcceptApplicationButton;
