
Template.settings.helpers({
  timeSelected: function(time) {
    var config = Meteor.zoblak.client.controller_state().config;
    return config.automaticTimeOfDay == time;
  },

  dayChecked: function(day) {
    var config = Meteor.zoblak.client.controller_state().config;
    var days = config.automaticDaysOfWeek || [];
    return days.includes(day)
  },

  manualInflowChecked: function(day) {
    var config = Meteor.zoblak.client.controller_state().config;
    return config.manualInflow;
  }


});

Template.settings.events({
  'click #save_settings': function() {
    var instance = Template.instance();
    selectedTime = instance.$('#time_of_day').val();
    selectedDays = [];
    instance.$('.day_checkbox').each(function() {
      if (this.checked) {
        selectedDays.push(instance.$(this).val());
      }
    });
    var manualInflow = instance.$('#manual_inflow').is(':checked');
    console.log("MI ", manualInflow);
    var controller_id = Session.get('controller_id');
    Meteor.call('saveControllerConfig', controller_id, selectedTime, selectedDays, manualInflow);
  }
});
