package com.remax.visualnovel.widget.imagepicker.views.wrapper

import android.content.Context
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.remax.visualnovel.R
import com.remax.visualnovel.databinding.PickBottomBarBinding
import com.remax.visualnovel.extension.findActivityContext
import com.remax.visualnovel.extension.setOnClick
import com.remax.visualnovel.utils.spannablex.utils.dp
import com.remax.visualnovel.widget.dialoglib.ScreenUtils
import com.remax.visualnovel.widget.imagepicker.bean.ImageItem
import com.remax.visualnovel.widget.imagepicker.bean.ImageSet
import com.remax.visualnovel.widget.imagepicker.bean.selectconfig.BaseSelectConfig
import com.remax.visualnovel.widget.imagepicker.views.base.PickerControllerView

/**
 * Created by HJW on 2022/10/24
 */
class BottomBar constructor(context: Context?, private val isAlbum: Boolean) : PickerControllerView(context) {

    private var binding: PickBottomBarBinding? = null

    private var tempSelectedList: ArrayList<ImageItem>? = null

    override fun getLayoutId(): Int {
        return R.layout.pick_bottom_bar
    }

    override fun initView(view: View?) {
        view?.run {
            binding = PickBottomBarBinding.bind(this.findViewById(R.id.bottomBar))
            binding?.also {
                it.content.maxWidth = ScreenUtils.getScreenWidth() - 106.dp
                setOnClick(it.checkBox, it.tips) {
                    val appCompatActivity = context?.findActivityContext() as? AppCompatActivity
                    when (this) {
                        it.checkBox -> {

                        }

                        it.tips -> {

                        }
                    }
                }
            }
        }
    }

    override fun getViewHeight(): Int {
        return if (isAlbum) 68.dp else 0
    }

    override fun getCanClickToCompleteView(): View? {
        return null
    }

    override fun getCanClickToIntentPreviewView(): View? {
        return null
    }

    override fun getCanClickToToggleFolderListView(): View? {
        return null
    }

    override fun setTitle(title: String?) {}

    override fun onTransitImageSet(isOpen: Boolean) {}

    override fun onImageSetSelected(imageSet: ImageSet?) {}

    override fun refreshCompleteViewState(selectedList: ArrayList<ImageItem>?, selectConfig: BaseSelectConfig?) {
        tempSelectedList = selectedList
        tempSelectedList?.forEach {
            it.openLock = binding?.checkBox?.isChecked == true
        }
    }

}