"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _enums = require("../../enums");
var _styles = require("./styles");
var _PostAdHeader = _interopRequireDefault(require("./PostAdHeader"));
var _hooks = require("../../hooks");
var _xml = require("../../../core/assets/icons/xml");
var _reactNativeSvg = require("react-native-svg");
var _AdInformation = _interopRequireDefault(require("../AdInformation/AdInformation"));
var _bottomSheetSlice = _interopRequireDefault(require("../../../core/stores/slices/bottomSheetSlice"));
var _AdEngine = _interopRequireDefault(require("../../../core/engines/AdEngine"));
var _AssetDownloader = _interopRequireDefault(require("../../../core/engines/AssetDownloader"));
var _store = require("../../../core/stores/store");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const PostAdComponent = ({
  ad,
  pageId = _enums.PageID.WildCardPage
}) => {
  var _ad$image1_, _ad$image1_2;
  const componentId = _enums.ComponentID.post_content;
  const dispatch = (0, _store.useUIKitDispatch)();
  const {
    openBottomSheet
  } = _bottomSheetSlice.default.actions;
  const {
    accessibilityId,
    themeStyles
  } = (0, _hooks.useAmityComponent)({
    pageId: pageId,
    componentId: componentId
  });
  const styles = (0, _styles.useStyles)(themeStyles);
  if (!ad) return null;
  return /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.container,
    testID: accessibilityId
  }, /*#__PURE__*/React.createElement(_reactNative.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.default, {
          pageId: pageId,
          companyName: ad.advertiser.companyName
        }),
        height: 400
      }));
    }
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    xml: (0, _xml.infoIcon)(),
    width: "16",
    height: "16"
  })), /*#__PURE__*/React.createElement(_PostAdHeader.default, {
    advertiser: ad === null || ad === void 0 ? void 0 : ad.advertiser,
    pageId: pageId
  }), ad.body && /*#__PURE__*/React.createElement(_reactNative.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(_reactNative.Image, {
    source: {
      uri: `file://${_AssetDownloader.default.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(_reactNative.View, {
    style: styles.footer
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.footerTextWrap
  }, /*#__PURE__*/React.createElement(_reactNative.Text, {
    numberOfLines: 1,
    style: styles.footerDescription
  }, ad === null || ad === void 0 ? void 0 : ad.description), /*#__PURE__*/React.createElement(_reactNative.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(_reactNative.TouchableOpacity, {
    style: styles.callToActionButton,
    onPress: () => {
      _AdEngine.default.instance.markClicked(ad, 'feed');
      _reactNative.Linking.openURL(ad === null || ad === void 0 ? void 0 : ad.callToActionUrl);
    }
  }, /*#__PURE__*/React.createElement(_reactNative.Text, {
    style: styles.callToActionText
  }, ad.callToAction))));
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(PostAdComponent);
//# sourceMappingURL=PostAdComponent.js.map