import React from 'react'

export default class Prefs extends React.Component {
  static propTypes = {
    prefs: React.PropTypes.object.isRequired,
    setPrefs: React.PropTypes.func.isRequired,
    providerRefresh: React.PropTypes.func.isRequired,
  }

  toggleEnabled = this.toggleEnabled.bind(this)
  handleRefresh = this.handleRefresh.bind(this)

  toggleEnabled(e) {
    e.preventDefault()
    let prefs = Object.assign({}, this.props.prefs)
    prefs.enabled = !prefs.enabled
    this.props.setPrefs('provider.cdg', prefs)
  }

  handleRefresh() {
    this.props.providerRefresh('cdg')
  }

  render() {
    const { prefs } = this.props
    if (!prefs) return null

    const enabled = prefs.enabled === true
    let paths = prefs.paths || []

    paths = paths.map(path => (
      <p key={path}>{path}</p>
    ))

    return (
      <div>
        <label>
          <input type='checkbox' checked={enabled} onClick={this.toggleEnabled}/>
          <strong> CD+Graphics</strong>
        </label>
        <button onClick={this.handleRefresh}>Refresh</button>
        {paths}
      </div>
    )
  }
}

@@ -246,30 +246,27 @@
 red,%0A  %7D%0A%0A  
-toggle
+set
 Enabled = th
@@ -264,30 +264,27 @@
 bled = this.
-toggle
+set
 Enabled.bind
@@ -341,22 +341,19 @@
 his)%0A%0A  
-toggle
+set
 Enabled(
@@ -361,31 +361,8 @@
 ) %7B%0A
-    e.preventDefault()%0A
     
@@ -433,20 +433,22 @@
 d = 
-!prefs.enabl
+e.target.check
 ed%0A 
@@ -884,25 +884,23 @@
  onC
-lick
+hange
 =%7Bthis.
-toggle
+set
 Enab

FIx warning and remove use of preventDefault on checkbox