package app.furmeet.events.system.schedule

import android.graphics.Color
import android.os.Bundle
import android.view.WindowManager
import androidx.core.app.ActivityCompat
import androidx.core.graphics.toColor
import androidx.core.graphics.toColorLong
import androidx.recyclerview.widget.LinearLayoutManager
import app.furmeet.events.bff.R
import app.furmeet.events.system.TranslatableAppCompatActivityWithScheduleServiceWrapped
import app.furmeet.events.system.helper.*
import app.furmeet.events.system.schedule.adapters.FavoritesAdapter
import app.furmeet.events.system.schedule.managers.ScheduleManagerGetter
import app.furmeet.events.bff.databinding.ActivityFavoritesBinding

//import kotlinx.android.synthetic.main.activity_favorites.*

class FavoritesActivity : TranslatableAppCompatActivityWithScheduleServiceWrapped() {

    lateinit var binding: ActivityFavoritesBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        ActivitiesForFragments[this.javaClass.simpleName] = this
        super.onCreate(savedInstanceState)
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
        window.statusBarColor = Color.TRANSPARENT
        binding = ActivityFavoritesBinding.inflate(layoutInflater)
        val view = binding.root
        setContentView(view)
        resourcesAliased = this.resources
        setSupportActionBar(binding.toolbar)
        val scheduleManager = ScheduleManagerGetter[this]
        binding.collapsingToolbar.setExpandedTitleTextAppearance(R.style.ExpandedAppBar)
        binding.collapsingToolbar.setCollapsedTitleTextAppearance(R.style.CollapsedAppBar)
        binding.collapsingToolbar.title = getString(R.string.schedule_events_favorites)
        binding.collapsingToolbar.setExpandedTitleColor(ActivityCompat.getColor(this, R.color.colorWhiteDoNotInvert))
        binding.collapsingToolbar.setCollapsedTitleTextColor(ActivityCompat.getColor(this, R.color.colorWhiteDoNotInvert))
        scheduleManager.convention.colorScheme?.primaryRegular?.let { binding.collapsingToolbar.setBackgroundColor(it) }
        scheduleManager.convention.imageFavorites.solved
                ?.fromCache(scheduleManager)
                ?.toDrawable()
                ?.asImageOf(binding.appBarImage)
        binding.favorites.layoutManager = LinearLayoutManager(this)
        FavoritesAdapter(this, scheduleManager).apply {
            binding.favorites.adapter = this
            scheduleManager.addObserver(this)
        }
    }
}
