import Ember from 'ember'

const {TextField, get, run} = Ember

export default TextField.extend({
  type: 'search',

  // Time in MS to wait (debounce) the search.
  wait: 60,

  // Selector for content tag using `document.querySelector`.
  // contentTag: '',

  // Optional array to observe for changes. Helps keep the search in sync.
  // content: []

  // Optional array to observe for changes. Helps keep the search in sync.
  // content: []

  options: {
    callSearchManually: true
  },

  didInsertElement() {
    this._super(...arguments)

    if (!window.Jets) throw new Error('The Jets.js module is missing')

    const options = get(this, 'options')
    const contentTag = get(this, 'contentTag')
    const filter = get(this, 'filter')

    // Set dynamic contentTag option.
    if (!contentTag) throw new Error('Missing "contentTag" property on {{jets-search}}')
    options.contentTag = contentTag

    // If a searchSelector is set, use it to parse the 'text' for the search.
    if (filter) {
      options.manualContentHandling = function (tag) {
        tag = tag.querySelector(filter)
        return tag && (tag.innerText || tag.textContent) || '';
      }
    }

    // Create and save Jets instance.
    this.jets = new window.Jets(options)
  },

  didRender() {
    this._super(...arguments)
    if (this.jets) this.jets.update()
  },

  willDestroyElement() {
    this._super(...arguments)
    if (this.jets) this.jets.destroy()
  },

  input() {
    this._super(...arguments)
    const wait = get(this, 'wait')
    const value = get(this, 'value')
    if (!this.jets) return
    run.debounce(this, this.jets.search, value, wait)
  }
})

@@ -175,17 +175,26 @@
 ,%0A%0A  // 
-S
+Required s
 elector 
@@ -212,16 +212,20 @@
  tag
- using %60
+. Refers to 
 docu
@@ -246,9 +246,56 @@
 ctor
-%60
+All() so many lists can be processed at one time
 .%0A  
@@ -313,17 +313,20 @@
 ag: '',%0A
-%0A
+  %0A 
   // Opt
@@ -335,192 +335,364 @@
 nal 
-array to observe for changes. Helps keep the search in sync.%0A  // content: %5B%5D%0A%0A  // Optional array to observe for changes. Helps keep the search in sync.%0A  // content: %5B%5D%0A%0A  options: %7B
+selector for filtering which elements to search inside the %60contentTag%60 selector.%0A  // filter: ''%0A%0A  // Optional array to observe for changes. Helps keep the search in sync.%0A  // content: %5B%5D%0A  %0A  // Options for jets.js. You can pass in an %60options%60 object to override it.%0A  options: %7B%0A    // Disabled auto searching and allows us to do it via Ember events.
 %0A   

Clarify component properties