package com.remax.visualnovel.widget.imageviewer.viewer

import android.view.View
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import com.remax.visualnovel.BuildConfig
import com.remax.visualnovel.R
import com.remax.visualnovel.entity.model.MyImgData
import com.remax.visualnovel.widget.imageviewer.ImageViewerBuilder
import com.remax.visualnovel.widget.imageviewer.core.Photo
import com.remax.visualnovel.widget.imageviewer.core.SimpleDataProvider
import com.remax.visualnovel.widget.imageviewer.utils.Config


/**
 * viewer的自定义初始化方案
 */
object ViewerHelper {
    fun openViewer(
        context: FragmentActivity,
        datas: List<Photo>,
        currPosition: Int = 0
    ) {
        if (datas.isNotEmpty() && currPosition < datas.size) {
            val newList = arrayListOf<Photo>().apply { addAll(datas) }
            provideImageViewerBuilder(context, newList[currPosition], newList).show()
        }
    }

    fun openViewerOne(context: FragmentActivity, imageView: View?, imageUrl: String?) {
        openViewerOne(context, MyImgData(imageView?.hashCode()?.toLong() ?: 0L, imageUrl))
    }

    fun openViewerOne(context: FragmentActivity, data: Photo) {
        val datas = arrayListOf(data)
        provideImageViewerBuilder(context, datas[0], datas).show()
    }

    private fun provideImageViewerBuilder(
        context: FragmentActivity,
        clickedData: Photo,
        myImgDatas: List<Photo>
    ): ImageViewerBuilder {
        // viewer 构造的基本元素
        val builder = ImageViewerBuilder(
            context = context,
            dataProvider = SimpleDataProvider(clickedData, myImgDatas),
            imageLoader = MyImageLoader(),
            transformer = SimpleTransformer()
        )
//        Config.TRANSITION_OFFSET_Y = StatusBarUtils.statusBarHeight
        Config.VIEWER_BACKGROUND_COLOR = ContextCompat.getColor(context, R.color.black)
        Config.DEBUG = BuildConfig.DEBUG

        //MyViewerCustomizer().process(context, builder) // 添加自定义业务逻辑和UI处理

        return builder
    }
}


