"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../tslib.es6-C4EgNkz1.js"),o=require("react"),h=require("classnames"),b=require("../icons/ebay-icon-avatar-signed-out/index.js"),l=["teal","light-teal","green","lime","yellow","orange","magenta","pink"];function A(e,t){if(t)return t;let n=0,a,r;if(e&&e.length>0)for(r=0;r<e.length;r++)a=e.charCodeAt(r),n=(n<<5)-n+a,n|=0;const c=l.length,s=Math.abs(n)%c;return l[s]}function g(e){return e&&(e<3/4||e<4/3)}const v=o.createContext(null),f=e=>{var{size:t,color:n,username:a,children:r,className:c,knownAspectRatio:s}=e,i=u.__rest(e,["size","color","username","children","className","knownAspectRatio"]);const[m,d]=o.useState(g(s)?"fit":"cover");return o.createElement(v.Provider,{value:{setImagePlacement:d}},o.createElement("div",Object.assign({},i,{role:"img",className:h("avatar",c,t&&`avatar--${t}`,m==="fit"&&"avatar--fit",a&&!r&&`avatar--${A(a,n)}`)}),r||a?.charAt(0).toUpperCase()||o.createElement(b.EbayIconAvatarSignedOut,null)))};function E(e,t){if(!e)throw new Error(t)}const y=e=>{var{onLoad:t}=e,n=u.__rest(e,["onLoad"]);const a=o.useContext(v);E(a,"EbayAvatarImage needs to be used with EbayAvatar component");const r=c=>{const s=c.target,i=s.naturalWidth/s.naturalHeight;a.setImagePlacement(g(i)?"fit":"cover"),t?.(c)};return o.createElement("img",Object.assign({onLoad:r},n))};exports.EbayAvatar=f;exports.EbayAvatarImage=y;
