import{__decorate as t}from"tslib";import{html as r}from"lit";import{property as e,state as a,customElement as i}from"lit/decorators.js";import{classMap as s}from"lit/directives/class-map.js";import{s as o}from"./nile-avatar.css.esm.js";import{N as n}from"../internal/nile-element.esm.js";import"../internal/accessibility/a11y.state.enum.esm.js";import"../internal/accessibility/a11y.property.enum.esm.js";import"../internal/accessibility/role.enum.esm.js";let l=class extends n{constructor(){super(...arguments),this.src="",this.variant="text",this.icon="var(--nile-icon-user, var(--ng-icon-user-01))",this.name="",this.bgColor="",this.textColor="",this.borderColor="",this.size="md",this.isRounded=!0,this.imageError=!1}static get styles(){return[o]}generateInitials(){if(!this.name)return"";const t=this.name.split(" ").filter((t=>t.length>0)).map((t=>t.charAt(0).toUpperCase())).slice(0,2);return t.length>1?t[0]+t[1]:t[0]}generateVariantCode(t){const r=t.charCodeAt(0),e=1==t.length?r:t.charCodeAt(1);return(r*e+r%23+e%23)%5}getDefaultIconSize(){switch(this.size){case"xs":return"6";case"sm":return"10";case"md":default:return"16";case"lg":return"20";case"xl":return"24";case"2xl":return"28"}}render(){if("image"!=this.variant||this.imageError){const t=this.generateInitials();return"text"==this.variant&&t?this.getContentWrapped(r`${t}`,t):this.getContentWrapped(this.getIconContent(),t)}return this.getImageContent()}getContentWrapped(t,e){const a=this.generateVariantCode(e);return r`
    <div
      class=${s({text__avatar:!0,avatar__xs:"xs"===this.size,avatar__small:"sm"===this.size,avatar__medium:"md"===this.size,avatar__large:"lg"===this.size,avatar__extralarge:"xl"===this.size,avatar__2xl:"2xl"===this.size,avatar__rounded:this.isRounded,variant__orange:0===a&&!this.bgColor,variant__pink:1===a&&!this.bgColor,variant__blue:2===a&&!this.bgColor,variant__light_blue:3===a&&!this.bgColor,variant__green:4===a&&!this.bgColor})}
      aria-hidden="true"
      part="avatar__content"
      style="
        background-color: ${this.bgColor};
        color:${this.textColor?this.textColor:"var(--nile-colors-white-base, var(--ng-colors-text-quaternary-500))"};
        border: 1px solid ${this.borderColor?this.borderColor:"var(--nile-colors-neutral-500 , var(--ng-colors-border-secondary))"};
        border-color:${e?`${this.borderColor?this.borderColor:"var(--nile-colors-neutral-500 , var(--ng-colors-border-secondary))"}`:"var(--nile-colors-neutral-500 , var(--ng-colors-border-secondary))"}"
    >
      ${t}
    </div>`}getIconContent(){return r`
    <nile-icon
      name="${this.icon}"
      method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))"
      color="${this.textColor?this.textColor:"var(--nile-colors-dark-500, var(--ng-colors-text-quaternary-500))"}"
      size="${this.getDefaultIconSize()}"
    ></nile-icon>`}getImageContent(){return r` 
    <img
      src="${this.src}"
      class="avatar"
      alt="${this.name||"Avatar"}"
      class=${s({avatar:!0,avatar__xs:"xs"===this.size,avatar__small:"sm"===this.size,avatar__medium:"md"===this.size,avatar__large:"lg"===this.size,avatar__extralarge:"xl"===this.size,avatar__2xl:"2xl"===this.size,avatar__rounded:this.isRounded})}
      part="avatar__image"
      style="	background-image: url(${this.src}), linear-gradient(lightgray, lightgray);"
      @error="${()=>this.imageError=!0}"
      @load="${()=>this.imageError=!1}"
    />`}};t([e({type:String,reflect:!0})],l.prototype,"src",void 0),t([e({type:String,reflect:!0})],l.prototype,"variant",void 0),t([e({type:String,reflect:!0})],l.prototype,"icon",void 0),t([e({type:String,reflect:!0})],l.prototype,"name",void 0),t([e({type:String,reflect:!0,attribute:"bg-color"})],l.prototype,"bgColor",void 0),t([e({type:String,reflect:!0,attribute:"text-color"})],l.prototype,"textColor",void 0),t([e({type:String,reflect:!0,attribute:"border-color"})],l.prototype,"borderColor",void 0),t([e({reflect:!0})],l.prototype,"size",void 0),t([e({type:Boolean,reflect:!0})],l.prototype,"isRounded",void 0),t([a()],l.prototype,"imageError",void 0),l=t([i("nile-avatar")],l);export{l as N};
