import {
useState
} from "react";
import {
TouchableOpacity,
Image,
View
} from "react-native";
import type ISiteLogoProps from "./type";
import stylesheet, {
getSiteLogoSize,
useStyles
} from "./stylesheet";
import {
NCoreUIKitLocalize,
NCoreUIKitTheme
} from "../../core/hooks";
import {
Home as HomeIcon
} from "lucide-react-native";
import Loading from "../loading";
import Text from "../text";
const SiteLogo = ({
logoBackgroundColor = "default",
isWorkWithFlex1 = true,
isShowBorder = false,
subTitleCustomColor,
isCustomImageSize,
isShowIcon = true,
isWorkWithAction,
titleCustomColor,
image: ImageProp,
backgroundColor,
subTitleVariant,
customLocalize,
icon: IconProp,
size = "large",
subTitleStyle,
subTitleColor,
titleVariant,
imageSource,
customTheme,
borderColor,
titleStyle,
imageSpace,
isDisabled,
titleColor,
imageProps,
isLoading,
iconColor,
titleKey,
imageUrl,
subTitle,
onPress,
title,
style
}: ISiteLogoProps) => {
const {
borders,
colors,
spaces
} = NCoreUIKitTheme.useContext(customTheme);
const {
localize
} = NCoreUIKitLocalize.useContext(customLocalize);
const currentSize = getSiteLogoSize({
spaces,
size
});
const [
imageLoadError,
setImageLoadError
] = useState(false);
const {
contentContainer: contentContainerDynamicStyle,
titlesContainer: titlesContainerDynamicStyle,
container: containerDynamicStyle,
image: imageDynamicStyle,
icon: iconDynamicStyle
} = useStyles({
logoBackgroundColor,
isCustomImageSize,
image: ImageProp,
isWorkWithFlex1,
backgroundColor,
isShowBorder,
borderColor,
currentSize,
isDisabled,
imageSpace,
isLoading,
imageUrl,
borders,
colors,
spaces
});
const renderIcon = () => {
if(IconProp) {
return ;
}
return ;
};
const renderLoading = () => {
let loadingColor: keyof NCoreUIKit.IconContentColors = "default";
if(title) {
loadingColor = "onPrimary";
} else if(imageUrl || ImageProp) {
loadingColor = "mid";
}
return ;
};
const renderContent = () => {
if(isLoading) {
return renderLoading();
}
if(IconProp) {
return renderIcon();
}
if(!ImageProp && !imageUrl) {
return renderIcon();
}
if((imageUrl || ImageProp) && imageLoadError) {
return renderIcon();
}
if(ImageProp) {
return setImageLoadError(true)}
height={currentSize.size}
width={currentSize.size}
style={[
stylesheet.image,
imageDynamicStyle,
imageProps?.style
]}
/>;
}
if(imageUrl) {
return setImageLoadError(true)}
height={currentSize.size}
width={currentSize.size}
source={{
uri: imageUrl,
...imageSource
}}
style={[
stylesheet.image,
imageDynamicStyle,
imageProps?.style
]}
/>;
}
return null;
};
const renderTitles = () => {
if(!title) {
return null;
}
return
{titleKey ? localize(titleKey) : title}
{
subTitle ?
{subTitle}
:
null
}
;
};
const renderContentContainer = () => {
if(!isShowIcon) {
return null;
}
return
{renderContent()}
;
};
return {
if(onPress) onPress();
}}
style={[
style,
stylesheet.container,
containerDynamicStyle
]}
>
{renderContentContainer()}
{renderTitles()}
;
};
export default SiteLogo;