require('insert-css')(require('./semantic-ui/semantic.css'));
require('insert-css')(require('./main.css'));

var Vue = require('vue');
var PouchDB = require('pouchdb');

var db = new PouchDB(location.protocol + '//' + location.hostname + ':'
    + location.port + '/hypothesizer');

Vue.filter('limit',
  function (list, n) {
    return list.slice(0, n);
  });

Vue.filter('truncate',
  function (s, n) {
    return s.slice(0, n) + '...';
  });

window.Hypothesizer = new Vue({
  el: 'body',
  data: {
    total_public: 0,
    total_public_tags: 0,
    users: [],
    uris: []
  },
  computed: {
    total_public_users: function() {
      return this.users.length;
    },
    total_public_uris: function() {
      return this.uris.length;
    },
    top_uris: function() {
      // sort uris by value
      // return top 100 from the list
    }
  },
  components: {
    'search-suggest': require('./search-suggest')
  }
});

db.query('hypothesizer/by_created')
  .then(function (res) {
    Hypothesizer.total_public = res['rows'][0]['value'];
  });

db.query('hypothesizer/by_tag')
  .then(function (res) {
    Hypothesizer.total_public_tags = res['rows'][0]['value'];
  });

db.query('hypothesizer/by_user', {group_level: 1})
  .then(function (res) {
    Hypothesizer.users = res['rows'];
  });

db.query('hypothesizer/by_uri', {group: true})
  .then(function (res) {
    Hypothesizer.uris = res['rows'];
  });

@@ -569,16 +569,17 @@
 uris: %5B%5D
+,
 %0A  %7D,%0A  
@@ -1074,16 +1074,31 @@
 /by_tag'
+, %7Bgroup: true%7D
 )%0A  .the
@@ -1160,36 +1160,31 @@
  res%5B'rows'%5D
-%5B0%5D%5B'value'%5D
+.length
 ;%0A  %7D);%0A%0Adb.

Fix total_public_tags to be unique tags count