import * as tslib_1 from "tslib";
import * as React from 'react';
import { css, divProperties, getInitials, getNativeProps, getRTL } from '../../Utilities';
import { Image, ImageFit, ImageLoadState } from '../../Image';
import { PersonaPresence } from './PersonaPresence';
import { PersonaPresence as PersonaPresenceEnum, PersonaSize } from './Persona.types';
import { Icon } from '../../Icon';
import * as stylesImport from './PersonaCoin.scss';
var styles = stylesImport;
var SIZE_TO_PIXELS = (_a = {},
    _a[PersonaSize.tiny] = 20,
    _a[PersonaSize.extraExtraSmall] = 24,
    _a[PersonaSize.extraSmall] = 28,
    _a[PersonaSize.small] = 40,
    _a[PersonaSize.regular] = 48,
    _a[PersonaSize.large] = 72,
    _a[PersonaSize.extraLarge] = 100,
    _a[PersonaSize.size24] = 24,
    _a[PersonaSize.size28] = 28,
    _a[PersonaSize.size10] = 20,
    _a[PersonaSize.size32] = 32,
    _a[PersonaSize.size40] = 40,
    _a[PersonaSize.size48] = 48,
    _a[PersonaSize.size72] = 72,
    _a[PersonaSize.size100] = 100,
    _a);
import { mergeStyles } from '../../Styling';
import { initialsColorPropToColorCode } from './PersonaInitialsColor';
export var PERSONACOIN_SIZE = (_b = {},
    // All non-numerically named sizes are deprecated, use the numerically named classes below
    _b[PersonaSize.tiny] = 'ms-Persona--tiny ' + styles.rootIsSize10,
    _b[PersonaSize.extraExtraSmall] = 'ms-Persona--xxs ' + styles.rootIsSize24,
    _b[PersonaSize.extraSmall] = 'ms-Persona--xs ' + styles.rootIsSize28,
    _b[PersonaSize.small] = 'ms-Persona--sm ' + styles.rootIsSize40,
    _b[PersonaSize.regular] = '',
    _b[PersonaSize.large] = 'ms-Persona--lg ' + styles.rootIsSize72,
    _b[PersonaSize.extraLarge] = 'ms-Persona--xl ' + styles.rootIsSize100,
    _b[PersonaSize.size10] = 'ms-Persona--size10 ' + styles.rootIsSize10,
    _b[PersonaSize.size16] = 'ms-Persona--size16 ' + styles.rootIsSize16,
    _b[PersonaSize.size24] = 'ms-Persona--size24 ' + styles.rootIsSize24,
    _b[PersonaSize.size28] = 'ms-Persona--size28 ' + styles.rootIsSize28,
    _b[PersonaSize.size32] = 'ms-Persona--size32 ' + styles.rootIsSize32,
    _b[PersonaSize.size40] = 'ms-Persona--size40 ' + styles.rootIsSize40,
    _b[PersonaSize.size48] = 'ms-Persona--size48 ' + styles.rootIsSize48,
    _b[PersonaSize.size72] = 'ms-Persona--size72 ' + styles.rootIsSize72,
    _b[PersonaSize.size100] = 'ms-Persona--size100 ' + styles.rootIsSize100,
    _b);
var PersonaCoin = /** @class */ (function (_super) {
    tslib_1.__extends(PersonaCoin, _super);
    function PersonaCoin(props) {
        var _this = _super.call(this, props) || this;
        _this._onRenderCoin = function (props) {
            var _a = _this.props, coinSize = _a.coinSize, imageUrl = _a.imageUrl, imageAlt = _a.imageAlt, imageShouldFadeIn = _a.imageShouldFadeIn, imageShouldStartVisible = _a.imageShouldStartVisible;
            var size = _this.props.size;
            return (React.createElement(Image, { className: css('ms-Persona-image', styles.image), imageFit: ImageFit.cover, src: imageUrl, width: coinSize || SIZE_TO_PIXELS[size], height: coinSize || SIZE_TO_PIXELS[size], alt: imageAlt, shouldFadeIn: imageShouldFadeIn, shouldStartVisible: imageShouldStartVisible, onLoadingStateChange: _this._onPhotoLoadingStateChange }));
        };
        _this._onRenderInitials = function (props) {
            var imageInitials = props.imageInitials;
            var primaryText = props.primaryText;
            var allowPhoneInitials = props.allowPhoneInitials;
            var isRTL = getRTL();
            imageInitials = imageInitials || getInitials(primaryText, isRTL, allowPhoneInitials);
            return (imageInitials !== '' ?
                React.createElement("span", null, imageInitials) :
                React.createElement(Icon, { iconName: 'Contact' }));
        };
        _this._onPhotoLoadingStateChange = function (loadState) {
            _this.setState({
                isImageLoaded: loadState === ImageLoadState.loaded,
                isImageError: loadState === ImageLoadState.error
            });
            if (_this.props.onPhotoLoadingStateChange) {
                _this.props.onPhotoLoadingStateChange(loadState);
            }
        };
        _this.state = {
            isImageLoaded: false,
            isImageError: false
        };
        return _this;
    }
    PersonaCoin.prototype.render = function () {
        var _a = this.props, coinProps = _a.coinProps, coinSize = _a.coinSize, imageUrl = _a.imageUrl, _b = _a.onRenderCoin, onRenderCoin = _b === void 0 ? this._onRenderCoin : _b, _c = _a.onRenderInitials, onRenderInitials = _c === void 0 ? this._onRenderInitials : _c;
        var size = this.props.size;
        var divProps = getNativeProps(this.props, divProperties);
        var coinSizeStyle = coinSize ? { width: coinSize, height: coinSize } : undefined;
        return (React.createElement("div", tslib_1.__assign({}, divProps, { className: css('ms-Persona-coin', PERSONACOIN_SIZE[size], coinProps && coinProps.className) }),
            (size !== PersonaSize.size10 && size !== PersonaSize.tiny) ? (React.createElement("div", tslib_1.__assign({}, coinProps, { className: css('ms-Persona-imageArea', styles.imageArea), style: coinSizeStyle }),
                !this.state.isImageLoaded &&
                    (!imageUrl || this.state.isImageError) &&
                    (React.createElement("div", { className: css('ms-Persona-initials', styles.initials, mergeStyles({
                            backgroundColor: initialsColorPropToColorCode(this.props)
                        })), style: coinSizeStyle, "aria-hidden": 'true' }, onRenderInitials(this.props, this._onRenderInitials))),
                onRenderCoin(this.props, this._onRenderCoin),
                React.createElement(PersonaPresence, tslib_1.__assign({}, this.props)))) :
                (this.props.presence ?
                    React.createElement(PersonaPresence, tslib_1.__assign({}, this.props)) :
                    React.createElement(Icon, { iconName: 'Contact', className: styles.size10NoPresenceIcon })),
            this.props.children));
    };
    PersonaCoin.defaultProps = {
        primaryText: '',
        size: PersonaSize.size48,
        presence: PersonaPresenceEnum.none,
        imageAlt: ''
    };
    return PersonaCoin;
}(React.Component));
export { PersonaCoin };
var _a, _b;
//# sourceMappingURL=PersonaCoin.js.map