package com.gh.gamecenter.gamedetail.fuli.kaifu

import android.app.Activity
import android.graphics.Paint
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.utils.toColor
import com.gh.gamecenter.R
import com.gh.gamecenter.databinding.DialogServersCalendearDetailItemBinding
import com.gh.gamecenter.entity.GameEntity
import com.gh.gamecenter.entity.MeEntity
import com.gh.gamecenter.entity.ServerCalendarEntity
import com.gh.gamecenter.servers.patch.PatchKaifuActivity
import com.lightgame.utils.Utils

class ServersDetailViewHolder(val binding: DialogServersCalendearDetailItemBinding) :
    BaseRecyclerViewHolder<Any>(binding.root) {

    fun bindItem(data: ServerCalendarEntity, meEntity: MeEntity?, gameEntity: GameEntity) {
        binding.name.text = data.getNote()
        binding.time.text = data.getFormatTime("HH:mm")
        binding.remark.text = data.remark

        binding.name.setTextColor(R.color.text_title.toColor(binding.root.context))
        binding.time.setTextColor(R.color.text_title.toColor(binding.root.context))
        binding.remark.setTextColor(R.color.text_title.toColor(binding.root.context))

        if (meEntity?.isPartTime == true) {
            binding.name.paint.flags = Paint.UNDERLINE_TEXT_FLAG
            binding.name.paint.isAntiAlias = true
            binding.name.setOnClickListener {
                val context = binding.root.context
                if ("删档内测" == data.type || "不删档内测" == data.type || "公测" == data.type) {
                    Utils.toast(context, "开测信息不可编辑");
                } else {
                    (context as Activity).startActivityForResult(
                        PatchKaifuActivity.getIntent(
                            context,
                            data,
                            gameEntity.id
                        ),
                        ServersCalendarActivity.GAME_DETAIL_PATCH_KAIFU_REQUEST
                    )
                }
            }
        }
    }
}