import React__default, { useState } from 'react';
import '@emotion/core';
import { a as __assign, b as __makeTemplateObject } from './_tslib-5c49bd3f.js';
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
import '@emotion/styled';
import '@emotion/react';
import { s as styled } from './css-efbd0d2d.js';
import { u as useId } from './auto-id.esm-bfe8e225.js';
import { u as useCustomCss, a as usePrevious } from './utilities-357c56e6.js';

var UserCard = function (_a) {
    var displayName = _a.displayName, username = _a.username, _b = _a.photoURL, photoURL = _b === void 0 ? '' : _b, userProvidedId = _a.id, _c = _a.placeholderSrc, placeholderSrc = _c === void 0 ? 'https://icon-library.com/images/default-profile-icon/default-profile-icon-5.jpg' : _c, onClick = _a.onClick, _d = _a.customCss, customCss = _d === void 0 ? '' : _d;
    var id = useId(userProvidedId);
    var resolvedCss = useCustomCss(customCss);
    var _e = React__default.useState(true), loading = _e[0], setLoading = _e[1];
    var _f = useState(placeholderSrc), currentSrc = _f[0], updateSrc = _f[1];
    var prevPhotoUrl = usePrevious(photoURL);
    React__default.useEffect(function () {
        if (loading || (photoURL && prevPhotoUrl !== photoURL)) {
            var imageToLoad = new Image();
            imageToLoad.src = photoURL;
            imageToLoad.onload = function () {
                setLoading(false);
                updateSrc(photoURL);
            };
        }
    }, [photoURL, loading, prevPhotoUrl]);
    return (jsx(StyledCardButton, __assign({ onClick: onClick, css: resolvedCss, id: id }, { children: jsxs(StyledWrapperDiv, { children: [jsx(StyledImgDiv, { src: currentSrc }, void 0),
                jsxs(StyledTextDiv, { children: [jsx(StyledTitle, { children: displayName }, void 0),
                        jsx(StyledSubTitle, { children: username }, void 0)] }, void 0)] }, void 0) }), void 0));
};
var StyledCardButton = styled('button')(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  background: rgba(255, 255, 255, 0.36) no-repeat padding-box;\n  border: none;\n  outline: none;\n  border-radius: 20px 6px 6px 20px;\n  opacity: 1;\n  height: 42px;\n  max-width: fit-content;\n  min-width: 171px;\n  &:focus-visible {\n    box-shadow: 0 0 0 2px ", ";\n  }\n  &:hover {\n    background: rgba(255, 255, 255, 0.57);\n  }\n"], ["\n  background: rgba(255, 255, 255, 0.36) no-repeat padding-box;\n  border: none;\n  outline: none;\n  border-radius: 20px 6px 6px 20px;\n  opacity: 1;\n  height: 42px;\n  max-width: fit-content;\n  min-width: 171px;\n  &:focus-visible {\n    box-shadow: 0 0 0 2px ", ";\n  }\n  &:hover {\n    background: rgba(255, 255, 255, 0.57);\n  }\n"])), function (_a) {
    var theme = _a.theme;
    return theme.colors.inputFocus;
});
var StyledWrapperDiv = styled('div')(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  display: flex;\n  flex-direction: row;\n  align-items: center;\n"], ["\n  display: flex;\n  flex-direction: row;\n  align-items: center;\n"])));
var StyledImgDiv = styled('div')(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n  background-image: url(", ");\n  background-size: cover;\n  background-position: center center;\n  min-height: 34px;\n  min-width: 34px;\n  width: 34px;\n  height: 34px;\n  border-radius: 50%;\n  border: 1px solid #445b88;\n"], ["\n  background-image: url(", ");\n  background-size: cover;\n  background-position: center center;\n  min-height: 34px;\n  min-width: 34px;\n  width: 34px;\n  height: 34px;\n  border-radius: 50%;\n  border: 1px solid #445b88;\n"])), function (_a) {
    var src = _a.src;
    return src;
});
var StyledTextDiv = styled('div')(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n  display: block;\n  text-align: left;\n  padding-left: 7px;\n"], ["\n  display: block;\n  text-align: left;\n  padding-left: 7px;\n"])));
var StyledTitle = styled('div')(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n  font-size: 14px;\n  font-weight: 600;\n"], ["\n  font-size: 14px;\n  font-weight: 600;\n"])));
var StyledSubTitle = styled('div')(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n  font-size: 11px;\n  font-style: italic;\n"], ["\n  font-size: 11px;\n  font-style: italic;\n"])));
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;

export { UserCard };
//# sourceMappingURL=UserCard.js.map
