//230404

require("FontHaxorNarrow7x17").add(Graphics);
require("FontDylex7x13").add(Graphics);

const locale = require("locale");
const dateutil = require("date_utils");
const currentFont=g.getFont();

const width = 175; 
const height = 175;
const offset = 25;

var d = new Date();
var nowDate = d.getDate(); //today's date
var drawTimeout;
var encourage = ["you\'re doing\ngreat!","pas de deux it!","you\'re amazing~","you got dis","keep going","you\'re one\nin a melon!","we\'re rooting\nfor you!","believe in\nyourself","dance like\nno one\'s\nwatching"];

var bgimg = {
  width : 175, height : 175, bpp : 4,
  transparent : -1,
  palette : new Uint16Array([46452,38393,32024,42585,52984,46739,59130,21489,46543,21493,25358,52696,48564,61210,29944,46322]),
  buffer : require("heatshrink").decompress(atob("[encoded data, 7024 characters]"))
};
//TAP ALL THE THINGS
Bangle.on('touch', (n, e) => {
  // <88, top
  if (e.x < width && e.y > offset) { 
    g.setColor(0,0,0);
    g.setFont("Dylex7x13",2).setFontAlign(0,0).drawString(getEncour(), width/2, height/2);
    setInterval(draw,3000);
  }
});

//getters
function getRandomInt(max) {
  return Math.floor(Math.random() * max);
}
function getEncour(){ //return string
  let rando = getRandomInt(encourage.length);
  return encourage[rando];
}
//everymine
function queueDraw() {
  if (drawTimeout) clearTimeout(drawTimeout);
  drawTimeout = setTimeout(function() {
    drawTimeout = undefined;
    draw();
  }, 60000 - (Date.now() % 60000));
}

function draw() {
  var time = locale.time(d, 1);
  //var date = locale.date(d);
  var mo = dateutil.month(d.getMonth() + 1, 1);

  g.drawImage(bgimg,0,offset); //bg
  g.setFont("HaxorNarrow7x17").setColor(0,0,0);
  g.setFontAlign(0, 0).setFont(currentFont, 7).drawString(time, width/2, 100);
  g.setFontAlign(0,0).setFont(currentFont, 3).drawString(mo + " " + nowDate, width/2, 130);

  queueDraw();
}

//ready set go!
g.clear();

Bangle.setUI("clock"); //button
Bangle.drawWidgets(); //widgets
Bangle.loadWidgets();

draw(); //draw all the things
