import m from 'mithril';
import { Widget } from 'components/widgets/widget';

require("./clock.css");

export class Clock extends Widget {
	constructor(vnode: any) {
		super(vnode);
	}
	
	view(vnode: m.Vnode<{}, {}>): m.Children {
		var now = new Date();
		var days = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
		var nextUpdateDelay = 61 - now.getSeconds();
		setTimeout(() => m.redraw(), nextUpdateDelay * 1000);
		
		return <div class="widget clock">
			<div class="date">
				<p class="day">{days[now.getDay()]}</p>
				<p class="date">{('0'+now.getDate()).slice(-2) + '/' + ('0'+now.getMonth()).slice(-2)}</p>
			</div>
			<p class="time">{('0'+now.getHours()).slice(-2) + ':' + ('0'+now.getMinutes()).slice(-2)}</p>
		</div>;    
	}
}
