import { Component, Input } from '@angular/core';
import { HealthProvider } from '../../providers/health/health';
import {Observable} from 'rxjs/Observable';
import { HumanizePipe  } from 'angular2-humanize';

/**
 * Generated class for the AuthDetailComponent component.
 *
 * See https://angular.io/api/core/Component for more info on Angular
 * Components.
 */
@Component({
    selector: 'auth-detail',
    templateUrl: 'auth-detail.html'
})
export class AuthDetailComponent {

    @Input() authId;
    @Input() rank;
    @Input() cals;
    @Input() showStyle;
    text: string;
    ath: Observable<object>;
    total: Observable<object>;

    constructor(private hp: HealthProvider) {
        console.log('Hello AuthDetailComponent Component');
        this.text = 'Hello World '+this.authId;
        console.log(this.authId);

    }
    ngOnInit() {
        console.log("aid = ",this.authId);
        this.ath = this.hp.getAthlete(this.authId);
        /*
            .subscribe(
                data => {
                    //console.log("ATH = ", JSON.stringify(data));
                    return data.output;
                }, 
                error => {
                    console.log(error);
                }
            );*/
    }

    format(data) {
        let r = /,/gi
        //console.log(data.replace(r, ''));
        console.log("format ", data);
        let n = parseInt(data);
        function abbreviateNumber(value) {
            var newValue = value;
            if (value >= 1000) {
                var suffixes = ["", "k", "m", "b","t"];
                var suffixNum = Math.floor( (""+value).length/3 );
                var shortValue;
                for (var precision = 2; precision >= 1; precision--) {
                    shortValue = parseFloat( (suffixNum != 0 ? (value / Math.pow(1000,suffixNum) ) : value).toPrecision(precision));
                    var dotLessShortValue = (shortValue + '').replace(/[^a-zA-Z 0-9]+/g,'');
                    if (dotLessShortValue.length <= 2) { break; }
                }
                var shortNum;
                if (shortValue % 1 != 0)  shortNum = shortValue.toFixed(1);
                newValue = shortValue+suffixes[suffixNum];
            }
            return newValue;
        }

        let v = abbreviateNumber(n);	
        //return (  n / 1000 ) + "k";
        return v;

    }
}
