<commit_before>import React, { Component, PropTypes } from 'react';
import ua from 'ua-parser-js';
import cookie from 'cookie-cutter';

import '../styles/style.scss';

class SmartBanner extends Component {
  constructor(props) {
    super(props);

    this.state = {
      type: '',
      appId: '',
      settings: {},
    };
  }

  static propTypes = {
    daysHidden: PropTypes.number,
    daysReminder: PropTypes.number,
    appStoreLanguage: PropTypes.string,
    button: PropTypes.string,
    storeText: PropTypes.objectOf(PropTypes.string),
    price: PropTypes.objectOf(PropTypes.string),
    force: PropTypes.string,
    title: PropTypes.string,
    author: PropTypes.string,
  };

  static defaultProps = {
    daysHidden: 15,
    daysReminder: 90,
    appStoreLanguage: window.navigator.language.slice(-2) ||
      window.navigator.userLanguage.slice(-2) || 'us',
    button: 'View',
    storeText: {
      ios: 'On the App Store',
      android: 'In Google Play',
      windows: 'In Windows Store',
      kindle: 'In the Amazon Appstore',
    },
    price: {
      ios: 'Free',
      android: 'Free',
      windows: 'Free',
      kindle: 'Free',
    },
    force: '',
    title: '',
    author: '',
  };

