import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { g as getIconPath } from './mer-animated-dots.js';
import 'lit';
import 'lit/directives/when.js';
import 'lit/directives/if-defined.js';
import { L as Locale } from './locale.js';

/**
 * Returns initials from the first two words of a name. Returns "X" for invalid input.
 *
 * @param name - The full name string.
 * @returns Initials of the first two words, or "X" if invalid.
 *
 * Example:
 * getInitialsFromName("John Doe") -> "JD"
 * getInitialsFromName("Jane") -> "J"
 * getInitialsFromName("") -> "X"
 */
const getInitialsFromName = (name) => {
    if (typeof name !== "string" || name.trim() === "") {
        return "X";
    }
    const nameData = name.split(" ").filter(Boolean); // Remove any empty strings from splitting
    if (nameData.length === 1) {
        return nameData[0][0].toUpperCase();
    }
    else {
        return `${nameData[0][0].toUpperCase()}${nameData[1][0].toUpperCase()}`;
    }
};
/**
 * Limits the full name to the first two words. Returns null for invalid input.
 *
 * @param fullName - The full name string to be limited.
 * @returns The first two words of the full name, or null if invalid.
 *
 * Example:
 * limitFullName("John Doe Smith") -> "John Doe"
 * limitFullName("Jane") -> "Jane"
 * limitFullName("") -> null
 */
const limitFullName = (fullName) => {
    if (typeof fullName !== "string" || fullName.trim() === "") {
        return null;
    }
    const fullNameData = fullName.split(" ").filter(Boolean); // Remove any empty strings from splitting
    if (fullNameData.length === 1) {
        return fullNameData[0];
    }
    else {
        return `${fullNameData[0]} ${fullNameData[1]}`;
    }
};

const currentUserInfoCss = ":host{display:inline-grid;justify-items:end;block-size:100%}.dropdown::part(expandable-button){display:grid;grid-template-columns:max-content max-content max-content;align-items:center;gap:var(--spacing-gap-l);block-size:auto;cursor:pointer}.user-login__details{display:grid;grid-template-rows:max-content max-content;gap:var(--spacing-gap-xs);justify-items:end}.user-login__name{font-weight:var(--font-style-semi-bold);font-size:var(--font-size-body-s);color:var(--color-text-neutral-default)}.user-login__name,.user-login__organization{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-inline-size:120px;display:inline-block;line-height:1 !important}.user-login__avatar{font-size:9px;flex:0 0 auto;display:flex;align-items:center;justify-content:center;block-size:24px;inline-size:24px;color:var(--color-text-neutral-default);border-radius:50%;background-color:var(--color-accent-neutral-contrast);border:1px solid var(--color-border-primary-on-default)}.user-login__footer{display:flex;flex-direction:column;gap:var(--spacing-gap-m)}.user-login__footer :where(button,a){all:unset;display:inline-flex;align-items:center;user-select:none;touch-action:manipulation;cursor:pointer}.user-login__footer button:disabled{pointer-events:none}.user-login__footer .agreement-link{text-decoration:underline;cursor:pointer;}";

