import { _ as _slicedToArray } from './slicedToArray-ca2c8b8d.js';
import React, { useState, useEffect } from 'react';
import Card from 'react-bootstrap/Card';
import DFPAdSlot from './AdSlot.js';

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 = useState(true),
      _useState2 = _slicedToArray(_useState, 2);
      _useState2[0];
      var setPreviewAd = _useState2[1];

  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.createElement(
    'div',
    { id: 'brand-insight-wrapper-' + (index + 1), className: 'brand-insight-wrapper', style: { display: 'flex', flex: '1 0 auto' } },
    React.createElement(
      Card,
      { className: 'ad-wrapper', style: { display: 'block !important', flexDirection: index === 0 || index % 4 === 0 ? 'top' : 'row' } },
      React.createElement(DFPAdSlot, {
        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.createElement(
      'style',
      { jsx: 'true' },
      '\n        .brand-insight-wrapper div[id*=\'google_ads_iframe\']:empty {\n          height: 0px !important;\n        }\n      '
    )
  );
};

export { ADInfeed as A };
