

Template.alarm.helpers({
  last_reading: Meteor.zoblak.client.last_sensor_reading,
  state: function() {
    return Meteor.zoblak.client.controller_state().state;
  },
  pretty_time: function(time) {
    return moment(time).format("DD.MM.YYYY, HH:mm")
  },
  all_temperatures: function() {
    var result = "";
    var temperatures = Meteor.zoblak.client.last_sensor_reading().temperatures;

    for (var i in temperatures) {
      var temperature = parseFloat(temperatures[i]).toFixed(1);
      var temperatureLabel = (Meteor.zoblak.shared.valid_temperature(temperature)) ? temperature : "XX.X";
      result += '' + temperatureLabel + ' °C ';
    }
    return result;
  },
  pretty_reasons: function(reasons) {
    var results = "";
    if(reasons.tooHot) {
      results += "Temperatura previsoka!";
    }
    if(reasons.tooCold) {
      results += "Temperatura preniska!";
    }
    if(reasons.phoneSilent) {
      results += "Mobitel nedostupan! Provjerite internet!";
    }
    if(reasons.boxSilent) {
      results += "Zoblak kutija se ne javlja! Provjerite internet!";
    }
    return results;
  }
});

Template.alarm.events({
  'click #run_alarm_settings': function() {
    Modal.show('alarm_settings');
  },
  'click #stop_alarm': function() {
    let controller_id = Meteor.zoblak.client.controller_state().controller_id;
    Meteor.call('stopTheAlarm', controller_id);
  }
});

Template.alarm.helpers({

});
