import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { c as cls } from './helpers.js';

const colorList = [
    'default',
    'primary',
    'accent',
    'danger',
    'warning',
    'success',
    'info',
    'blue',
    'indigo',
    'purple',
    'pink',
    'red',
    'orange',
    'yellow',
    'green',
    'teal',
    'cyan',
    'brown',
    'stone'
];

const styleCss = "x-avatar{display:inline-block;position:relative;margin:0px;padding:0px}x-avatar>div{display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:center;align-items:center;position:relative;width:1em;height:1em;margin:0px;padding:0px;border-radius:0.45rem;overflow:hidden;background-color:rgba(0, 0, 0, 0.1);background-position:center;background-repeat:no-repeat;background-size:cover;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-border-rgb, 200, 199, 204), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-border-rgb, 200, 199, 204), 0.35)}x-avatar>div:not(.avatar-only-letters){-webkit-transition:background-color 0.2s;transition:background-color 0.2s}x-avatar>div.avatar-image-loaded{background-color:white !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-border-rgb, 200, 199, 204), 0.35) !important;box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-border-rgb, 200, 199, 204), 0.35) !important}x-avatar>div.avatar-image-loaded span{opacity:0}x-avatar>div.avatar-image-loaded img{opacity:1}x-avatar>div.avatar-rounded,x-avatar>div.avatar-rounded img,x-avatar>div.avatar-rounded span{border-radius:50%}.is-dark-mode x-avatar>div{background-color:rgba(255, 255, 255, 0.1)}x-avatar>div img{width:100%;height:auto;-webkit-transition:0.3s;transition:0.3s;opacity:0;position:absolute}x-avatar>div span{font-size:0.45em;font-weight:normal;-webkit-transition:0.3s;transition:0.3s}x-avatar>div.avatar-primary{background-color:var(--color-primary-tinted, #7b9ef6);color:var(--color-primary-shaded, #2e52a9) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-primary-rgb, 66, 117, 242), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-primary-rgb, 66, 117, 242), 0.35)}.is-dark-mode x-avatar>div.avatar-primary{color:var(--color-primary-shadest, #1e356d) !important}x-avatar>div.avatar-accent{background-color:var(--color-accent-tinted, #f66858);color:var(--color-accent-shaded, #a91b0b) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-accent-rgb, 242, 39, 16), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-accent-rgb, 242, 39, 16), 0.35)}.is-dark-mode x-avatar>div.avatar-accent{color:var(--color-accent-shadest, #6d1207) !important}x-avatar>div.avatar-danger{background-color:var(--color-danger-tinted, #e7727d);color:var(--color-danger-shaded, #9a2530) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-danger-rgb, 220, 53, 69), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-danger-rgb, 220, 53, 69), 0.35)}.is-dark-mode x-avatar>div.avatar-danger{color:var(--color-danger-shadest, #63181f) !important}x-avatar>div.avatar-warning{background-color:var(--color-warning-tinted, #ebbf6d);color:var(--color-warning-shaded, #9f7221) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-warning-rgb, 227, 163, 47), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-warning-rgb, 227, 163, 47), 0.35)}.is-dark-mode x-avatar>div.avatar-warning{color:var(--color-warning-shadest, #664915) !important}x-avatar>div.avatar-success{background-color:var(--color-success-tinted, #4dc696);color:var(--color-success-shaded, #007a4a) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-success-rgb, 0, 174, 105), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-success-rgb, 0, 174, 105), 0.35)}.is-dark-mode x-avatar>div.avatar-success{color:var(--color-success-shadest, #004e2f) !important}x-avatar>div.avatar-info{background-color:var(--color-info-tinted, #6dc4d9);color:var(--color-info-shaded, #21778c) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-info-rgb, 47, 170, 200), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-info-rgb, 47, 170, 200), 0.35)}.is-dark-mode x-avatar>div.avatar-info{color:var(--color-info-shadest, #154d5a) !important}x-avatar>div.avatar-link{background-color:var(--color-link-tinted, #7b9ef6);color:var(--color-link-shaded, #2e52a9) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-link-rgb, 66, 117, 242), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-link-rgb, 66, 117, 242), 0.35)}.is-dark-mode x-avatar>div.avatar-link{color:var(--color-link-shadest, #1e356d) !important}x-avatar>div.avatar-blue{background-color:var(--color-blue-tinted, #6c8fcb);color:var(--color-blue-shaded, #20437f) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-blue-rgb, 45, 95, 181), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-blue-rgb, 45, 95, 181), 0.35)}.is-dark-mode x-avatar>div.avatar-blue{color:var(--color-blue-shadest, #142b51) !important}x-avatar>div.avatar-indigo{background-color:var(--color-indigo-tinted, #8792ca);color:var(--color-indigo-shaded, #3b457d) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-indigo-rgb, 84, 99, 179), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-indigo-rgb, 84, 99, 179), 0.35)}.is-dark-mode x-avatar>div.avatar-indigo{color:var(--color-indigo-shadest, #262d51) !important}x-avatar>div.avatar-purple{background-color:var(--color-purple-tinted, #a488d8);color:var(--color-purple-shaded, #583c8b) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-purple-rgb, 125, 85, 199), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-purple-rgb, 125, 85, 199), 0.35)}.is-dark-mode x-avatar>div.avatar-purple{color:var(--color-purple-shadest, #38265a) !important}x-avatar>div.avatar-pink{background-color:var(--color-pink-tinted, #f999b9);color:var(--color-pink-shaded, #ac4c6d) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-pink-rgb, 246, 109, 155), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-pink-rgb, 246, 109, 155), 0.35)}.is-dark-mode x-avatar>div.avatar-pink{color:var(--color-pink-shadest, #6f3146) !important}x-avatar>div.avatar-red{background-color:var(--color-red-tinted, #d87772);color:var(--color-red-shaded, #8b2a26) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-red-rgb, 199, 60, 54), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-red-rgb, 199, 60, 54), 0.35)}.is-dark-mode x-avatar>div.avatar-red{color:var(--color-red-shadest, #5a1b18) !important}x-avatar>div.avatar-orange{background-color:var(--color-orange-tinted, #e4a372);color:var(--color-orange-shaded, #985725) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-orange-rgb, 217, 124, 53), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-orange-rgb, 217, 124, 53), 0.35)}.is-dark-mode x-avatar>div.avatar-orange{color:var(--color-orange-shadest, #623818) !important}x-avatar>div.avatar-yellow{background-color:var(--color-yellow-tinted, #e1c670);color:var(--color-yellow-shaded, #947a23) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-yellow-rgb, 212, 174, 50), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-yellow-rgb, 212, 174, 50), 0.35)}.is-dark-mode x-avatar>div.avatar-yellow{color:var(--color-yellow-shadest, #5f4e17) !important}x-avatar>div.avatar-green{background-color:var(--color-green-tinted, #74d49c);color:var(--color-green-shaded, #278750) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-green-rgb, 56, 193, 114), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-green-rgb, 56, 193, 114), 0.35)}.is-dark-mode x-avatar>div.avatar-green{color:var(--color-green-shadest, #195733) !important}x-avatar>div.avatar-teal{background-color:var(--color-teal-tinted, #82d3cb);color:var(--color-teal-shaded, #36867f) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-teal-rgb, 77, 192, 181), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-teal-rgb, 77, 192, 181), 0.35)}.is-dark-mode x-avatar>div.avatar-teal{color:var(--color-teal-shadest, #235651) !important}x-avatar>div.avatar-cyan{background-color:var(--color-cyan-tinted, #98c9f1);color:var(--color-cyan-shaded, #4c7da5) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-cyan-rgb, 108, 178, 235), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-cyan-rgb, 108, 178, 235), 0.35)}.is-dark-mode x-avatar>div.avatar-cyan{color:var(--color-cyan-shadest, #31506a) !important}x-avatar>div.avatar-brown{background-color:var(--color-brown-tinted, #897d72);color:var(--color-brown-shaded, #3d3025) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-brown-rgb, 87, 69, 53), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-brown-rgb, 87, 69, 53), 0.35)}.is-dark-mode x-avatar>div.avatar-brown{color:var(--color-brown-shadest, #271f18) !important}x-avatar>div.avatar-stone{background-color:var(--color-stone-tinted, #747f8c);color:var(--color-stone-shaded, #27323f) !important;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-stone-rgb, 56, 72, 90), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-stone-rgb, 56, 72, 90), 0.35)}.is-dark-mode x-avatar>div.avatar-stone{color:var(--color-stone-shadest, #192029) !important}x-chip x-avatar>div{width:1.5rem !important;height:1.5rem !important;max-width:1.5rem !important;max-height:1.5rem !important}x-chip x-avatar>div span{font-size:1.1rem}x-avatar x-badge{position:absolute;bottom:-0.25em;left:-0.25em;-webkit-box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-border-rgb, 200, 199, 204), 0.35);box-shadow:0px 3px 1rem rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(var(--color-border-rgb, 200, 199, 204), 0.35);margin:0;font-size:0.25em;height:1.5em;padding-left:0.5em;padding-right:0.5em}";
const XAvatarStyle0 = styleCss;

