localforage.config({
    name: 'todostorage'
});
var kaamKaajKoyta = '0';
localforage.length(function(e, v) {
  kaamKaajKoyta = v;
});
document.querySelector('.add-todo-now').addEventListener('click', function() {
  document.querySelector('.kiki-korbo-text').style.bottom = "-1px";
});
var todoInput = '';
document.querySelector('.kiki-korba-lekho').addEventListener('input', function() {
  todoInput = document.querySelector('.kiki-korba-lekho').value;
  console.log(todoInput);
});
document.querySelector('.kaj-korar-button').addEventListener('click', function() {
  document.querySelector('.kiki-korbo-text').style.bottom = "-50px";
  localforage.setItem(Math.random() + kaamKaajKoyta + 1, todoInput, function(e, v) {
    console.log('item saved');
    alert('item saved successfully');
    location.reload(true);
  })
});
var todoList = "";
localforage.iterate(function(value, key) {
  console.log([key, value]);
  todoList += '<div class="item item-button-right"><h2>' + value + '</h2><button data-id="' + key + '" class="todos button button-clear"><i class="icon ion-checkmark-circled"></i></button></div>';
  document.querySelector('.ajaira').innerHTML = todoList;
}, function(v, k) {
  var todoGayeb = document.getElementsByClassName('todos');
  console.log(todoGayeb);
  for (var i = 0; i < todoGayeb.length; i++) {
    todoGayeb[i].onclick = function() {
      localforage.removeItem(this.getAttribute('data-id'), function(err) {
        console.log('Key is cleared!');
        alert('Done!');
        location.reload(true);
      });
    }
  console.log('Iteration has completed');
}
});
