import { memo, useEffect, useState } from 'react';
import { Image, StyleSheet, View } from 'react-native';
import { useAmityElement, useFile } from '../../hooks';
import { PageID, ComponentID, ElementID } from '../../enums';
import { SvgXml } from 'react-native-svg';
import { category as categoryIcon } from '../../../core/assets/icons';
const CategoryRowImage = ({
  avatarFileId,
  pageId = PageID.WildCardPage,
  componentId = ComponentID.WildCardComponent
}) => {
  const elementId = ElementID.category_row_image;
  const {
    getImage
  } = useFile();
  const {
    themeStyles,
    isExcluded
  } = useAmityElement({
    pageId,
    componentId,
    elementId
  });
  const [imageUri, setImageUri] = useState(null);
  const styles = StyleSheet.create({
    contianer: {
      color: themeStyles === null || themeStyles === void 0 ? void 0 : themeStyles.colors.base,
      height: 40,
      width: 40,
      borderRadius: 40
    },
    placeholder: {
      width: '100%',
      height: '100%',
      borderRadius: 40,
      justifyContent: 'center',
      alignItems: 'center',
      // TODO: fix color
      backgroundColor: themeStyles.colors.primaryShade2
    },
    image: {
      overflow: 'hidden',
      width: '100%',
      height: '100%'
    }
  });
  useEffect(() => {
    if (!avatarFileId) return;
    const fetchImage = async () => {
      const image = await getImage({
        fileId: avatarFileId
      });
      if (image) {
        setImageUri(image);
      }
    };
    fetchImage();
  }, [avatarFileId, getImage]);
  if (isExcluded) return null;
  return /*#__PURE__*/React.createElement(View, {
    style: styles.contianer
  }, avatarFileId && imageUri ? /*#__PURE__*/React.createElement(Image, {
    source: {
      uri: imageUri
    },
    style: styles.image,
    resizeMode: "cover"
  }) : /*#__PURE__*/React.createElement(View, {
    style: styles.placeholder
  }, /*#__PURE__*/React.createElement(SvgXml, {
    xml: categoryIcon(),
    color: themeStyles === null || themeStyles === void 0 ? void 0 : themeStyles.colors.primaryShade2
  })));
};
export default /*#__PURE__*/memo(CategoryRowImage);
//# sourceMappingURL=CategoryRowImage.js.map