package com.colorful.keyboard.theme.view

import android.graphics.Color

interface ButtonController {
    fun getPressedColor(color: Int): Int

    fun getLighterColor(color: Int): Int

    fun getDarkerColor(color: Int): Int

    fun enablePress(): Boolean

    fun enableGradient(): Boolean

}

class DefaultButtonController : ButtonController {
    private var enablePress = false

    private var enableGradient = false

    /**
     * 获得按下的颜色（明度降低10%）
     *
     * @param color
     * @return int
     */
    override fun getPressedColor(color: Int): Int {
        val hsv = FloatArray(3)
        Color.colorToHSV(color, hsv)
        hsv[2] -= 0.1f
        return Color.HSVToColor(hsv)
    }

    /**
     * 由右边的颜色算出左边的颜色（左边的颜色比右边的颜色降饱和度30%，亮度增加30%）
     * +
     *
     * @param color
     * @return
     */
    override fun getLighterColor(color: Int): Int {
        val hsv = FloatArray(3)
        Color.colorToHSV(color, hsv)
        hsv[1] -= 0.3f
        hsv[2] += 0.3f
        return Color.HSVToColor(hsv)
    }

    /**
     * 由左边的颜色生成右边的颜色
     *
     * @param color
     * @return int
     */
    override fun getDarkerColor(color: Int): Int {
        val hsv = FloatArray(3)
        Color.colorToHSV(color, hsv)
        hsv[1] += 0.3f
        hsv[2] -= 0.3f
        return Color.HSVToColor(hsv)
    }

    override fun enablePress(): Boolean {
        return enablePress
    }

    override fun enableGradient(): Boolean {
        return enableGradient
    }

    fun setEnablePress(enablePress: Boolean): DefaultButtonController? {
        this.enablePress = enablePress
        return this
    }

    fun setEnableGradient(enableGradient: Boolean): DefaultButtonController? {
        this.enableGradient = enableGradient
        return this
    }

}