"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _enums = require("../../enums");
var _reactNative = require("react-native");
var _styles = require("./styles");
var _hooks = require("../../hooks");
var _xml = require("../../../core/assets/icons/xml");
var _reactNativeSvg = require("react-native-svg");
var _AvatarElement = _interopRequireDefault(require("../../elements/CommonElements/AvatarElement"));
var _AdInformation = _interopRequireDefault(require("../AdInformation/AdInformation"));
var _assets = require("../../../core/assets");
var _bottomSheetSlice = _interopRequireDefault(require("../../../core/stores/slices/bottomSheetSlice"));
var _AssetDownloader = _interopRequireDefault(require("../../../core/engines/AssetDownloader"));
var _AdEngine = _interopRequireDefault(require("../../../core/engines/AdEngine"));
var _store = require("../../../core/stores/store");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const CommentAdComponent = ({
  ad,
  pageId = _enums.PageID.WildCardPage
}) => {
  var _ad$advertiser, _ad$advertiser3, _ad$image1_, _ad$image1_2;
  const dispatch = (0, _store.useUIKitDispatch)();
  const componentId = _enums.ComponentID.WildCardComponent;
  const {
    openBottomSheet
  } = _bottomSheetSlice.default.actions;
  const {
    accessibilityId,
    themeStyles
  } = (0, _hooks.useAmityComponent)({
    pageId: pageId,
    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(_AvatarElement.default, {
    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: _enums.ElementID.WildCardElement,
    componentID: componentId
    // TODO: change default avatar to be SVG with background color
    ,
    defaultAvatar: _assets.defaultAdAvatarUri
  }), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.bubble
  }, /*#__PURE__*/React.createElement(_reactNative.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.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(_reactNative.View, {
    style: styles.header
  }, /*#__PURE__*/React.createElement(_reactNative.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(_reactNative.View, {
    style: styles.adBadge
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    style: styles.adBadgeIcon,
    xml: (0, _xml.star)(),
    width: "12",
    height: "12"
  }), /*#__PURE__*/React.createElement(_reactNative.Text, {
    style: styles.adBadgeContent
  }, "Sponsored"))), ad.body && /*#__PURE__*/React.createElement(_reactNative.Text, {
    style: styles.textContent
  }, ad.body), /*#__PURE__*/React.createElement(_reactNative.Pressable, {
    style: styles.callToActionCard,
    onPress: () => {
      if (!(ad !== null && ad !== void 0 && ad.callToActionUrl)) return;
      _AdEngine.default.instance.markClicked(ad, 'comment');
      _reactNative.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(_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.callToActionCardImage,
    resizeMode: "cover"
  }), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.callToActionCardRightSection
  }, /*#__PURE__*/React.createElement(_reactNative.Text, {
    numberOfLines: 1,
    style: styles.callToActionCardDescription
  }, ad === null || ad === void 0 ? void 0 : ad.description), /*#__PURE__*/React.createElement(_reactNative.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(_reactNative.View, {
    style: styles.callToActionButton
  }, /*#__PURE__*/React.createElement(_reactNative.Text, {
    numberOfLines: 1,
    style: styles.callToActionText
  }, ad.callToAction))))));
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(CommentAdComponent);
//# sourceMappingURL=CommentAdComponent.js.map