import angular from 'angular';

const app = angular.module('ir.filters', [])

app.filter('lapTime', ['Helpers', function(Helpers) {
    return function(time) {
        return Helpers.formatLapTime(time)
    }
}])

app.filter('fixed', [function() {
    return function(number, precision = null) {
        if (!number || null == number || typeof number == 'undefined') {
            return '-'
        }

        if (null !== precision) {
            return number.toFixed(precision)
        }

        if (number >= 100) {
            return number.toFixed(0)
        }

        if (number <= 9.99) {
            return number.toFixed(2)
        }

        return number.toFixed(1)
    }
}])

app.filter('speed', [function() {
    return function(speed) {
        if (null == speed || typeof speed == 'undefined') {
            return '-'
        }

        return (speed * 3.6).toFixed(0)
    }
}])

app.filter('gear', [function() {
    return function(gear) {
        if (null == gear || typeof gear == 'undefined') {
            return '-'
        }

        if (gear == 0) {
            return 'N'
        }

        if (gear == -1) {
            return 'R'
        }

        return gear
    }
}])
