define([
    'text!searchbar.html!strip'
  , 'css!searchbar'
  ],
  function (source) {
    var response = {};

    response.data = source;


    response.callback = function (self) {
      var filter = self.dom.find(".searchbar_filter");

      filter.on("filterbarbeforefilter", function (e, data) {
        var value = data.input.value;

        if ( value ) {
          // now we can autocomplete...
          // this should also run from JIO
          // whatever happens should take into account presets
          // like sorting criteria or filters set!

          // we have two actions
          //  > display suggestions listitems with a checkbox
          //  > user can check, then it will be a delete
          //  > checked items will be... moved to input, kept in suggestions
          // second action is user hitting search button
          //  > this searches, clears the autocomplete
          //  start with this!

          // question will be how to store information...
          // if we follow the DC scheme, we have some core metadata and the
          // rest must be stored in an attachment.
        }
      });

      if (window.App === undefined) {
        def = new $.Deferred;

        def.done(function(gadget) {
          // prefix instance-ids, pass JSON
          window.App.renderGadgets(gadget);
        });

        window.fallbackLoader.deferreds.push(def);
        window.fallbackLoader.args.push(self);
      } else {
        // prefix instance-ids, pass JSON
        window.App.renderGadgets(self);
      }
    };

  // return response object
  return response;
  }
);
