package com.example.base.extensions

import android.content.Context
import android.util.TypedValue
import android.view.ViewGroup
import com.example.base.utils.Utils

fun Int.dp2px(): Int {
    if (toInt() in intArrayOf(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) {
        return this
    }
    return (this * Utils.getApp().resources.displayMetrics.density).toInt()
}

fun Int.dp2px(context: Context): Int {
    if (toInt() in intArrayOf(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) {
        return this
    }
    return (this * context.resources.displayMetrics.density).toInt()
}

fun Int.sp2px(): Float {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, this.toFloat(), Utils.getApp().resources.displayMetrics)
}

fun Int.sp2px(context: Context): Float {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, this.toFloat(), context.resources.displayMetrics)
}

fun Int.getTwoFormat(): String {
    return if (this < 10) "0$this" else "$this"
}

