import { r as registerInstance, c as createEvent, h, H as Host } from './index-ecdfb761.js';
import { S as SozlukApi } from './index-3bf9b308.js';
import './apiBase-6015f41f.js';
import './data-transfer-field-2f305919.js';
import './filter-cbaa3d7d.js';
import { g as getSessionDetails, c as createMentornityApiInstance, I as Invitation, M as ModelReference, C as Collection, a as InvitationStatus, m as mentornityApiEndpoint } from './session-2a491341.js';
import { s as sozlukEntries, M as MentornityMembershipAppListWrapperI18nKey, m as mentornityMembershipAppListWrapperI18nDefault } from './sozluk-entries-1e8f5234.js';
import './BaseField-0b01dc2c.js';
import './membership-b6639471.js';
import './data-model-88af49fc.js';
import './table-config-d73a72ab.js';
import './FieldModelGenerator-378c8613.js';
import './reference-field-a5b414d1.js';
import './index-61dcd269.js';
import './FieldGenerator-3ae403b2.js';
import './date-1bc489bd.js';
import './index-4e451db4.js';
import './index-23baeeef.js';
import './index-09efdc01.js';
import './index-150b6a59.js';
import './string-3065a411.js';
import './User-72c4643a.js';
import './UserSettings-7e4170a7.js';
import './cookie-5d9f5819.js';
import './kimlik-api-fddeac81.js';
import './_commonjsHelpers-27f122dd.js';
import './index-d3bd30bd.js';
import './mentorinty-bridge-api-5ca2d652.js';
import './index-e66e8eca.js';
import './attachment-961dd228.js';
import './CalendarConfig-412d1b0f.js';
import './calendar-470c802a.js';
import './index-a3ca021c.js';
import './moment-65eca6b3.js';
import './i18n-09a07b97.js';
import './i18n-0e757ca5.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) {
    registerInstance(this, hostRef);
    this.acceptApplication = createEvent(this, "acceptApplication", 7);
    this.isProgressing = false;
    this.isInvitationSent = false;
    this.setDictionaryLanguage = async () => {
      const apiSozluk = new SozlukApi().setLanguage(this.item.language).setContents(sozlukEntries);
      this.strings = await apiSozluk.getContent(MentornityMembershipAppListWrapperI18nKey, mentornityMembershipAppListWrapperI18nDefault);
    };
    this.onInviteClick = async () => {
      const { context: { organisationId }, headers } = 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 = createMentornityApiInstance(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 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();
    };
  }
  componentWillLoad() {
    this.setDictionaryLanguage();
  }
  render() {
    const isInvited = this.item.applicationStatus === 'invited' || this.isInvitationSent;
    if (!this.strings)
      return;
    return (h(Host, { class: "d-flex align-items-center", style: { height: '30px' } }, 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)));
  }
};

export { MentornityAcceptApplicationButton as mentornity_accept_application_button };
