package pxds.dlpf.buoz.fico

import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import com.test.basd.supercleanermax.R

class Jcai : View {

    private val drawPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG)

    private var isOrder: Boolean = false

    private var isAscOrder: Boolean = true

    private var lowMargin = 0f

    private var upMargin = 0f

    private val arrowLoweN: Bitmap = BitmapFactory.decodeResource(resources, R.mipmap.iyrxfubb)

    private val arrowUpN: Bitmap = BitmapFactory.decodeResource(resources, R.mipmap.xehnywbj)

    private val arrowLoweS: Bitmap = BitmapFactory.decodeResource(resources, R.mipmap.wqirzwwx)

    private val arrowUpS: Bitmap = BitmapFactory.decodeResource(resources, R.mipmap.idddacfi)

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        upMargin = measuredHeight / 4f
        lowMargin = measuredHeight / 2.3f
    }

    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {}

    fun drawOrderArrow(canvas: Canvas) {
        if (!isOrder) {
            canvas.drawBitmap(arrowUpN, 0f, upMargin, drawPaint)
            canvas.drawBitmap(arrowLoweN, 0f, lowMargin, drawPaint)
        } else {
            if (isAscOrder) {
                canvas.drawBitmap(arrowUpS, 0f, upMargin, drawPaint)
                canvas.drawBitmap(arrowLoweN, 0f, lowMargin, drawPaint)
            } else {
                canvas.drawBitmap(arrowUpN, 0f, upMargin, drawPaint)
                canvas.drawBitmap(arrowLoweS, 0f, lowMargin, drawPaint)
            }
        }

    }

    constructor(context: Context?) : super(context)

    fun setAscOrder(isOrder: Boolean, isAscOrder: Boolean = false) {
        this.isOrder = isOrder
        this.isAscOrder = isAscOrder
        invalidate()
    }

    override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
        super.onLayout(changed, left, top, right, bottom)
    }

    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        drawOrderArrow(canvas)
    }
}