package cn.muchinfo.rma.view.autoWidget

import android.content.Context

import android.view.View
import cn.muchinfo.rma.R
import com.blankj.utilcode.util.ScreenUtils
import com.qmuiteam.qmui.util.QMUIResHelper
import com.qmuiteam.qmui.util.QMUIStatusBarHelper

import org.jetbrains.anko.px2dip
 class AutoConfig(private val designWidth: Int) {



    fun auto(size: Number): Int {
        val screenWidth = ScreenUtils.getScreenWidth()
        return size.toFloat().times(screenWidth).div(designWidth).toInt().takeIf { (size.toDouble() > 0.0 && it > 0) || size.toDouble() == 0.0 } ?: 1
    }
}

fun autoSize(size: Number,weight : Int = 900): Int = AutoConfig(weight).auto(size)
fun View.px2dp(autoSize:Number):Float = context.px2dp(autoSize(autoSize))
fun Context.px2dp(autoSize:Number):Float = px2dip(autoSize(autoSize))

fun Context.getTopBarSize(): Int = AutoConfig(900).auto(QMUIResHelper.getAttrDimen(this, R.attr.qmui_topbar_height))
fun Context.getStatusBarSize(): Int = QMUIStatusBarHelper.getStatusbarHeight(this)