const { useState: useStateSR } = React;
const ALL_COMPETITORS_ID = '__all_competitors__';
window.SearchRow = function SearchRow({ row, onChange, onRemove, onSearch, searching, canRemove, competitors }) {
const filters = row.filters || {};
const togglePlatform = (p) => {
const next = {
foreplay: !!row.platforms?.foreplay,
adspy: !!row.platforms?.adspy,
brandsearch: !!row.platforms?.brandsearch,
metaads: false,
};
next[p] = !next[p];
onChange({ ...row, platforms: next });
};
const selectAllPlatforms = () => onChange({
...row,
platforms: { foreplay: true, adspy: true, brandsearch: true, metaads: false },
});
const setFilter = (key, value) => {
onChange({ ...row, filters: { ...filters, [key]: value } });
};
const onCompetitor = (e) => {
const competitorId = e.target.value || null;
onChange({ ...row, competitorId });
};
const allCompetitorsSet = row.competitorId === ALL_COMPETITORS_ID;
const competitorSet = !!row.competitorId;
const foreplayEnabled = !!row.platforms?.foreplay;
const adspyEnabled = !!row.platforms?.adspy;
const brandsearchEnabled = !!row.platforms?.brandsearch;
return (
onChange({ ...row, query: e.target.value })}
placeholder={allCompetitorsSet ? 'Optional keyword across competitor ads' : competitorSet ? 'Optional keyword within competitor' : 'Brand or keyword (e.g. mushroom coffee)'}
/>
onChange({ ...row, count: +e.target.value })}
/>
{Object.entries(PLATFORMS).map(([key, p]) => {
const on = row.platforms[key];
const live = key === 'foreplay' || key === 'adspy' || key === 'brandsearch';
return (
);
})}
{foreplayEnabled && (
)}
{adspyEnabled && (
)}
{brandsearchEnabled && (
)}
{(foreplayEnabled || adspyEnabled || brandsearchEnabled) && (
{foreplayEnabled && (
setFilter('foreplayUrl', e.target.value)}
placeholder="Foreplay ad URL"
title="Fetch only this Foreplay ad"
/>
)}
{adspyEnabled && (
<>
setFilter('adspyUrl', e.target.value)}
placeholder="AdSpy ad URL substring"
title="Search AdSpy ads containing this URL string"
/>
setFilter('adspyLandingUrl', e.target.value)}
placeholder="AdSpy landing-page URL substring"
title="Search AdSpy landing pages containing this URL string"
/>
>
)}
{brandsearchEnabled && (
setFilter('brandsearchUrl', e.target.value)}
placeholder="BrandSearch ad URL"
title="Fetch only this BrandSearch ad"
/>
)}
)}
);
};