import { getUserInitials } from '@dvn/kimlik/api/models/User';
import { Component, Element, h, Host, Prop, State } from '@stencil/core';
import { injectContext } from '../../global/context';
function wrapContent(content) {
  return (h(Host, { class: "d-block row justify-content-center pt-3" },
    h("div", { class: "col mt-3" }, content)));
}
export class DvnAppActivateMembership {
  constructor() {
    this.renderTrigger = 0;
    this.isProgressing = false;
  }
  async activateMembership() {
    const { membership } = this;
    const result = await this.apiUye.activateMembership(membership.config._id, membership._id).catch(e => {
      console.log(e);
    });
    if (!result)
      return;
    this.appContextInvalidator();
  }
  render() {
    const { membership, user } = this;
    if (!membership) {
      return wrapContent(h("dvn-progress", { indefinite: true }));
    }
    // TODO handle this scenario
    // if membership and session users don't match, show 'mismatch user' message
    // if (isUserLoggedIn() && getSessionData().uid !== membership.user._id) {
    //   return wrapContent(
    //     <div class="d-flex flex-column align-items-center">
    //       <p>
    //         This membership is created for <b>{membership.user.email} </b>
    //         but you're logged in from a different account. Please logout in order to proceed.
    //       </p>
    //       <kimlik-logout-action redirectTo={location.pathname} sendApiRequest={false}>
    //         <dvn-button shape="rounded" tint="primary">
    //           Logout
    //         </dvn-button>
    //       </kimlik-logout-action>
    //     </div>
    //   );
    // }
    return wrapContent(h("div", { class: "text-centered" },
      h("div", { class: "d-flex align-items-center justify-content-center" },
        h("dvn-image", { bordered: true, src: membership.config.space.logoUrl, size: 64, text: membership.config.space.name[0] }),
        h("dvn-icon", { iconName: "uil uil-plus", scale: "large" }),
        h("dvn-image", { bordered: true, src: user.imageUrl, size: 64, shape: "circle", text: getUserInitials(user) })),
      h("p", null,
        "You're invited as ",
        h("i", null, membership.config.roleName),
        " to join ",
        membership.config.space.name,
        "."),
      h("dvn-button", { onClick: () => this.activateMembership(), tint: "primary" }, "Accept Invitation")));
  }
  static get is() { return "dvn-app-activate-membership"; }
  static get originalStyleUrls() { return {
    "$": ["./dvn-app-activate-membership.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["dvn-app-activate-membership.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/kimlik-api"
          }
        }
      },
      "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
    },
    "appContextInvalidator": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "AppContextInvalidator",
        "resolved": "() => void",
        "references": {
          "AppContextInvalidator": {
            "location": "import",
            "path": "@dvn/core/global/context/context"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "membership": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Membership",
        "resolved": "Membership",
        "references": {
          "Membership": {
            "location": "import",
            "path": "@dvn/core/models/membership"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "user": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "User",
        "resolved": "User",
        "references": {
          "User": {
            "location": "import",
            "path": "@dvn/kimlik/api/models"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "error": {},
    "renderTrigger": {},
    "isProgressing": {}
  }; }
  static get elementRef() { return "el"; }
}
injectContext(DvnAppActivateMembership);
