/* @flow strict-local */
import { connect } from 'react-redux';

import React, { PureComponent } from 'react';

import { caseNarrow } from '../utils/narrow';
import { getSession } from '../selectors';

import type { Message, GlobalState, Narrow } from '../types';
import TitlePrivate from './TitlePrivate';
import TitleGroup from './TitleGroup';
import TitleSpecial from './TitleSpecial';
import TitleStream from './TitleStream';
import TitlePlain from './TitlePlain';

type Props = {|
  narrow: Narrow,
  editMessage: Message,
  color: string,
|};

class Title extends PureComponent<Props> {
  render() {
    const { narrow, color, editMessage } = this.props;
    const props = { color };
    if (editMessage != null) {
      return <TitlePlain text="Edit message" {...props} />;
    }
    return caseNarrow(narrow, {
      home: () => <TitleSpecial code="home" color={color} />,
      starred: () => <TitleSpecial code="starred" {...props} />,
      mentioned: () => <TitleSpecial code="mentioned" {...props} />,
      allPrivate: () => <TitleSpecial code="private" {...props} />,
      stream: () => <TitleStream narrow={narrow} {...props} />,
      topic: () => <TitleStream narrow={narrow} {...props} />,
      pm: email => <TitlePrivate email={email} {...props} />,
      groupPm: () => <TitleGroup narrow={narrow} {...props} />,
      search: () => null,
    });
  }
}

export default connect((state: GlobalState) => ({
  editMessage: getSession(state).editMessage,
}))(Title);

@@ -658,37 +658,8 @@
 ps;%0A
-    const props = %7B color %7D;%0A
     
@@ -730,25 +730,28 @@
 essage%22 
-%7B...props
+color=%7Bcolor
 %7D /%3E;%0A  
@@ -894,33 +894,36 @@
 e=%22starred%22 
-%7B...props
+color=%7Bcolor
 %7D /%3E,%0A      
@@ -970,25 +970,28 @@
 tioned%22 
-%7B...props
+color=%7Bcolor
 %7D /%3E,%0A  
@@ -1041,25 +1041,28 @@
 rivate%22 
-%7B...props
+color=%7Bcolor
 %7D /%3E,%0A  
@@ -1104,33 +1104,36 @@
 ow=%7Bnarrow%7D 
-%7B...props
+color=%7Bcolor
 %7D /%3E,%0A      
@@ -1170,33 +1170,36 @@
 ow=%7Bnarrow%7D 
-%7B...props
+color=%7Bcolor
 %7D /%3E,%0A      
@@ -1239,25 +1239,28 @@
 %7Bemail%7D 
-%7B...props
+color=%7Bcolor
 %7D /%3E,%0A  
@@ -1310,17 +1310,20 @@
 ow%7D 
-%7B...props
+color=%7Bcolor
 %7D /%3E

Simplify out single-prop `...props` in Title.