'use strict';

var React = require('react');
var Card = require('react-bootstrap/Card');
var slicedToArray = require('./slicedToArray-f6d4eaa8.js');
var AdSlot = require('./AdSlot.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var Card__default = /*#__PURE__*/_interopDefaultLegacy(Card);

var ADInfeed = function ADInfeed(_ref) {
  var index = _ref.index,
      infeedAd = _ref.infeedAd,
      _ref$refreshFlag = _ref.refreshFlag,
      refreshFlag = _ref$refreshFlag === undefined ? false : _ref$refreshFlag;
  var className = infeedAd.className,
      slotId = infeedAd.slotId,
      adUnit = infeedAd.adUnit,
      _infeedAd$targeting = infeedAd.targeting,
      targeting = _infeedAd$targeting === undefined ? {} : _infeedAd$targeting,
      networkID = infeedAd.networkID,
      sizes = infeedAd.sizes;

  var _useState = React.useState(true),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      previewAd = _useState2[0],
      setPreviewAd = _useState2[1];

  React.useEffect(function () {
    var path = window && window.location && window.location.search;
    // Setting flag for Ad-preview URLs
    setPreviewAd(path.split('&').some(function (param) {
      return param.includes('creativeId');
    }));
  }, []);

  return React__default['default'].createElement(
    'div',
    { id: 'brand-insight-wrapper-' + (index + 1), className: 'brand-insight-wrapper', style: { display: 'flex', flex: '1 0 auto' } },
    React__default['default'].createElement(
      Card__default['default'],
      { className: 'ad-wrapper', style: { display: 'block !important', flexDirection: index === 0 || index % 4 === 0 ? 'top' : 'row' } },
      React__default['default'].createElement(AdSlot, {
        className: className,
        networkID: networkID,
        adUnit: adUnit,
        slotId: slotId,
        targeting: targeting,
        sizes: sizes
        /* Passing function to check for ad creative only if it is not in preview. */
        // checkIsAdFound={previewAd ? null : checkIsAdFound}
        /* Passing refresh flag */
        , refreshFlag: refreshFlag
      })
    ),
    React__default['default'].createElement(
      'style',
      { jsx: 'true' },
      '\n        .brand-insight-wrapper div[id*=\'google_ads_iframe\']:empty {\n          height: 0px !important;\n        }\n      '
    )
  );
};

exports.ADInfeed = ADInfeed;
