import { renderMenu } from '@dvn/core/components/dvn-app-left-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 { getUserFullName, getUserInitials } from '@dvn/kimlik/api/models/User';
import { Component, Event, h, Host, Prop } from '@stencil/core';
const menuWidth = '200px';
const dropdownWidth = '184px';
export class DvnAppLeftMenu {
  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" },
          h("dvn-dropdown", { placement: "bottomLeft", trigger: "hover", width: menuWidth, leaned: true },
            h("dvn-card", { leaned: true, bodyLeaned: true, elevation: 0 },
              membership
                ? h("dvn-info-summary", { title: membership.config.space.name, subTitle: capitalize(membership.config.roleName) }, membership.config.space.logoUrl &&
                  h("dvn-image", { slot: "media", src: membership.config.space.logoUrl, shape: "circle" }))
                : h("dvn-info-summary", { title: "Select your space" }),
              membershipOptions.length > 0 &&
                h("div", { class: "menu-dropdown-icon" },
                  h("i", { class: "uil uil-angle-down" }))),
            h("div", { slot: "content" },
              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 })))))))),
      showSpaceRouteOptions &&
        h("div", { class: "menu-container" }, renderMenu(viewId, membership, appConfig.mainNavigation)),
      membership &&
        h("div", { class: "separator" }),
      h("div", { class: "user-info-container" },
        h("dvn-dropdown", { placement: "topRight", trigger: "hover", width: menuWidth, leaned: true },
          h("dvn-info-summary", { title: getUserFullName(user), leaned: true },
            h("dvn-image", { bordered: true, slot: "media", 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", { kimlikApi: this.apiKimlik, storage: this.storage, navigate: this.navigate },
                  h("dvn-info-summary", { title: "Logout", width: "120px" }))))))),
      h("div", { class: "space-holder" }),
      h("dvn-input-group", { leaned: true },
        h("dvn-button", { view: this.theme.name === 'dvn-dark' ? 'flat' : 'solid', onClick: () => this.themeChange.emit('dvn-light') },
          h("dvn-icon", { iconName: "uil-sun" })),
        h("dvn-button", { view: this.theme.name === 'dvn-light' ? 'flat' : 'solid', onClick: () => this.themeChange.emit('dvn-dark') },
          h("dvn-icon", { iconName: "uil-moon" })))));
  }
  static get is() { return "dvn-app-left-menu"; }
  static get originalStyleUrls() { return {
    "$": ["dvn-app-left-menu.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["dvn-app-left-menu.css"]
  }; }
  static get properties() { return {
    "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": ""
      }
    },
    "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": ""
      }
    },
    "theme": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "AlacaTheme",
        "resolved": "AlacaTheme",
        "references": {
          "AlacaTheme": {
            "location": "import",
            "path": "@dvn/alaca/theme"
          }
        }
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get events() { return [{
      "method": "themeChange",
      "name": "themeChange",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
}
