package com.mime.dualscreenview.view

import android.content.Context
import android.util.AttributeSet
import android.widget.Button
import androidx.appcompat.widget.AppCompatButton
import com.mime.dualscreenview.R

class ScopeEditor: SideButtonTextView {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )
    var titleArray : Array<String>? = null
        set(value) {
            if(value != null && value.size < 1) {
                Error("titleArray는 최소 한개 이상이여야됨.")
                return
            }
            field = value
            maxValue = field!!.size
        }

    var maxValue : Int = 1
        set(value) {
            if (value < 1) {
                Error("maxValue는 무조건 0보다 커야하눈뎅....")
                return
            }
            field = value
        }

    override var value : Int = 14
        set(newValue) {
            field = newValue
            text_value?.text = displayFormat.format(titleArray?.get(field) ?:"defulat")
            mValueChange?.invoke(field)
        }


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



    init {
//        super.i
//        inflate(context, R.layout.layout_steps_editor,this)
        btn_decrement?.setOnClickListener { value = Math.abs(value.dec()).rem(maxValue) }
        btn_increment?.setOnClickListener { value = value.inc().rem(maxValue) }
        leftButtonTitle = "<"
        rightButtonTitle = ">"
    }



}