import { memo } from 'react';
import { ComponentID, ElementID, PageID } from '../../enums';
import { Image, Pressable, Text, View } from 'react-native';
import { useStyles } from './styles';
import { useAmityComponent } from '../../hooks';
import { star } from '../../../core/assets/icons/xml';
import { SvgXml } from 'react-native-svg';
import AvatarElement from '../../elements/CommonElements/AvatarElement';
import AdInformation from '../AdInformation/AdInformation';
import { infoIcon } from '../../../core/assets/icons/xml';
import { defaultAdAvatarUri } from '../../../core/assets';
import bottomSheetSlice from '../../../core/stores/slices/bottomSheetSlice';
import AssetDownloader from '../../../core/engines/AssetDownloader';
import AdEngine from '../../../core/engines/AdEngine';
import { Linking } from 'react-native';
import { useUIKitDispatch } from '../../../core/stores/store';
const CommentAdComponent = ({
  ad,
  pageId = PageID.WildCardPage
}) => {
  var _ad$advertiser, _ad$advertiser3, _ad$image1_, _ad$image1_2;
  const dispatch = useUIKitDispatch();
  const componentId = ComponentID.WildCardComponent;
  const {
    openBottomSheet
  } = bottomSheetSlice.actions;
  const {
    accessibilityId,
    themeStyles
  } = useAmityComponent({
    pageId: pageId,
    componentId
  });
  const styles = useStyles(themeStyles);
  if (!ad) return null;
  return /*#__PURE__*/React.createElement(View, {
    style: styles.container,
    testID: accessibilityId
  }, /*#__PURE__*/React.createElement(AvatarElement, {
    style: styles.avatar,
    avatarId: ad === null || ad === void 0 || (_ad$advertiser = ad.advertiser) === null || _ad$advertiser === void 0 ? void 0 : _ad$advertiser.avatarFileId,
    pageID: pageId,
    elementID: ElementID.WildCardElement,
    componentID: componentId
    // TODO: change default avatar to be SVG with background color
    ,
    defaultAvatar: defaultAdAvatarUri
  }), /*#__PURE__*/React.createElement(View, {
    style: styles.bubble
  }, /*#__PURE__*/React.createElement(Pressable, {
    style: styles.infoIcon,
    onPress: () => {
      var _ad$advertiser2;
      (ad === null || ad === void 0 || (_ad$advertiser2 = ad.advertiser) === null || _ad$advertiser2 === void 0 ? void 0 : _ad$advertiser2.companyName) && dispatch(openBottomSheet({
        content: /*#__PURE__*/React.createElement(AdInformation, {
          pageId: pageId,
          companyName: ad.advertiser.companyName
        }),
        height: 400
      }));
    }
  }, /*#__PURE__*/React.createElement(SvgXml, {
    xml: infoIcon(),
    width: "16",
    height: "16"
  })), /*#__PURE__*/React.createElement(View, {
    style: styles.header
  }, /*#__PURE__*/React.createElement(Text, {
    numberOfLines: 1,
    style: styles.headerText
  }, ad === null || ad === void 0 || (_ad$advertiser3 = ad.advertiser) === null || _ad$advertiser3 === void 0 ? void 0 : _ad$advertiser3.name), /*#__PURE__*/React.createElement(View, {
    style: styles.adBadge
  }, /*#__PURE__*/React.createElement(SvgXml, {
    style: styles.adBadgeIcon,
    xml: star(),
    width: "12",
    height: "12"
  }), /*#__PURE__*/React.createElement(Text, {
    style: styles.adBadgeContent
  }, "Sponsored"))), ad.body && /*#__PURE__*/React.createElement(Text, {
    style: styles.textContent
  }, ad.body), /*#__PURE__*/React.createElement(Pressable, {
    style: styles.callToActionCard,
    onPress: () => {
      if (!(ad !== null && ad !== void 0 && ad.callToActionUrl)) return;
      AdEngine.instance.markClicked(ad, 'comment');
      Linking.openURL(ad === null || ad === void 0 ? void 0 : ad.callToActionUrl);
    }
  }, (ad === null || ad === void 0 || (_ad$image1_ = ad.image1_1) === null || _ad$image1_ === void 0 ? void 0 : _ad$image1_.fileUrl) && /*#__PURE__*/React.createElement(Image, {
    source: {
      uri: `file://${AssetDownloader.instance.getFilePath((ad === null || ad === void 0 || (_ad$image1_2 = ad.image1_1) === null || _ad$image1_2 === void 0 ? void 0 : _ad$image1_2.fileUrl) + '?size=large')}`
    },
    style: styles.callToActionCardImage,
    resizeMode: "cover"
  }), /*#__PURE__*/React.createElement(View, {
    style: styles.callToActionCardRightSection
  }, /*#__PURE__*/React.createElement(Text, {
    numberOfLines: 1,
    style: styles.callToActionCardDescription
  }, ad === null || ad === void 0 ? void 0 : ad.description), /*#__PURE__*/React.createElement(Text, {
    numberOfLines: 2,
    style: styles.callToActionCardHeadline
  }, ad === null || ad === void 0 ? void 0 : ad.headline), (ad === null || ad === void 0 ? void 0 : ad.callToActionUrl) && /*#__PURE__*/React.createElement(View, {
    style: styles.callToActionButton
  }, /*#__PURE__*/React.createElement(Text, {
    numberOfLines: 1,
    style: styles.callToActionText
  }, ad.callToAction))))));
};
export default /*#__PURE__*/memo(CommentAdComponent);
//# sourceMappingURL=CommentAdComponent.js.map