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

import android.content.Context
import android.view.View
import androidx.core.view.isVisible
import com.remax.visualnovel.R
import com.remax.visualnovel.databinding.PickerFolderItemBinding
import com.remax.visualnovel.widget.imagepicker.bean.ImageItem
import com.remax.visualnovel.widget.imagepicker.bean.ImageSet
import com.remax.visualnovel.widget.imagepicker.presenter.IPickerPresenter
import com.remax.visualnovel.widget.imagepicker.views.base.PickerFolderItemView

/**
 * Created by HJW on 2022/10/21
 */
class FolderItemView constructor(context: Context?) : PickerFolderItemView(context) {

    private var binding: PickerFolderItemBinding? = null

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

    override fun initView(view: View?) {
        view?.let {
            binding = PickerFolderItemBinding.bind(this.findViewById(R.id.group))
        }
    }

    override fun getItemHeight(): Int = -1

    override fun displayCoverImage(imageSet: ImageSet?, presenter: IPickerPresenter?) {
        imageSet?.also {
            if (it.cover != null) {
                presenter?.displayImage(binding?.cover, it.cover, binding?.cover?.measuredWidth ?: 0, true)
            } else {
                val imageItem = ImageItem()
                imageItem.path = it.coverPath
                imageItem.setUriPath(it.coverPath)
                presenter?.displayImage(binding?.cover, imageItem, binding?.cover?.measuredWidth ?: 0, true)
            }
        }
    }

    override fun loadItem(imageSet: ImageSet?) {
        binding?.run {
            imageSet?.let {
                name.text = it.name
                size.text = it.count.toString()
                indicator.isVisible = it.isSelected
            }
        }

    }
}