var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m")
        throw new TypeError("Private method is not writable");
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _GxIdeNewEnvironment_componentLocale, _GxIdeNewEnvironment_initials, _GxIdeNewEnvironment_menuDropdownModel, _GxIdeNewEnvironment_userLoginButton, _GxIdeNewEnvironment_dropDownitemClickHandler;
const CSS_BUNDLES = [
    // TODO: review if "utils/form--full" is required.
    "resets/box-sizing",
    "components/tooltip",
    "components/switch",
    "components/icon",
    "components/dropdown",
    "utils/layout",
    "utils/typography",
    "utils/spacing",
    "chameleon/scrollbar"
];
const CHEVRON_DOWN_ICON = getIconPath({
    category: "navigation",
    name: "chevron-down",
    colorType: "interactive"
});
const MY_ACCOUNT_ID = "my-account";
const CHANGE_TEAM_ID = "change-team";
const SIGN_OUT_ID = "sign-out";
const LANGUAGE_ID = "language";
const GxIdeNewEnvironment = /*@__PURE__*/ proxyCustomElement(class GxIdeNewEnvironment extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        _GxIdeNewEnvironment_componentLocale.set(this, void 0);
        _GxIdeNewEnvironment_initials.set(this, "");
        // #mode: Mode;
        _GxIdeNewEnvironment_menuDropdownModel.set(this, void 0);
        _GxIdeNewEnvironment_userLoginButton.set(this, void 0);
        // #handleModeSwitch = () => {
        //   this.#mode = this.#mode === "dark" ? "light" : "dark";
        //   if (this.changeModeCallback) {
        //     this.changeModeCallback(this.#mode);
        //   }
        // };
        _GxIdeNewEnvironment_dropDownitemClickHandler.set(this, (event) => {
            const id = event.detail.id;
            if (id === MY_ACCOUNT_ID) ;
            else if (id === CHANGE_TEAM_ID) {
                this.changeTeamCallback();
            }
            else if (id === SIGN_OUT_ID) {
                this.signOutCallback();
            }
            else if (id === LANGUAGE_ID) {
                this.changeLanguageCallback();
            }
        });
        this.showMenu = false;
        this.userInfo = undefined;
        this.myAccountCallback = undefined;
        this.changeTeamCallback = undefined;
        this.changeLanguageCallback = undefined;
        this.changeModeCallback = undefined;
        this.menuAlign = undefined;
        this.signOutCallback = undefined;
        this.termsCallback = undefined;
        this.privacyCallback = undefined;
    }
    async componentWillLoad() {
        __classPrivateFieldSet(this, _GxIdeNewEnvironment_componentLocale, await Locale.getComponentStrings(this.el), "f");
        __classPrivateFieldSet(this, _GxIdeNewEnvironment_initials, getInitialsFromName(this.userInfo.name), "f");
        __classPrivateFieldSet(this, _GxIdeNewEnvironment_menuDropdownModel, [
            // {
            //   id: MY_ACCOUNT_ID,
            //   caption: this.#componentLocale.myAccountLabel,
            //   showSeparator: false
            // },
            {
                id: CHANGE_TEAM_ID,
                caption: __classPrivateFieldGet(this, _GxIdeNewEnvironment_componentLocale, "f").changeTeamLabel
            },
            {
                id: SIGN_OUT_ID,
                caption: __classPrivateFieldGet(this, _GxIdeNewEnvironment_componentLocale, "f").signOutLabel
            },
            {
                type: "separator"
            },
            {
                type: "slot",
                id: "agreement"
            }
        ], "f");
    }
    render() {
        var _a, _b;
        const userName = limitFullName((_a = this.userInfo) === null || _a === void 0 ? void 0 : _a.name);
        return (h(Host, { class: "widget" }, h("ch-theme", { model: CSS_BUNDLES }), h("ch-action-menu-render", { class: "dropdown user-login__button", model: __classPrivateFieldGet(this, _GxIdeNewEnvironment_menuDropdownModel, "f"), inlineAlign: "inside-end", blockAlign: "outside-end", onButtonClick: __classPrivateFieldGet(this, _GxIdeNewEnvironment_dropDownitemClickHandler, "f") }, h("div", { class: "user-login__details" }, userName ? (h("span", { class: "body-semi-bold-s user-login__name" }, userName)) : null, ((_b = this.userInfo) === null || _b === void 0 ? void 0 : _b.team) ? (h("span", { class: "body-regular-xs user-login__organization" }, this.userInfo.team)) : null), h("div", { class: "user-login__avatar" }, __classPrivateFieldGet(this, _GxIdeNewEnvironment_initials, "f")), h("ch-image", { src: CHEVRON_DOWN_ICON, class: "icon-m", containerRef: __classPrivateFieldGet(this, _GxIdeNewEnvironment_userLoginButton, "f") }), h("div", { class: "user-login__footer footer-slot", slot: "agreement" }, h("button", { class: "body-regular-s agreement-link", onClick: this.termsCallback }, __classPrivateFieldGet(this, _GxIdeNewEnvironment_componentLocale, "f").termsAndConditionsCaption), h("button", { class: "body-regular-s\tagreement-link", onClick: this.privacyCallback }, __classPrivateFieldGet(this, _GxIdeNewEnvironment_componentLocale, "f").privacyPolicyCaption)))));
    }
    static get assetsDirs() { return ["gx-ide-assets/current-user-info"]; }
    get el() { return this; }
    static get style() { return currentUserInfoCss; }
}, [1, "gx-ide-current-user-info", {
        "userInfo": [16],
        "myAccountCallback": [16],
        "changeTeamCallback": [16],
        "changeLanguageCallback": [16],
        "changeModeCallback": [16],
        "menuAlign": [16],
        "signOutCallback": [16],
        "termsCallback": [16],
        "privacyCallback": [16],
        "showMenu": [32]
    }]);
_GxIdeNewEnvironment_componentLocale = new WeakMap(), _GxIdeNewEnvironment_initials = new WeakMap(), _GxIdeNewEnvironment_menuDropdownModel = new WeakMap(), _GxIdeNewEnvironment_userLoginButton = new WeakMap(), _GxIdeNewEnvironment_dropDownitemClickHandler = new WeakMap();
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["gx-ide-current-user-info"];
    components.forEach(tagName => { switch (tagName) {
        case "gx-ide-current-user-info":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, GxIdeNewEnvironment);
            }
            break;
    } });
}

const GxIdeCurrentUserInfo = GxIdeNewEnvironment;
const defineCustomElement = defineCustomElement$1;

export { GxIdeCurrentUserInfo, defineCustomElement };

//# sourceMappingURL=gx-ide-current-user-info.js.map