import { buildRoute, getActivateMembershipRouteParams } from '@dvn/core/util/route';
import { Component, Element, h, Host, Prop, State } from '@stencil/core';
import { injectContext } from '../../global/context';
function wrapContent(content) {
  return (h(Host, { class: "container-fluid" },
    h("div", { class: "row justify-content-center" },
      h("div", { class: "col-4 d-flex flex-column justify-content-center align-items-center mt-3" }, content))));
}
export class DvnAppActivateMembershipAnonymous {
  constructor() {
    this.renderTrigger = 0;
    this.isProgressing = false;
  }
  async componentDidLoad() {
    const { membershipConfigId, membershipId, viewId } = getActivateMembershipRouteParams(this.path);
    const membership = await this.apiUye.getMembership(membershipConfigId, membershipId).catch((e) => {
      this.error = e;
    }).finally(() => this.isProgressing = false);
    if (!membership)
      return;
    this.membershipToActivate = membership;
    if (viewId !== 'activate' && membership.status !== 'active') {
      // navigate to membership activation page if it's not already activation page
      this.navigate({ path: buildRoute(membership.config.space._id, membership.config._id, membership._id, 'activate') });
    }
  }
  render() {
    const { membershipToActivate } = this;
    if (!membershipToActivate) {
      return wrapContent(h("dvn-progress", { indefinite: true }));
    }
    if (membershipToActivate.user.status === 'active') {
      // if membership user is already an active user, show 'login required' message
      return wrapContent(h("div", { class: "d-flex flex-column align-items-center" },
        h("dvn-card", { elevation: 0, tint: "warning" },
          "You need to login as ",
          h("b", null,
            membershipToActivate.user.email,
            " "),
          " in order to accept the invitation."),
        h("dvn-card", null,
          h("kimlik-login-form", { api: this.apiKimlik, data: {
              email: membershipToActivate.user.email,
            }, onLogin: () => {
              this.navigate({ path: buildRoute(membershipToActivate.config.space._id, membershipToActivate.config._id, membershipToActivate._id) });
            } }))));
    }
    return wrapContent(h("div", { class: "d-flex flex-column align-items-center" },
      h("dvn-app-space-message-card", { space: membershipToActivate.config.space },
        h("div", null,
          "You're invited as ",
          h("i", null, membershipToActivate.config.roleName),
          " to join ",
          membershipToActivate.config.space.name,
          ".")),
      h("i", null, "But first, create account"),
      h("dvn-card", { elevation: 0 },
        h("kimlik-activate-user-form", { api: this.apiKimlik, data: {
            email: membershipToActivate.user.email,
            firstName: membershipToActivate.user.firstName,
            lastName: membershipToActivate.user.lastName,
          }, onActivate: () => {
            this.navigate({ path: buildRoute(membershipToActivate.config.space._id, membershipToActivate.config._id, membershipToActivate._id) });
          } }))));
  }
  static get is() { return "dvn-app-activate-membership-anonymous"; }
  static get originalStyleUrls() { return {
    "$": ["./dvn-app-activate-membership-anonymous.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["dvn-app-activate-membership-anonymous.css"]
  }; }
  static get properties() { return {
    "apiUye": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "UyeApi",
        "resolved": "UyeApi",
        "references": {
          "UyeApi": {
            "location": "import",
            "path": "@dvn/uye/api/uyeApi"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "apiKimlik": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "KimlikApi",
        "resolved": "KimlikApi",
        "references": {
          "KimlikApi": {
            "location": "import",
            "path": "@dvn/kimlik/api/kimlikApi"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "navigate": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "NavigationHandler",
        "resolved": "(config: NavigateConfig) => void",
        "references": {
          "NavigationHandler": {
            "location": "import",
            "path": "@dvn/core/routing/routing"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "storage": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Storage",
        "resolved": "Storage",
        "references": {
          "Storage": {
            "location": "import",
            "path": "@dvn/kimlik/storage/Storage.interface"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "path": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "path",
      "reflect": false
    }
  }; }
  static get states() { return {
    "error": {},
    "membershipToActivate": {},
    "renderTrigger": {},
    "isProgressing": {}
  }; }
  static get elementRef() { return "el"; }
}
injectContext(DvnAppActivateMembershipAnonymous);
