<commit_before>/* eslint-disable import/no-unresolved */
import React, { Component } from 'react';

import PropTypes from 'prop-types';

import { StyleSheet, Text, View } from 'react-native';

import Separator from './Separator';

class Section extends Component {
  constructor(props) {
    super(props);
    this.state = {
      highlightedRowIndex: undefined,
    };

    this.handleHighlightRow = index =>
      !this.state.highlightedRowIndex &&
      this.setState({ highlightedRowIndex: index });
    this.handleUnHighlightRow = () =>
      this.setState({ highlightedRowIndex: undefined });
  }
  render() {
    const {
      allowFontScaling,
      children,
      footerComponent,
      headerComponent,
      headerTextColor,
      hideSeparator,
      footerTextColor,
      sectionPaddingBottom,
      sectionPaddingTop,
      sectionTintColor,
      separatorInsetLeft,
      separatorInsetRight,
      separatorTintColor,
    } = this.props;

    const header = this.props.header ? this.props.header : false;
    const footer = this.props.footer ? this.props.footer : false;

    /**
     * Merge styles with props
     */
    // eslint-disable-next-line no-underscore-dangle
    const _styles = {
      ...styles,
      section: [
        styles.section,
        {
          backgroundColor: sectionTintColor,
          paddingBottom: sectionPaddingBottom,
          paddingTop: sectionPaddingTop,
        },
      ],
      sectionheader__text: [
        styles.sectionheader__text,
        { color: headerTextColor },
      ],
      sectionfooter__text: [
        styles.sectionfooter__text,
        { color: footerTextColor },
      ],
    };

    /**
     * Render Cell and add Border
     * @param  {Cell} child [description]
     * @param  {Int} index [description]
     * @return {View}       [description]
     */
    const renderChild = (child, index) => {
      if (!child) {
        return null;
      }
      const propsToAdd = {
        onHighlightRow: () => this.handleHighlightRow(index),
        onUnHighlightRow: this.handleUnHighlightRow,
      };

      // Skip rendering of separator
      if (
        hideSeparator ||
        !Array.isArray(children) ||
        React.Children.count(children) === 1 ||
        index === React.Children.count(children) - 1
      ) {
        return React.cloneElement(child, propsToAdd);
      }

      const invisibleSeparator =
        this.state.highlightedRowIndex === index ||
        this.state.highlightedRowIndex === index + 1;

      // Add margin, if Image is provided
      if (child.props.image) {
        // Only update if not manually updated
        const insetLeft = separatorInsetLeft !== 15 ? separatorInsetLeft : 60;
      }

      return (
        <View>
          {React.cloneElement(child, propsToAdd)}
          <Separator
            isHidden={invisibleSeparator}
            backgroundColor={child.props.backgroundColor}
            tintColor={separatorTintColor}
            insetLeft={separatorInsetLeft}
            insetRight={separatorInsetRight}
          />
        </View>
      );
    };

    /**
     * Render header if defined
     * @return {View} View with Text
     */
    const renderHeader = () => {
      if (header) {
        return (
          <View style={styles.sectionheader}>
            <Text
              allowFontScaling={allowFontScaling}
              style={_styles.sectionheader__text}
            >
              {header}
            </Text>
          </View>
        );
      }
      return undefined;
    };

    /**
     * Render footer if defined
     * @return {View} View with Text
     */
    const renderFooter = () => {
      if (footer) {
        return (
          <View style={styles.sectionfooter}>
            <Text
              allowFontScaling={allowFontScaling}
              style={_styles.sectionfooter__text}
            >
              {footer}
            </Text>
          </View>
        );
      }
      return undefined;
    };

    return (
      <View style={_styles.section}>
        {headerComponent || renderHeader()}
        <View style={styles.section_inner}>
          {React.Children.map(children, renderChild)}
        </View>
        {footerComponent || renderFooter()}
      </View>
    );
  }
}

const styles = StyleSheet.create({
  section: {},
  section_inner: {
    borderTopWidth: StyleSheet.hairlineWidth,
    borderBottomWidth: StyleSheet.hairlineWidth,
    borderColor: '#C8C7CC',
  },
  sectionheader: {
    paddingLeft: 15,
    paddingRight: 15,
    paddingBottom: 5,
  },
  sectionheader__text: {
    fontSize: 13,
  },
  sectionfooter: {
    paddingLeft: 15,
    paddingRight: 15,
    paddingTop: 10,
  },
  sectionfooter__text: {
    fontSize: 13,
  },
});

