/* @flow */
import { createSelector } from 'reselect';

import type { Narrow } from '../types';
import { BRAND_COLOR } from '../styles';
import { getSubscriptions } from '../directSelectors';
import { getCurrentRouteName } from '../nav/navSelectors';
import { foregroundColorFromBackground } from '../utils/color';
import { isStreamNarrow, isTopicNarrow, isStreamOrTopicNarrow } from '../utils/narrow';
import { NULL_SUBSCRIPTION } from '../nullObjects';

export const getIsInTopicOrStreamNarrow = (narrow?: Narrow) =>
  createSelector(
    getCurrentRouteName,
    routeName => (routeName === 'chat' ? isStreamNarrow(narrow) || isTopicNarrow(narrow) : false),
  );

/** (If `narrow` omitted, returns 'transparent'.) */
export const getTitleBackgroundColor = (narrow?: Narrow) =>
  createSelector(
    getSubscriptions,
    subscriptions =>
      isStreamOrTopicNarrow(narrow)
        ? (
            subscriptions.find(sub => Array.isArray(narrow) && narrow[0].operand === sub.name)
            || NULL_SUBSCRIPTION
          ).color
        : 'transparent',
  );

/** (If `narrow` omitted, returns BRAND_COLOR.) */
export const getTitleTextColor = (narrow?: Narrow) =>
  createSelector(
    getTitleBackgroundColor(narrow),
    backgroundColor =>
      backgroundColor && isStreamOrTopicNarrow(narrow)
        ? foregroundColorFromBackground(backgroundColor)
        : BRAND_COLOR,
  );

@@ -189,67 +189,8 @@
 s';%0A
-import %7B getCurrentRouteName %7D from '../nav/navSelectors';%0A
 impo
@@ -261,39 +261,8 @@
 rt %7B
- isStreamNarrow, isTopicNarrow,
  isS
@@ -363,219 +363,8 @@
 ';%0A%0A
-export const getIsInTopicOrStreamNarrow = (narrow?: Narrow) =%3E%0A  createSelector(%0A    getCurrentRouteName,%0A    routeName =%3E (routeName === 'chat' ? isStreamNarrow(narrow) %7C%7C isTopicNarrow(narrow) : false),%0A  );%0A%0A
 /** 

Remove now-unused `getIsInTopicOrStreamNarrow` selector.