import { memo } from 'react';
import { Image, View, TouchableOpacity, Linking, Text } from 'react-native';
import { ComponentID, PageID } from '../../enums';
import { useStyles } from './styles';
import PostAdHeader from './PostAdHeader';
import { useAmityComponent } from '../../hooks';
import { infoIcon } from '../../../core/assets/icons/xml';
import { SvgXml } from 'react-native-svg';
import AdInformation from '../AdInformation/AdInformation';
import bottomSheetSlice from '../../../core/stores/slices/bottomSheetSlice';
import AdEngine from '../../../core/engines/AdEngine';
import AssetDownloader from '../../../core/engines/AssetDownloader';
import { useUIKitDispatch } from '../../../core/stores/store';
const PostAdComponent = ({
  ad,
  pageId = PageID.WildCardPage
}) => {
  var _ad$image1_, _ad$image1_2;
  const componentId = ComponentID.post_content;
  const dispatch = useUIKitDispatch();
  const {
    openBottomSheet
  } = bottomSheetSlice.actions;
  const {
    accessibilityId,
    themeStyles
  } = useAmityComponent({
    pageId: pageId,
    componentId: componentId
  });
  const styles = useStyles(themeStyles);
  if (!ad) return null;
  return /*#__PURE__*/React.createElement(View, {
    style: styles.container,
    testID: accessibilityId
  }, /*#__PURE__*/React.createElement(TouchableOpacity, {
    style: styles.infoIcon,
    onPress: () => {
      var _ad$advertiser;
      (ad === null || ad === void 0 || (_ad$advertiser = ad.advertiser) === null || _ad$advertiser === void 0 ? void 0 : _ad$advertiser.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(PostAdHeader, {
    advertiser: ad === null || ad === void 0 ? void 0 : ad.advertiser,
    pageId: pageId
  }), ad.body && /*#__PURE__*/React.createElement(Text, {
    style: styles.textContent
  }, ad.body), (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.image,
    resizeMode: "cover"
  }), /*#__PURE__*/React.createElement(View, {
    style: styles.footer
  }, /*#__PURE__*/React.createElement(View, {
    style: styles.footerTextWrap
  }, /*#__PURE__*/React.createElement(Text, {
    numberOfLines: 1,
    style: styles.footerDescription
  }, ad === null || ad === void 0 ? void 0 : ad.description), /*#__PURE__*/React.createElement(Text, {
    numberOfLines: 2,
    style: styles.footerHeadline
  }, ad === null || ad === void 0 ? void 0 : ad.headline)), (ad === null || ad === void 0 ? void 0 : ad.callToActionUrl) && /*#__PURE__*/React.createElement(TouchableOpacity, {
    style: styles.callToActionButton,
    onPress: () => {
      AdEngine.instance.markClicked(ad, 'feed');
      Linking.openURL(ad === null || ad === void 0 ? void 0 : ad.callToActionUrl);
    }
  }, /*#__PURE__*/React.createElement(Text, {
    style: styles.callToActionText
  }, ad.callToAction))));
};
export default /*#__PURE__*/memo(PostAdComponent);
//# sourceMappingURL=PostAdComponent.js.map