Section.propTypes = {
  allowFontScaling: PropTypes.bool,
  children: PropTypes.node,
  footerComponent: PropTypes.element,<commit_msg>use Separator component in Section component<commit_after>/* eslint-disable import/no-unresolved */
import React, { Component } from 'react';

import PropTypes from 'prop-types';

import { StyleSheet, Text, View } from 'react-native';

import Separator from './Separator';

class Section extends Component {
  constructor(props) {
    super(props);
    this.state = {
      highlightedRowIndex: undefined,
    };

    this.handleHighlightRow = index =>
      !this.state.highlightedRowIndex &&
      this.setState({ highlightedRowIndex: index });
    this.handleUnHighlightRow = () =>
      this.setState({ highlightedRowIndex: undefined });
  }
  render() {
    const {
      allowFontScaling,
      children,
      footerComponent,
      headerComponent,
      headerTextColor,
      hideSeparator,
      footerTextColor,
      sectionPaddingBottom,
      sectionPaddingTop,
      sectionTintColor,
      separatorInsetLeft,
      separatorInsetRight,
      separatorTintColor,
    } = this.props;

    const header = this.props.header ? this.props.header : false;
    const footer = this.props.footer ? this.props.footer : false;

    /**
     * Merge styles with props
     */
    // eslint-disable-next-line no-underscore-dangle
    const _styles = {
      ...styles,
      section: [
        styles.section,
        {
          backgroundColor: sectionTintColor,
          paddingBottom: sectionPaddingBottom,
          paddingTop: sectionPaddingTop,
        },
      ],
      sectionheader__text: [
        styles.sectionheader__text,
        { color: headerTextColor },
      ],
      sectionfooter__text: [
        styles.sectionfooter__text,
        { color: footerTextColor },
      ],
    };

    /**
     * Render Cell and add Border
     * @param  {Cell} child [description]
     * @param  {Int} index [description]
     * @return {View}       [description]
     */
    const renderChild = (child, index) => {
      if (!child) {
        return null;
      }
      const propsToAdd = {
        onHighlightRow: () => this.handleHighlightRow(index),
        onUnHighlightRow: this.handleUnHighlightRow,
      };

      // Skip rendering of separator
      if (
        hideSeparator ||
        !Array.isArray(children) ||
        React.Children.count(children) === 1 ||
        index === React.Children.count(children) - 1
      ) {
        return React.cloneElement(child, propsToAdd);
      }

      const invisibleSeparator =
        this.state.highlightedRowIndex === index ||
        this.state.highlightedRowIndex === index + 1;

      // Add margin, if Image is provided
      if (child.props.image) {
        // Only update if not manually updated
        const insetLeft = separatorInsetLeft !== 15 ? separatorInsetLeft : 60;
      }

      return (
        <View>
          {React.cloneElement(child, propsToAdd)}
          <Separator
            isHidden={invisibleSeparator}
            backgroundColor={child.props.backgroundColor}
            tintColor={separatorTintColor}
            insetLeft={separatorInsetLeft}
            insetRight={separatorInsetRight}
          />
        </View>
      );
    };

    /**
     * Render header if defined
     * @return {View} View with Text
     */
    const renderHeader = () => {
      if (header) {
        return (
          <View style={styles.sectionheader}>
            <Text
              allowFontScaling={allowFontScaling}
              style={_styles.sectionheader__text}
            >
              {header}
            </Text>
          </View>
        );
      }
      return undefined;
    };

    /**
     * Render footer if defined
     * @return {View} View with Text
     */
    const renderFooter = () => {
      if (footer) {
        return (
          <View style={styles.sectionfooter}>
            <Text
              allowFontScaling={allowFontScaling}
              style={_styles.sectionfooter__text}
            >
              {footer}
            </Text>
          </View>
        );
      }
      return undefined;
    };

    return (
      <View style={_styles.section}>
        {headerComponent || renderHeader()}
        <Separator insetLeft={0} tintColor={separatorTintColor} />
        {React.Children.map(children, renderChild)}
        <Separator insetLeft={0} tintColor={separatorTintColor} />
        {footerComponent || renderFooter()}
      </View>
    );
  }
}

const styles = StyleSheet.create({
  section: {},
  sectionheader: {
    paddingLeft: 15,
    paddingRight: 15,
    paddingBottom: 5,
  },
  sectionheader__text: {
    fontSize: 13,
  },
  sectionfooter: {
    paddingLeft: 15,
    paddingRight: 15,
    paddingTop: 10,
  },
  sectionfooter__text: {
    fontSize: 13,
  },
});

Section.propTypes = {
  allowFontScaling: PropTypes.bool,
  children: PropTypes.node,
  footerComponent: PropTypes.element,
{'fraction_non_alphanumeric': 0.11035478547854785, 'fraction_numerical': 0.0049504950495049506, 'mean_word_length': 2.0341051314142677, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 45, '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': '7351915', 'n_tokens_mistral': 2774, 'n_tokens_neox': 2692, 'n_words': 548}