const XAvatar = /*@__PURE__*/ proxyCustomElement(class XAvatar extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.image = undefined;
        this.letters = '?';
        this.size = '3rem';
        this.rounded = false;
        this.imageLoaded = false;
        this.imageError = false;
    }
    /**
     * Get a number index by letter
     *
     * @returns
     */
    getLetterNumber() {
        const text = (this.letters || 'A').toUpperCase();
        const size = (this.letters || 'A').length;
        let number = 0;
        for (let position = 0; position < size; position++) {
            number += (text.charCodeAt(position) - 64) * Math.pow(26, size - position - 1);
        }
        return number;
    }
    /**
     * Get the color relative to the letters
     *
     * @returns
     */
    getColorByLetters() {
        const list = colorList.filter(color => color != 'default');
        return list[this.getLetterNumber() % list.length];
    }
    /**
     * Callback on finished loaded image
     *
     * @param event
     */
    onLoadImage() {
        this.imageLoaded = true;
    }
    /**
     * Callback error on loaded image
     *
     * @param event
     */
    onErrorImage() {
        this.imageError = true;
    }
    /**
     * Render component
     */
    render() {
        var _a;
        return h(Host, { key: '8997f167d8b2aae3fdc44a91f3c851a23560a681', style: { fontSize: this.size } }, h("div", { key: '3b65c80606088abe8a243bd79906a09f15aea0ae', class: cls(`avatar-${this.getColorByLetters()}`, {
                'avatar-only-letters': !this.image,
                'avatar-image-loaded': this.imageLoaded && !this.imageError,
                'avatar-rounded': this.rounded,
            }) }, !!((_a = this.image) === null || _a === void 0 ? void 0 : _a.length) && h("img", { key: 'a9939f161e5e58b7ed6181442784c17349abd16f', src: this.image, alt: this.letters, onLoad: () => this.onLoadImage(), onError: () => this.onErrorImage() }), h("span", { key: '9c7b4ea049945034cd17c72c8a2d563aac204a10' }, this.letters.substring(0, 2))), h("slot", { key: 'b0ae678777eb40169682db3013d56b7bde7b1103' }));
    }
    static get style() { return XAvatarStyle0; }
}, [4, "x-avatar", {
        "image": [1],
        "letters": [1],
        "size": [1],
        "rounded": [4],
        "imageLoaded": [32],
        "imageError": [32]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["x-avatar"];
    components.forEach(tagName => { switch (tagName) {
        case "x-avatar":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, XAvatar);
            }
            break;
    } });
}

export { XAvatar as X, defineCustomElement as d };
