const { useState: useStateSR } = React;
const ALL_COMPETITORS_ID = '__all_competitors__';
window.SearchRow = function SearchRow({ row, onChange, onRemove, canRemove, competitors }) {
const filters = row.filters || {};
const togglePlatform = (p) => {
const next = { ...row.platforms, [p]: !row.platforms[p] };
onChange({ ...row, platforms: next });
};
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 (
Keyword search
All competitors
{(competitors || []).map(c => (
{c.name}
))}
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 (
live && togglePlatform(key)}
style={on ? { background: p.bg, color: p.color, borderColor: p.bg } : {}}
title={live ? `Toggle ${p.label}` : `${p.label} — backend not wired yet`}
disabled={!live}
>
{p.label}
);
})}
{adspyEnabled && (
Likes
setFilter('minLikes', e.target.value)}
placeholder="0"
/>
Daily
setFilter('minDailyLikes', e.target.value)}
placeholder="0"
/>
setFilter('orderBy', e.target.value)}
title="AdSpy sort order"
>
Sort
Likes
Shares
Oldest
)}
{brandsearchEnabled && (
setFilter('bsPlatform', e.target.value)}
title="BrandSearch ad platform"
>
All BS
Meta
TikTok
Instagram
Views
setFilter('bsMinViews', e.target.value)}
placeholder="0"
/>
Likes
setFilter('bsMinLikes', e.target.value)}
placeholder="0"
/>
ER%
setFilter('bsMinEngagement', e.target.value)}
placeholder="0"
/>
setFilter('bsSort', e.target.value)}
title="BrandSearch sort order"
>
Sort
Views
Likes
ER%
Reach
Spend
)}
{(foreplayEnabled || brandsearchEnabled) && (
{foreplayEnabled && (
setFilter('foreplayUrl', e.target.value)}
placeholder="Foreplay ad URL"
title="Fetch only this Foreplay ad"
/>
)}
{brandsearchEnabled && (
setFilter('brandsearchUrl', e.target.value)}
placeholder="BrandSearch ad URL"
title="Fetch only this BrandSearch ad"
/>
)}
)}
);
};