import m from 'mithril';
import { GaugeLinear } from 'components/widgets/gauge-linear';

export class GaugeBattery extends GaugeLinear {
	constructor(vnode: any) {
		super(vnode);
		this.svgPaddingTop = 0.06;
	}
	
	createSvg(svgElement: SVGElement) {
		super.createSvg(svgElement);
		
		let w = Math.round(svgElement.clientWidth);
		let h = Math.round(svgElement.clientHeight);
		let paddingTop = Math.round(svgElement.clientHeight * this.svgPaddingTop);
		
		const batteryTopWidth = 0.5;
		
		let batteryTop = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
		batteryTop.setAttribute('width', (w * batteryTopWidth).toFixed(1));
		batteryTop.setAttribute('height', (paddingTop).toString());
		batteryTop.setAttribute('x', (w * (1.0 - batteryTopWidth)*0.5).toFixed(1));
		batteryTop.setAttribute('y', '0');
		batteryTop.classList.add('gauge-bg');
		svgElement.append(batteryTop);
	}
}
