<commit_before>// @flow

import React from 'react';
import PropTypes from 'prop-types';
import { red500, grey50 } from 'material-ui/styles/colors';

import Paper from 'material-ui/Paper';
import { Tabs, Tab } from 'material-ui/Tabs';
import { List } from 'material-ui/List';
import Subheader from 'material-ui/Subheader';
import SwipeableViews from 'react-swipeable-views';

import CastListItem from './CastListItem';

class CastList extends React.Component {

    static propTypes = {
        show: PropTypes.object,
        missingMainCastName: PropTypes.string,
    };

    state = {
        slideIndex: 0,
    };

    defaultProps = {
        missingMainCastName: 'Unbekannt',
    };

    componentWillReceiveProps(nextProps) {
        /* Select the first tab if the date has changed. */
        if (!this.props.show || !nextProps.show || this.props.show.day !== nextProps.show.day) {
            this.setState({ slideIndex: 0 });
        }
    };

    handleChange = value => {
        this.setState({ slideIndex: value });
    };

    renderDivider(title) {
        const key = `divider-${title}`;
        return (
            <Subheader
                key={key}
            >
                {title}
            </Subheader>
        );
    }

    getItemKey(role, person) {
        /* The same person can appear in more than one role, so mix both keys. */
        return role + person.name;
    };

    renderMainCastItemsForRole(role) {
        const { show, missingMainCastName } = this.props;
        const persons = (show.cast[role] && show.cast[role].length !== 0) ? show.cast[role] : [{
            id: 0,
            name: missingMainCastName,
        }];

        return persons.map(person => {
            return (
                <CastListItem
                    key={this.getItemKey(role, person)}
                    role={role}
                    displayRole={true}
                    person={person}
                />
            );
        });
    };

    renderMainCastList() {
        const { show } = this.props;
        if (!show) {
            return (
                <div />
            );
        }

        return [
            this.renderDivider('Hauptrollen'),
            ...this.renderMainCastItemsForRole('<NAME>'),
            ...this.renderMainCastItemsForRole('Alfred'),
            ...this.renderMainCastItemsForRole('Professor Abronsius'),
            ...this.renderMainCastItemsForRole('Sarah'),
            ...this.renderMainCastItemsForRole('Chagal'),
            ...this.renderMainCastItemsForRole('Magda'),
            ...this.renderMainCastItemsForRole('Rebecca'),
            ...this.renderMainCastItemsForRole('Herbert'),
            ...this.renderMainCastItemsForRole('Koukol'),

            this.renderDivider('Dirigent'),
            ...this.renderMainCastItemsForRole('Dirigent'),
        ];
    };

    renderEnsembleGroup(label, key) {
        const { show } = this.props;
        if (!show.cast[key] || show.cast[key].length === 0) {
            return [];
        }

        const divider = this.renderDivider(label);
        return [divider].concat(
            show.cast[key].map(person => {
                return (
                    <CastListItem
                        key={this.getItemKey(key, person)}
                        role={key}
                        displayRole={false}
                        person={person}
                    />
                );
            })
        );
    };

    renderEnsembleList() {
        const { show } = this.props;
        if (!show) {
            return (
                <div />
            );
        }

        return [
            ...this.renderEnsembleGroup('Tanzsolisten', 'Solotänzer'),
            ...this.renderEnsembleGroup('Tanzsolisten', 'Tanzsolisten'),
            ...this.renderEnsembleGroup('Gesangssolisten', 'Gesangssolisten'),
            ...this.renderEnsembleGroup('Tanzensemble', 'Tanzensemble'),
            ...this.renderEnsembleGroup('Gesangsensemble', 'Gesangsensemble'),
        ];
    };

