import { r as registerInstance, c as createEvent, h, H as Host } from './index-55faf181.js';
import './kimlikApi-7350588e.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-46ab1e99.js';
import { g as getSessionDetails, m as mentornityApiEndpoint } from './session-3ec0aa4c.js';
import './BaseField-461b6d0c.js';
import './FieldModelGenerator-1ee7fda2.js';
import './index-6a1cf9c1.js';
import './index-403e215e.js';
import './date-ce777316.js';
import './index-083a6906.js';
import './index-fa1db470.js';
import './membership-61c4a2f7.js';
import './data-model-f5160369.js';
import './membership-config-a51a5232.js';
import './table-config-5c917348.js';
import './string-3065a411.js';
import './User-d2ee8b71.js';
import './UserSettings-7b80b841.js';
import './cookie-93ea205f.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;
};
const 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-block" }, 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 };
