package com.gh.common.pop

import android.content.Context
import android.view.LayoutInflater
import com.gh.gamecenter.R
import com.gh.gamecenter.common.databinding.LayoutPopupContainerBinding
import com.gh.gamecenter.feature.entity.GameEntity

class CancelReservePop(
    private val game: GameEntity,
    binding: LayoutPopupContainerBinding,
    private val listener: OnCancelReserveListener

) : CommonPopupWindow(binding) {

    override val viewDataList: List<ViewData>
        get() {
            val list = arrayListOf<ViewData>()
            if (game.wifiAutoDownloadEnable) {
                list.add(ViewData(if (game.wifiAutoDownload) R.string.cancel_auto_download_with_wifi else R.string.enable_automatic_downloading_with_wifi) {
                    listener.enableAutoDownload(!game.wifiAutoDownload)
                })
            }
            list.add(ViewData(R.string.cancel_reserve, listener::cancelReserve))
            return list
        }

    companion object {

        fun create(
            game: GameEntity,
            context: Context,
            listener: OnCancelReserveListener
        ): CancelReservePop {
            val inflater = LayoutInflater.from(context)
            val binding = LayoutPopupContainerBinding.inflate(inflater)
            return CancelReservePop(game, binding, listener).apply {
                initView()
            }
        }
    }

    interface OnCancelReserveListener {

        fun enableAutoDownload(isEnable: Boolean)

        fun cancelReserve()
    }
}