/**
 * @fileoverview added by tsickle
 * Generated from: utils/unit/unit-formatter.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/*!
 * Copyright 2020 VMware, Inc.
 * SPDX-License-Identifier: BSD-2-Clause
 */
import { Injectable } from '@angular/core';
import { TranslationService } from '@vcd/i18n';
import { CommonUtil } from '../common-util';
/**
 * UnitFormatter is used to format the value with unitName in localized string
 */
var UnitFormatter = /** @class */ (function () {
    function UnitFormatter(translationService) {
        this.translationService = translationService;
    }
    /**
     * Converts the value of inputUnit to outPutUnit returns in
     * localized string format `${value} ${outputUnit.unitName}`
     *
     * Ex: format(1000, Unit.MB, Unit.GB, 2) = "1 GB"
     *
     * @param value - value of inputUnit
     * @param inputUnit - unit of value
     * @param outputUnit - unit to which value is converted
     * @param precision - how many digits are shown after decimal
     */
    /**
     * Converts the value of inputUnit to outPutUnit returns in
     * localized string format `${value} ${outputUnit.unitName}`
     *
     * Ex: format(1000, Unit.MB, Unit.GB, 2) = "1 GB"
     *
     * @param {?} value - value of inputUnit
     * @param {?} inputUnit - unit of value
     * @param {?} outputUnit - unit to which value is converted
     * @param {?=} precision - how many digits are shown after decimal
     * @return {?}
     */
    UnitFormatter.prototype.format = /**
     * Converts the value of inputUnit to outPutUnit returns in
     * localized string format `${value} ${outputUnit.unitName}`
     *
     * Ex: format(1000, Unit.MB, Unit.GB, 2) = "1 GB"
     *
     * @param {?} value - value of inputUnit
     * @param {?} inputUnit - unit of value
     * @param {?} outputUnit - unit to which value is converted
     * @param {?=} precision - how many digits are shown after decimal
     * @return {?}
     */
    function (value, inputUnit, outputUnit, precision) {
        // TODO response from getOutputValue() needs to be formatted to localized number
        return this.translationService.translate(outputUnit.getValueWithUnitTranslationKey(), [
            CommonUtil.roundTo(inputUnit.getOutputValue(value, outputUnit), precision),
        ]);
    };
    /**
     * Converts the value of inputUnit to best unit out of availableUnits and returns
     * in localized string format `${value} ${outputUnit.unitName}`
     *
     * Ex: bestFormat(1000000, Unit.KB, [Unit.KB, Unit.MB, Unit.GB]) = "1 GB"
     *
     * @param value = value of inputUnit
     * @param inputUnit - unit of value
     * @param availableUnits - list of units from which best unit is calculated
     */
    /**
     * Converts the value of inputUnit to best unit out of availableUnits and returns
     * in localized string format `${value} ${outputUnit.unitName}`
     *
     * Ex: bestFormat(1000000, Unit.KB, [Unit.KB, Unit.MB, Unit.GB]) = "1 GB"
     *
     * @param {?} value = value of inputUnit
     * @param {?} inputUnit - unit of value
     * @param {?} availableUnits - list of units from which best unit is calculated
     * @return {?}
     */
    UnitFormatter.prototype.bestFormat = /**
     * Converts the value of inputUnit to best unit out of availableUnits and returns
     * in localized string format `${value} ${outputUnit.unitName}`
     *
     * Ex: bestFormat(1000000, Unit.KB, [Unit.KB, Unit.MB, Unit.GB]) = "1 GB"
     *
     * @param {?} value = value of inputUnit
     * @param {?} inputUnit - unit of value
     * @param {?} availableUnits - list of units from which best unit is calculated
     * @return {?}
     */
    function (value, inputUnit, availableUnits) {
        return this.format(value, inputUnit, inputUnit.findBestUnit(value, availableUnits));
    };
    UnitFormatter.decorators = [
        { type: Injectable }
    ];
    /** @nocollapse */
    UnitFormatter.ctorParameters = function () { return [
        { type: TranslationService }
    ]; };
    return UnitFormatter;
}());
export { UnitFormatter };
if (false) {
    /**
     * @type {?}
     * @private
     */
    UnitFormatter.prototype.translationService;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5pdC1mb3JtYXR0ZXIuanMiLCJzb3VyY2VSb290Ijoibmc6Ly9AdmNkL3VpLWNvbXBvbmVudHMvIiwic291cmNlcyI6WyJ1dGlscy91bml0L3VuaXQtZm9ybWF0dGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUtBLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFDM0MsT0FBTyxFQUFFLGtCQUFrQixFQUF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