package com.develop.food.base.widgets

import android.graphics.Canvas
import android.graphics.ColorFilter
import android.graphics.Paint
import android.graphics.PixelFormat
import android.graphics.drawable.Drawable

class CookProgressDrawable: Drawable() {

    private var stepCount = 0
    private var stepIndex = 0
    private val bgColor = 0xffE5E5E5.toInt()
    private val pgColor = 0xffE60012.toInt()
    private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
    init {
        paint.color = pgColor
        paint.style = Paint.Style.FILL
    }

    override fun draw(canvas: Canvas) {
        canvas.drawColor(bgColor)
        if (stepCount == 0) {
            return
        }
        val width = bounds.width()
        val height = bounds.height()
        val length = (stepIndex + 1) / stepCount.toFloat() * width
        canvas.drawRect(0f, 0f, length, height.toFloat(), paint)
    }

    override fun setAlpha(alpha: Int) {
        
    }

    override fun setColorFilter(colorFilter: ColorFilter?) {
        
    }

    override fun getOpacity(): Int {
        return PixelFormat.TRANSLUCENT
    }

    fun setStepState(stepIndex: Int, stepCount: Int) {
        this.stepIndex = stepIndex
        this.stepCount = stepCount
        invalidateSelf()
    }
}