1import React, { useEffect } from 'react';
2import ColorTintFilter, { getTintColorStyle } from './ColorTintFilter';
3import { getImageWrapperEventHandler } from './getImageWrapperEventHandler';
4import { useHeaders, useImageHashes } from './hooks';
5import { absoluteFilledPosition, getObjectPositionFromContentPositionObject } from './positioning';
6function getFetchPriorityFromImagePriority(priority = 'normal') {
7    return priority && ['low', 'high'].includes(priority) ? priority : 'auto';
8}
9function getImgPropsFromSource(source) {
10    if (source && 'srcset' in source) {
11        return {
12            srcSet: source.srcset,
13            sizes: source.sizes,
14        };
15    }
16    return {};
17}
18const ImageWrapper = React.forwardRef(({ source, events, contentPosition, hashPlaceholderContentPosition, priority, style, hashPlaceholderStyle, tintColor, className, accessibilityLabel, cachePolicy, ...props }, ref) => {
19    useEffect(() => {
20        events?.onMount?.forEach((e) => e?.());
21    }, []);
22    // Thumbhash uri always has to start with 'thumbhash:/'
23    const { resolvedSource, isImageHash } = useImageHashes(source);
24    const objectPosition = getObjectPositionFromContentPositionObject(isImageHash ? hashPlaceholderContentPosition : contentPosition);
25    const sourceWithHeaders = useHeaders(resolvedSource, cachePolicy, events?.onError);
26    if (!sourceWithHeaders) {
27        return null;
28    }
29    return (React.createElement(React.Fragment, null,
30        React.createElement(ColorTintFilter, { tintColor: tintColor }),
31        React.createElement("img", { ref: ref, alt: accessibilityLabel, className: className, src: sourceWithHeaders?.uri || undefined, key: source?.uri, style: {
32                objectPosition,
33                ...absoluteFilledPosition,
34                ...getTintColorStyle(tintColor),
35                ...(isImageHash ? hashPlaceholderStyle : {}),
36                ...style,
37            },
38            // @ts-ignore
39            // eslint-disable-next-line react/no-unknown-property
40            fetchpriority: getFetchPriorityFromImagePriority(priority || 'normal'), ...getImageWrapperEventHandler(events, sourceWithHeaders), ...getImgPropsFromSource(source), ...props })));
41});
42export default ImageWrapper;
43//# sourceMappingURL=ImageWrapper.js.map