    render() {
        const { show } = this.props;
        if (!show) {<commit_msg>Render a message if the Ensemble tab is empty.<commit_after>// @flow

import React from 'react';
import PropTypes from 'prop-types';
import { red500, grey50 } from 'material-ui/styles/colors';

import Paper from 'material-ui/Paper';
import { Tabs, Tab } from 'material-ui/Tabs';
import { List } from 'material-ui/List';
import Subheader from 'material-ui/Subheader';
import SwipeableViews from 'react-swipeable-views';

import CastListItem from './CastListItem';

class CastList extends React.Component {

    static propTypes = {
        show: PropTypes.object,
        missingMainCastName: PropTypes.string,
    };

    state = {
        slideIndex: 0,
    };

    defaultProps = {
        missingMainCastName: 'Unbekannt',
    };

    componentWillReceiveProps(nextProps) {
        /* Select the first tab if the date has changed. */
        if (!this.props.show || !nextProps.show || this.props.show.day !== nextProps.show.day) {
            this.setState({ slideIndex: 0 });
        }
    };

    handleChange = value => {
        this.setState({ slideIndex: value });
    };

    renderDivider(title) {
        const key = `divider-${title}`;
        return (
            <Subheader
                key={key}
            >
                {title}
            </Subheader>
        );
    }

    getItemKey(role, person) {
        /* The same person can appear in more than one role, so mix both keys. */
        return role + person.name;
    };

    renderMainCastItemsForRole(role) {
        const { show, missingMainCastName } = this.props;
        const persons = (show.cast[role] && show.cast[role].length !== 0) ? show.cast[role] : [{
            id: 0,
            name: missingMainCastName,
        }];

        return persons.map(person => {
            return (
                <CastListItem
                    key={this.getItemKey(role, person)}
                    role={role}
                    displayRole={true}
                    person={person}
                />
            );
        });
    };

    renderMainCastList() {
        const { show } = this.props;
        if (!show) {
            return (
                <div />
            );
        }

        return [
            this.renderDivider('Hauptrollen'),
            ...this.renderMainCastItemsForRole('<NAME>'),
            ...this.renderMainCastItemsForRole('Alfred'),
            ...this.renderMainCastItemsForRole('Professor Abronsius'),
            ...this.renderMainCastItemsForRole('Sarah'),
            ...this.renderMainCastItemsForRole('Chagal'),
            ...this.renderMainCastItemsForRole('Magda'),
            ...this.renderMainCastItemsForRole('Rebecca'),
            ...this.renderMainCastItemsForRole('Herbert'),
            ...this.renderMainCastItemsForRole('Koukol'),

            this.renderDivider('Dirigent'),
            ...this.renderMainCastItemsForRole('Dirigent'),
        ];
    };

    renderEnsembleGroup(label, key) {
        const { show } = this.props;
        if (!show.cast[key] || show.cast[key].length === 0) {
            return [];
        }

        const divider = this.renderDivider(label);
        return [divider].concat(
            show.cast[key].map(person => {
                return (
                    <CastListItem
                        key={this.getItemKey(key, person)}
                        role={key}
                        displayRole={false}
                        person={person}
                    />
                );
            })
        );
    };

    renderEnsembleList() {
        const { show } = this.props;
        if (!show) {
            return (
                <div />
            );
        }

        const ensemble = [
            ...this.renderEnsembleGroup('Tanzsolisten', 'Solotänzer'),
            ...this.renderEnsembleGroup('Tanzsolisten', 'Tanzsolisten'),
            ...this.renderEnsembleGroup('Gesangssolisten', 'Gesangssolisten'),
            ...this.renderEnsembleGroup('Tanzensemble', 'Tanzensemble'),
            ...this.renderEnsembleGroup('Gesangsensemble', 'Gesangsensemble'),
        ];

        if (ensemble.length === 0) {
            return (
                <div style={{ textAlign: 'center' }}>
                    <p>Für das Ensemble liegen keine Informationen vor.</p>
                </div>
            );
        }

        return ensemble;
    };

    render() {
        const { show } = this.props;
        if (!show) {
{'fraction_non_alphanumeric': 0.1307044231219284, 'fraction_numerical': 0.0024572899602153054, 'mean_word_length': 1.6185661764705883, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, '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': '5385818', 'n_tokens_mistral': 2400, 'n_tokens_neox': 2308, 'n_words': 429}