  componentWillMount() {
    this.setType(this.props.force);
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.force !== this.props.force) {
      this.setType(nextProps.force);
    }
  }

  setType(deviceType) {
    const agent = ua(window.navigator.userAgent);
    let type = '';

    if (deviceType) { // force set case
      type = deviceType;
    } else if (agent.os.name === 'Windows Phone' || agent.os.name === 'Windows Mobile') {
      type = 'windows';
    // iOS >= 6 has native support for Smart Banner
    } else if (agent.os.name === 'iOS' && parseInt(agent.os.version, 10) < 6) {
      type = 'ios';
    } else if (agent.device.vender === 'Amazon' || agent.browser.name === 'Silk') {
      type = 'kindle'
    } else if (agent.os.name === 'Android') {
      type = 'android';
    }

    this.setState({
      type,
    }, () => {
      if (type) {
        this.setSettingsByType();
      }
    });
  }

  parseAppId() {
    const meta = window.document.querySelector(
      `meta[name="${this.state.settings.appMeta}"]`);

    if (!meta) {
      return '';
    }

    let appId = '';
    if (this.state.type === 'windows') {
      appId = meta.getAttribute('content');
    } else {
      appId = /app-id=([^\s,]+)/.exec(meta.getAttribute('content'))[1];
    }

    this.setState({
      appId,
    });

    return appId;
  }

  setSettingsByType() {
    const mixins = {
      ios: {
        appMeta: 'apple-itunes-app',
        iconRels: ['apple-touch-icon-precomposed', 'apple-touch-icon'],
        getStoreLink: () =>
          `https://itunes.apple.com/${this.props.appStoreLanguage}/app/id`,
      },
      android: {
        appMeta: 'google-play-app',
        iconRels: ['android-touch-icon', 'apple-touch-icon-precomposed', 'apple-touch-icon'],
        getStoreLink: () =>
          'http://play.google.com/store/apps/details?id=',
      },
      windows: {
        appMeta: 'msApplication-ID',
        iconRels: ['windows-touch-icon', 'apple-touch-icon-precomposed', 'apple-touch-icon'],
        getStoreLink: () =>
          'http://www.windowsphone.com/s?appid=',
      },
      kindle: {
        appMeta: 'kindle-fire-app',
          iconRels: ['windows-touch-icon', 'apple-touch-icon-precomposed', 'apple-touch-icon'],
          getStoreLink: () =>
            'amzn://apps/android?asin=',
      },
    };

    this.setState({
      settings: mixins[this.state.type],
    }, () => {
      if (this.state.type) {
        this.parseAppId();
      }
    });
  }

  hide() {
    window.document.querySelector('html').classList.remove('smartbanner-show');
  }

  show() {
    window.document.querySelector('html').classList.add('smartbanner-show');
  }

  close() {<commit_msg>Fixed lint errors<commit_after>import React, { Component, PropTypes } from 'react';
import ua from 'ua-parser-js';
import cookie from 'cookie-cutter';

import '../styles/style.scss';

class SmartBanner extends Component {
  constructor(props) {
    super(props);

    this.state = {
      type: '',
      appId: '',
      settings: {},
    };
  }

  static propTypes = {
    daysHidden: PropTypes.number,
    daysReminder: PropTypes.number,
    appStoreLanguage: PropTypes.string,
    button: PropTypes.string,
    storeText: PropTypes.objectOf(PropTypes.string),
    price: PropTypes.objectOf(PropTypes.string),
    force: PropTypes.string,
    title: PropTypes.string,
    author: PropTypes.string,
  };

  static defaultProps = {
    daysHidden: 15,
    daysReminder: 90,
    appStoreLanguage: window.navigator.language.slice(-2) ||
      window.navigator.userLanguage.slice(-2) || 'us',
    button: 'View',
    storeText: {
      ios: 'On the App Store',
      android: 'In Google Play',
      windows: 'In Windows Store',
      kindle: 'In the Amazon Appstore',
    },
    price: {
      ios: 'Free',
      android: 'Free',
      windows: 'Free',
      kindle: 'Free',
    },
    force: '',
    title: '',
    author: '',
  };

  componentWillMount() {
    this.setType(this.props.force);
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.force !== this.props.force) {
      this.setType(nextProps.force);
    }
  }

  setType(deviceType) {
    const agent = ua(window.navigator.userAgent);
    let type = '';

    if (deviceType) { // force set case
      type = deviceType;
    } else if (agent.os.name === 'Windows Phone' || agent.os.name === 'Windows Mobile') {
      type = 'windows';
    // iOS >= 6 has native support for Smart Banner
    } else if (agent.os.name === 'iOS' && parseInt(agent.os.version, 10) < 6) {
      type = 'ios';
    } else if (agent.device.vender === 'Amazon' || agent.browser.name === 'Silk') {
      type = 'kindle';
    } else if (agent.os.name === 'Android') {
      type = 'android';
    }

    this.setState({
      type,
    }, () => {
      if (type) {
        this.setSettingsByType();
      }
    });
  }

  parseAppId() {
    const meta = window.document.querySelector(
      `meta[name="${this.state.settings.appMeta}"]`);

    if (!meta) {
      return '';
    }

    let appId = '';
    if (this.state.type === 'windows') {
      appId = meta.getAttribute('content');
    } else {
      appId = /app-id=([^\s,]+)/.exec(meta.getAttribute('content'))[1];
    }

    this.setState({
      appId,
    });

    return appId;
  }

  setSettingsByType() {
    const mixins = {
      ios: {
        appMeta: 'apple-itunes-app',
        iconRels: ['apple-touch-icon-precomposed', 'apple-touch-icon'],
        getStoreLink: () =>
          `https://itunes.apple.com/${this.props.appStoreLanguage}/app/id`,
      },
      android: {
        appMeta: 'google-play-app',
        iconRels: ['android-touch-icon', 'apple-touch-icon-precomposed', 'apple-touch-icon'],
        getStoreLink: () =>
          'http://play.google.com/store/apps/details?id=',
      },
      windows: {
        appMeta: 'msApplication-ID',
        iconRels: ['windows-touch-icon', 'apple-touch-icon-precomposed', 'apple-touch-icon'],
        getStoreLink: () =>
          'http://www.windowsphone.com/s?appid=',
      },
      kindle: {
        appMeta: 'kindle-fire-app',
        iconRels: ['windows-touch-icon', 'apple-touch-icon-precomposed', 'apple-touch-icon'],
        getStoreLink: () =>
          'amzn://apps/android?asin=',
      },
    };

    this.setState({
      settings: mixins[this.state.type],
    }, () => {
      if (this.state.type) {
        this.parseAppId();
      }
    });
  }

  hide() {
    window.document.querySelector('html').classList.remove('smartbanner-show');
  }

  show() {
    window.document.querySelector('html').classList.add('smartbanner-show');
  }

  close() {
{'fraction_non_alphanumeric': 0.1724137931034483, 'fraction_numerical': 0.0027993383382109685, 'mean_word_length': 2.4070221066319895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '6934057', 'n_tokens_mistral': 2586, 'n_tokens_neox': 2567, 'n_words': 454}