<commit_before>import React from 'react'
import { openURL } from '@/_helpers/browser-api'
import { Props } from '../typings'
import { updateConfigOrProfile, formItemLayout } from '../helpers'

import { FormComponentProps } from 'antd/lib/form'
import { Form, Select, Switch, Button } from 'antd'

const isChrome = navigator.userAgent.includes('Chrome')

export class General extends React.Component<Props & FormComponentProps> {
  openShortcuts = () => {
    openURL('chrome://extensions/shortcuts')
  }

  render () {
    const { t, config } = this.props
    const { getFieldDecorator } = this.props.form

    return (
      <Form>
        {isChrome && // @todo wait for firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1303384
          <Button onClick={this.openShortcuts}>{t('opt_shortcuts')}</Button>
        }
        <Form.Item
          {...formItemLayout}
          label={t('opt_active')}
          help={t('opt_app_active_help')}
        >{
          getFieldDecorator('config#active', {
            initialValue: config.active,
            valuePropName: 'checked',
          })(
            <Switch />
          )
        }</Form.Item>
        <Form.Item
          {...formItemLayout}
          label={t('opt_animation')}
          help={t('opt_animation_help')}
        >{
          getFieldDecorator('config#animation', {
            initialValue: config.animation,
            valuePropName: 'checked',
          })(
            <Switch />
          )
        }</Form.Item>
        <Form.Item
          {...formItemLayout}
          label={t('opt_language')}
        >{
          getFieldDecorator('config#langCode', {
            initialValue: config.langCode,
          })(
            <Select>
              <Select.Option value='zh-CN'>简体中文</Select.Option>
              <Select.Option value='zh-TW'>繁體中文</Select.Option>
              <Select.Option value='en'>English</Select.Option>
            </Select>
          )
        }</Form.Item>
      </Form>
    )
  }
}

export default Form.create({
  onValuesChange: updateConfigOrProfile
})(General)<commit_msg>refactor(options): add reset button<commit_after>import React from 'react'
import { openURL } from '@/_helpers/browser-api'
import { resetConfig } from '@/_helpers/config-manager'
import { resetAllProfiles } from '@/_helpers/profile-manager'
import { Props } from '../typings'
import { updateConfigOrProfile, formItemLayout } from '../helpers'

import { FormComponentProps } from 'antd/lib/form'
import { Form, Select, Switch, Button } from 'antd'

const isChrome = navigator.userAgent.includes('Chrome')

export class General extends React.Component<Props & FormComponentProps> {
  isReseted = false

  openShortcuts = () => {
    openURL('chrome://extensions/shortcuts')
  }

  resetConfigs = async () => {
    await resetConfig()
    this.isReseted = true
    await resetAllProfiles()
    this.isReseted = true
  }

  componentDidUpdate () {
    if (this.isReseted) {
      this.isReseted = false
      this.props.form.resetFields()
    }
  }

  render () {
    const { t, config } = this.props
    const { getFieldDecorator } = this.props.form

    return (
      <Form>
        {isChrome && // @todo wait for firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1303384
          <Button onClick={this.openShortcuts}>{t('opt_shortcuts')}</Button>
        }
        <Form.Item
          {...formItemLayout}
          label={t('opt_active')}
          help={t('opt_app_active_help')}
        >{
          getFieldDecorator('config#active', {
            initialValue: config.active,
            valuePropName: 'checked',
          })(
            <Switch />
          )
        }</Form.Item>
        <Form.Item
          {...formItemLayout}
          label={t('opt_animation')}
          help={t('opt_animation_help')}
        >{
          getFieldDecorator('config#animation', {
            initialValue: config.animation,
            valuePropName: 'checked',
          })(
            <Switch />
          )
        }</Form.Item>
        <Form.Item
          {...formItemLayout}
          label={t('opt_language')}
        >{
          getFieldDecorator('config#langCode', {
            initialValue: config.langCode,
          })(
            <Select>
              <Select.Option value='zh-CN'>简体中文</Select.Option>
              <Select.Option value='zh-TW'>繁體中文</Select.Option>
              <Select.Option value='en'>English</Select.Option>
            </Select>
          )
        }</Form.Item>
        <Form.Item
          {...formItemLayout}
          label={t('opt_config_reset')}
        >
          <Button
            type='danger'
            onClick={this.resetConfigs}
          >{t('opt_config_reset')}</Button>
        </Form.Item>
      </Form>
    )
  }
}

export default Form.create({
  onValuesChange: updateConfigOrProfile
})(General)
{'fraction_non_alphanumeric': 0.140321914981428, 'fraction_numerical': 0.002888980602558811, 'mean_word_length': 2.0774603174603175, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 52, 'https://': 2, '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': '6639915', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1425, 'n_words': 238}