package kr.co.vividnext.sodalive.live.reservation.complete

import android.content.Intent
import android.widget.Toast
import androidx.core.content.IntentCompat
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.base.BaseActivity
import kr.co.vividnext.sodalive.common.Constants
import kr.co.vividnext.sodalive.databinding.ActivityLiveReservationCompleteBinding
import kr.co.vividnext.sodalive.live.reservation.MakeLiveReservationResponse
import kr.co.vividnext.sodalive.main.MainActivity

class LiveReservationCompleteActivity : BaseActivity<ActivityLiveReservationCompleteBinding>(
    ActivityLiveReservationCompleteBinding::inflate
) {
    override fun setupView() {
        val response = IntentCompat.getParcelableExtra(
            intent,
            Constants.EXTRA_LIVE_RESERVATION_RESPONSE,
            MakeLiveReservationResponse::class.java
        )

        if (response == null) {
            Toast.makeText(applicationContext, R.string.retry, Toast.LENGTH_LONG).show()
            finish()
            return
        }

        binding.toolbar.tvBack.text = "라이브 예약 완료"
        binding.toolbar.tvBack.setOnClickListener { finish() }

        binding.tvNickname.text = response.nickname
        binding.tvTitle.text = response.title
        binding.tvDate.text = response.beginDateString
        binding.tvPrice.text = response.price

        binding.tvHaveCan.text = "${response.haveCan}"
        binding.tvUseCan.text = "${response.useCan}"
        binding.tvRemainingCan.text = "${response.remainingCan}"

        binding.tvGoHome.setOnClickListener {
            val intent = Intent(applicationContext, MainActivity::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
            intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
            startActivity(intent)
            finish()
        }

        binding.tvGoReservationList.setOnClickListener {
            finish()
        }
    }
}
