<commit_before>/* @flow strict-local */
import template from './template';
import type { Message, Narrow, Outbox } from '../../types';
import type { BackgroundData } from '../MessageList';
import {
  streamNarrow,
  topicNarrow,
  privateNarrow,
  groupNarrow,
  caseNarrow,
} from '../../utils/narrow';
import { foregroundColorFromBackground } from '../../utils/color';

const renderSubject = item =>
  // TODO: pin down if '' happens, and what its proper semantics are.
  item.match_subject !== undefined && item.match_subject !== ''
    ? item.match_subject
    : template`${item.subject}`;

export default (
  { ownEmail, subscriptions }: BackgroundData,
  narrow: Narrow,
  item: Message | Outbox | {||},
) => {
  const headerStyle = caseNarrow(narrow, {
    home: () => 'full',
    pm: () => null,
    groupPm: () => null,
    starred: () => 'full',
    mentioned: () => 'full',
    allPrivate: () => 'full',
    stream: () => 'topic+date',
    topic: () => null,
    search: () => 'full',
  });

  if (!item.type) {
    return '';
  }

  if (item.type === 'stream' && headerStyle === 'topic+date') {
    const topicNarrowStr = JSON.stringify(topicNarrow(item.display_recipient, item.subject));
    const topicHtml = renderSubject(item);

    return template`
<div<commit_msg>msglist header: Refactor which-header-style logic slightly further.<commit_after>/* @flow strict-local */
import template from './template';
import type { Message, Narrow, Outbox } from '../../types';
import type { BackgroundData } from '../MessageList';
import {
  streamNarrow,
  topicNarrow,
  privateNarrow,
  groupNarrow,
  caseNarrow,
} from '../../utils/narrow';
import { foregroundColorFromBackground } from '../../utils/color';

const renderSubject = item =>
  // TODO: pin down if '' happens, and what its proper semantics are.
  item.match_subject !== undefined && item.match_subject !== ''
    ? item.match_subject
    : template`${item.subject}`;

export default (
  { ownEmail, subscriptions }: BackgroundData,
  narrow: Narrow,
  item: Message | Outbox | {||},
) => {
  type HeaderStyle = 'none' | 'topic+date' | 'full';
  const headerStyle: HeaderStyle = caseNarrow(narrow, {
    stream: () => 'topic+date',
    topic: () => 'none',

    pm: () => 'none',
    groupPm: () => 'none',

    home: () => 'full',
    starred: () => 'full',
    mentioned: () => 'full',
    allPrivate: () => 'full',
    search: () => 'full',
  });

  if (!item.type) {
    return '';
  }

  if (item.type === 'stream' && headerStyle === 'topic+date') {
    const topicNarrowStr = JSON.stringify(topicNarrow(item.display_recipient, item.subject));
    const topicHtml = renderSubject(item);

    return template`
<div
{'fraction_non_alphanumeric': 0.18053491827637444, 'fraction_numerical': 0.0, 'mean_word_length': 3.4512396694214877, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1997129', 'n_tokens_mistral': 841, 'n_tokens_neox': 835, 'n_words': 209}