'use strict';

var _extends = require('../../../../../@babel_runtime@7.24.8/node_modules/@babel/runtime/helpers/esm/extends.cjs');
var React = require('react');
var index = require('../../../../../@radix-ui_react-context@1.0.1_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-context/dist/index.cjs');
var index$2 = require('../../../../../@radix-ui_react-use-callback-ref@1.0.1_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs');
var index$3 = require('../../../../../@radix-ui_react-use-layout-effect@1.0.1_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs');
var index$1 = require('../../../../../@radix-ui_react-primitive@1.0.3_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@18.3._44pjkdrkjq3hxuh62jsxoggm4e/node_modules/@radix-ui/react-primitive/dist/index.cjs');

/* -------------------------------------------------------------------------------------------------
 * Avatar
 * -----------------------------------------------------------------------------------------------*/ const $cddcb0b647441e34$var$AVATAR_NAME = 'Avatar';
const [$cddcb0b647441e34$var$createAvatarContext, $cddcb0b647441e34$export$90370d16b488820f] = index.createContextScope($cddcb0b647441e34$var$AVATAR_NAME);
const [$cddcb0b647441e34$var$AvatarProvider, $cddcb0b647441e34$var$useAvatarContext] = $cddcb0b647441e34$var$createAvatarContext($cddcb0b647441e34$var$AVATAR_NAME);
const $cddcb0b647441e34$export$e2255cf6045e8d47 = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
    const { __scopeAvatar: __scopeAvatar , ...avatarProps } = props;
    const [imageLoadingStatus, setImageLoadingStatus] = React.useState('idle');
    return /*#__PURE__*/ React.createElement($cddcb0b647441e34$var$AvatarProvider, {
        scope: __scopeAvatar,
        imageLoadingStatus: imageLoadingStatus,
        onImageLoadingStatusChange: setImageLoadingStatus
    }, /*#__PURE__*/ React.createElement(index$1.Primitive.span, _extends.default({}, avatarProps, {
        ref: forwardedRef
    })));
});
/* -------------------------------------------------------------------------------------------------
 * AvatarImage
 * -----------------------------------------------------------------------------------------------*/ const $cddcb0b647441e34$var$IMAGE_NAME = 'AvatarImage';
const $cddcb0b647441e34$export$2cd8ae1985206fe8 = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
    const { __scopeAvatar: __scopeAvatar , src: src , onLoadingStatusChange: onLoadingStatusChange = ()=>{} , ...imageProps } = props;
    const context = $cddcb0b647441e34$var$useAvatarContext($cddcb0b647441e34$var$IMAGE_NAME, __scopeAvatar);
    const imageLoadingStatus = $cddcb0b647441e34$var$useImageLoadingStatus(src);
    const handleLoadingStatusChange = index$2.useCallbackRef((status)=>{
        onLoadingStatusChange(status);
        context.onImageLoadingStatusChange(status);
    });
    index$3.useLayoutEffect(()=>{
        if (imageLoadingStatus !== 'idle') handleLoadingStatusChange(imageLoadingStatus);
    }, [
        imageLoadingStatus,
        handleLoadingStatusChange
    ]);
    return imageLoadingStatus === 'loaded' ? /*#__PURE__*/ React.createElement(index$1.Primitive.img, _extends.default({}, imageProps, {
        ref: forwardedRef,
        src: src
    })) : null;
});
/* -------------------------------------------------------------------------------------------------
 * AvatarFallback
 * -----------------------------------------------------------------------------------------------*/ const $cddcb0b647441e34$var$FALLBACK_NAME = 'AvatarFallback';
const $cddcb0b647441e34$export$69fffb6a9571fbfe = /*#__PURE__*/ React.forwardRef((props, forwardedRef)=>{
    const { __scopeAvatar: __scopeAvatar , delayMs: delayMs , ...fallbackProps } = props;
    const context = $cddcb0b647441e34$var$useAvatarContext($cddcb0b647441e34$var$FALLBACK_NAME, __scopeAvatar);
    const [canRender, setCanRender] = React.useState(delayMs === undefined);
    React.useEffect(()=>{
        if (delayMs !== undefined) {
            const timerId = window.setTimeout(()=>setCanRender(true)
            , delayMs);
            return ()=>window.clearTimeout(timerId)
            ;
        }
    }, [
        delayMs
    ]);
    return canRender && context.imageLoadingStatus !== 'loaded' ? /*#__PURE__*/ React.createElement(index$1.Primitive.span, _extends.default({}, fallbackProps, {
        ref: forwardedRef
    })) : null;
});
/* -----------------------------------------------------------------------------------------------*/ function $cddcb0b647441e34$var$useImageLoadingStatus(src) {
    const [loadingStatus, setLoadingStatus] = React.useState('idle');
    React.useEffect(()=>{
        if (!src) {
            setLoadingStatus('error');
            return;
        }
        let isMounted = true;
        const image = new window.Image();
        const updateStatus = (status)=>()=>{
                if (!isMounted) return;
                setLoadingStatus(status);
            }
        ;
        setLoadingStatus('loading');
        image.onload = updateStatus('loaded');
        image.onerror = updateStatus('error');
        image.src = src;
        return ()=>{
            isMounted = false;
        };
    }, [
        src
    ]);
    return loadingStatus;
}
const $cddcb0b647441e34$export$be92b6f5f03c0fe9 = $cddcb0b647441e34$export$e2255cf6045e8d47;
const $cddcb0b647441e34$export$3e431a229df88919 = $cddcb0b647441e34$export$2cd8ae1985206fe8;
const $cddcb0b647441e34$export$fb8d7f40caaeea67 = $cddcb0b647441e34$export$69fffb6a9571fbfe;

exports.Avatar = $cddcb0b647441e34$export$e2255cf6045e8d47;
exports.AvatarFallback = $cddcb0b647441e34$export$69fffb6a9571fbfe;
exports.AvatarImage = $cddcb0b647441e34$export$2cd8ae1985206fe8;
exports.Fallback = $cddcb0b647441e34$export$fb8d7f40caaeea67;
exports.Image = $cddcb0b647441e34$export$3e431a229df88919;
exports.Root = $cddcb0b647441e34$export$be92b6f5f03c0fe9;
exports.createAvatarScope = $cddcb0b647441e34$export$90370d16b488820f;
//# sourceMappingURL=index.cjs.map
