import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class OpenstackUtils {
  public static MiBToUserFriendly(mebibytes: any, showMBParentheses=false, resource=$localize`RAM`) {
    let display;
    let size = Number(mebibytes);
    let converted = false;
    if (size >= 1024) {
      size /= 1024;
      size = Math.round(size * 10) / 10;
      display = $localize`${size} GB`;
      converted = true;
    } else {
      display = $localize`${size} MB`;
    }
    if (showMBParentheses && converted) {
      display += ` (${mebibytes} MB)`;
    }
    display += ` ${resource}`;
    return display;
  }
}
