import { r as registerInstance, c as createEvent, h, H as Host } from './index-b7735e0d.js';
import './apiBase-d573f009.js';
import './data-transfer-field-918730a3.js';
import './filter-cbaa3d7d.js';
import { c as createMentornityApiInstance, I as Invitation, M as ModelReference, C as Collection, a as InvitationStatus } from './instance-7b02ef1d.js';
import { m as mentornityApiEndpoint } from './env-4ec3c807.js';
import { g as getSessionDetails } from './session-b16a440c.js';
import './BaseField-461b6d0c.js';
import './FieldModelGenerator-020f4a04.js';
import './reference-field-0e7cd534.js';
import './index-7b119e61.js';
import './index-403101cb.js';
import './date-ce777316.js';
import './index-1d3efe49.js';
import './index-eb14fd2d.js';
import './index-80ec23ef.js';
import './index-4c39b6a6.js';
import './membership-e92743d1.js';
import './data-model-f7ccf826.js';
import './table-config-0c06fb1f.js';
import './string-3065a411.js';
import './User-1ef5a482.js';
import './UserSettings-27df01e6.js';
import './cookie-1686830b.js';
import './kimlikApi-0d7e6ce7.js';
import './_commonjsHelpers-27f122dd.js';
import './index-d3bd30bd.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) {
    registerInstance(this, hostRef);
    this.acceptApplication = createEvent(this, "acceptApplication", 7);
    this.isProgressing = false;
    this.isInvitationSent = false;
    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();
    };
  }
  render() {
    const isInvited = this.item.applicationStatus === 'invited' || this.isInvitationSent;
    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 ? 'Invited' : 'Accept & Invite')));
  }
};

export { MentornityAcceptApplicationButton as mentornity_accept_application_button };
