package com.gh.gamecenter.core.utils

import java.text.DecimalFormat
import kotlin.math.roundToInt

object NumberUtils {

    @JvmStatic
    fun transSimpleCount(count: Int): String {
        val s: String
        s = if (count > 10000) {
            val number = count / 10000f
            val fmt = DecimalFormat("#.0")
            fmt.format(number) + "万"
        } else {
            count.toString()
        }
        return s
    }

    @JvmStatic
    fun transSimpleLetterCount(count: Int): String {
        val s: String
        s = if (count > 10000) {
            val number = count / 10000f
            val fmt = DecimalFormat("#.0")
            fmt.format(number) + "W"
        } else {
            count.toString()
        }
        return s
    }

    @JvmStatic
    fun transNewSimpleCount(count: Int, pattern: String = "#"): String {
        return if (count > 10000) {
            val number = count / 10000F
            val fmt = DecimalFormat(pattern)
            fmt.format(number) + "万"
        } else {
            count.toString()
        }
    }

    @JvmStatic
    fun transSimpleUsageTime(second: Long): String {
        val totalMinute = second / 60
        if (totalMinute < 60) return ((if (totalMinute == 0L) 1 else totalMinute).toString() + "分钟")
        val hour = (totalMinute / 60).toFloat().roundToInt()
        val minute = (totalMinute - hour * 60).toFloat().roundToInt()
        return hour.toString() + "小时" + if (minute == 0) "" else minute.toString() + "分钟"
    }

    @JvmStatic
    fun findMax(lastPositions: IntArray): Int {
        var max = lastPositions[0]
        for (value in lastPositions) {
            if (value > max) {
                max = value
            }
        }
        return max
    }
}