import { renderMenu } from '@dvn/core/components/dvn-app-top-menu/util';
import { doesMembershipNeedAgreementConsent, doesMembershipNeedDataCompletion, isMembershipActive } from '@dvn/core/models/membership';
import { buildRoute } from '@dvn/core/util/route';
import { capitalize } from '@dvn/core/util/string';
import { getUserInitials } from '@dvn/kimlik/api/models/User';
import { Component, h, Host, Prop } from '@stencil/core';
const dropdownWidth = '184px';
export class DvnAppTopMenu {
  render() {
    const { appConfig, membership, memberships, user, viewId } = this;
    const showSpaceRouteOptions = appConfig && membership
      && isMembershipActive(membership)
      && !doesMembershipNeedAgreementConsent(membership)
      && !doesMembershipNeedDataCompletion(membership);
    const membershipOptions = membership ? memberships.filter(m => m._id !== (membership === null || membership === void 0 ? void 0 : membership._id)) : memberships;
    return (h(Host, null,
      memberships.length > 0 &&
        h("div", { class: { 'space-info-container': true, 'flex-grow-1': true } },
          h("dvn-dropdown", { placement: "bottomLeft", trigger: "click", leaned: true },
            membership
              ? h("dvn-info-summary", { title: membership.config.space.name, subTitle: capitalize(membership.config.roleName), leaned: true }, membership.config.space.logoUrl &&
                h("dvn-image", { bordered: true, slot: "media", src: membership.config.space.logoUrl }))
              : h("dvn-info-summary", { title: "Select your space" }),
            h("div", { slot: "content" },
              showSpaceRouteOptions &&
                h("div", { class: "menu-container flex-grow-1" }, renderMenu(viewId, membership, appConfig.mainNavigation)),
              h("dvn-menu", { leaned: true }, membershipOptions.map(m => (h("dvn-menu-item", { leaned: true, onClick: () => this.navigate({ path: buildRoute(m.config.space._id, m.config._id, m._id) }) },
                h("dvn-info-summary", { title: m.config.space.name, subTitle: capitalize(m.config.roleName), width: dropdownWidth })))))))),
      h("div", { class: "user-info-container" },
        h("dvn-dropdown", { placement: "bottomRight", trigger: "click" },
          h("dvn-image", { bordered: true, src: user.imageUrl, shape: "circle", text: getUserInitials(user) }),
          h("div", { slot: "content" },
            h("dvn-menu", { leaned: true },
              h("dvn-menu-item", null,
                h("kimlik-logout-action", null,
                  h("dvn-info-summary", { title: "Logout", width: "120px" })))))))));
  }
  static get is() { return "dvn-app-top-menu"; }
  static get originalStyleUrls() { return {
    "$": ["dvn-app-top-menu.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["dvn-app-top-menu.css"]
  }; }
  static get properties() { return {
    "appConfig": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "AppConfig",
        "resolved": "AppConfig",
        "references": {
          "AppConfig": {
            "location": "import",
            "path": "@dvn/core/models/app-config"
          }
        }
      },
      "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": ""
      }
    },
    "memberships": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Membership[]",
        "resolved": "Membership[]",
        "references": {
          "Membership": {
            "location": "import",
            "path": "@dvn/core/models/membership"
          }
        }
      },
      "required": false,
      "optional": false,
      "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": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    },
    "viewId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "view-id",
      "reflect": false
    },
    "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": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
}
