import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { Instructor } from '../api/documents.js';
import './document.js'
import { Editor } from './editor.js'
import './instructor.html';

Template.instructor.onCreated(function bodyOnCreated() {
});

Template.instructor.helpers({
  instructor() {
    return Instructor.find({}).fetch();
    },
});

Template.instructor.events({
  'click .records' (event){
    var filename= event.target.innerText;
    document.getElementById('valores').innerHTML =" "+filename;
    Meteor.call('instructor.find',(err, res) => {
      if (err) {
        alert(err);
      } else {
        var text = Editor.search(res, filename);
        var editor = $('.CodeMirror')[0].CodeMirror;
        editor.setValue(text);   
      }
    });
  },
  'click #menuToggler' (event){
    $('#wrapper').toggleClass('toggled');
  }
});

Template.instructor.onRendered( function() {
  this.editor = CodeMirror.fromTextArea( this.find( "#editorcode" ), {
    readOnly: true,
    lineNumbers: true,
    fixedGutter: true,
    theme:"monokai",
    mode:"text/html",
    lineWrapping: true,
    cursorHeight: 0.90
  });

  this.autorun(() => {
    var subscriptions = Meteor.subscribe('instructor');
    const isReady = subscriptions.ready();
    var docs = Instructor.find({});
    if (isReady && docs) {
      var lines = Editor.readLines(docs);
      this.editor.setValue(lines);
      document.getElementById('valores').innerHTML ="index.html";
    }
  });
});
@@ -408,16 +408,252 @@
 vents(%7B%0A
+  'click #optionFiles' (event) %7B%0A    $('#wrapper').toggleClass('toggled');%0A    $('.collapse').toggleClass('in');%0A  %7D,%0A  'click #menuToggler' (event)%7B%0A    $('#wrapper').toggleClass('toggled');%0A    $('.collapse').collapse('toggle');%0A  %7D,%0A
   'click
@@ -1016,104 +1016,147 @@
 xt);
-   
 %0A      
-%7D%0A    %7D);%0A  %7D,%0A  'click #menuToggler' (event)%7B%0A    $('#wrapper').toggleClass('toggled'
+  var menu = $(%22.collapse%22);%0A        if (menu.hasClass('in')) %7B%0A          $(%22.collapse%22).collapse('toggle');%0A        %7D%0A      %7D%0A    %7D
 );%0A 

add missing collapse logic