package app.furmeet.events.system.schedule

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import app.furmeet.events.system.MainActivity
import app.furmeet.events.bff.R
import app.furmeet.events.system.TranslatableAppCompatActivityWithScheduleServiceWrapped
import app.furmeet.events.system.helper.logException
import app.furmeet.events.system.helper.longToast
import app.furmeet.events.system.schedule.abstractDataTypes.managed.AttendeeConFavorite
import app.furmeet.events.bff.databinding.ActivityRoomPartyPreviewerBinding
import com.google.gson.GsonBuilder
//import org.jetbrains.anko.longToast

// Only redirects; shows nothing
class RoomPartyPreviewerActivity : TranslatableAppCompatActivityWithScheduleServiceWrapped() {

    lateinit var binding: ActivityRoomPartyPreviewerBinding;

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityRoomPartyPreviewerBinding.inflate(layoutInflater)
        val view = binding.root
        setContentView(view)
        if (this.intent?.data == null) return finish()
        val uri = this.intent!!.data!!
        try {
            val json = Uri.decode(uri.encodedFragment!!)
            GsonBuilder().create().fromJson(json, AttendeeConFavorite::class.java)
        } catch (e: Throwable) {
            logException(e)
            longToast(getString(R.string.error_broken_invite))
            startActivity(Intent(this, MainActivity::class.java))
            return finish()
        }
        val json = Uri.decode(uri.encodedFragment!!)
        val favorite = GsonBuilder().create().fromJson(json, AttendeeConFavorite::class.java)
        favorite.notified = false
        startActivity(Intent(this, EventActivity::class.java).apply {
            putExtra("favorite", favorite)
            putExtra("offerStar", true)
            putExtra("fromNotification", this@RoomPartyPreviewerActivity.intent.getBooleanExtra("notQr", true))
        })
        finish()
    }
}
