export function filterOverlays(records, filter = 'all') {
  if (filter === 'affected') return records.filter(({ seg }) => !seg.ignorePostFx);
  if (filter === 'ignored') return records.filter(({ seg }) => Boolean(seg.ignorePostFx));
  return records;
}

export function overlaysNeedBase(records) {
  return records.some(({ seg }) => seg.blendMode && seg.blendMode !== 'source-over');
}

export function splitPostFxOverlays(records) {
  return {
    affected: filterOverlays(records, 'affected'),
    ignored: filterOverlays(records, 'ignored'),
  };
}

export function overlayPassHasContent(mediaRecords, textRecords, filter) {
  return filterOverlays(mediaRecords, filter).length > 0 || filterOverlays(textRecords, filter).length > 0;
}

export function renderOverlayPass(time, filter, renderImages, renderText, baseImage = null) {
  const imageResult = renderImages(time, filter, baseImage);
  const textRendered = renderText(time, filter, imageResult);
  return { imageResult, textRendered };
}
