package com.tencent.liteav.demo.player

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import com.tencent.liteav.demo.player.databinding.FragmentMenuBinding
import com.tencent.liteav.demo.player.menu.PlayerTimer

class PlayerMenu : AppCompatActivity(), View.OnClickListener {
    private var _viewBinding: FragmentMenuBinding? = null
    private val viewBinding get() = _viewBinding!!

    private val imageBack get() = viewBinding.menuItemBack
    private val imageShare get() = viewBinding.menuItemShare
    private val imageFavorite get() = viewBinding.menuItemFavorite
    private val imageCast get() = viewBinding.menuItemCast
    private val imageTimer get() = viewBinding.menuItemTimer

    private lateinit var courseId: String

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        _viewBinding = FragmentMenuBinding.inflate(layoutInflater)
        setContentView(viewBinding.root)

        window.setLayout(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT
        )

        courseId = intent?.getStringExtra(KEY_COURSE_ID) ?: "0"

        imageBack.setOnClickListener(this)

        imageShare.setOnClickListener(this)
        imageShare.setIcon(R.mipmap.item_share)
        imageShare.setTitle("分享")

        imageFavorite.setOnClickListener(this)
        imageFavorite.setIcon(R.mipmap.item_favorite)
        imageFavorite.setTitle("收藏")

        imageCast.setOnClickListener(this)
        imageCast.setIcon(R.mipmap.item_cast)
        imageCast.setTitle("投屏")

        imageTimer.setOnClickListener(this)
        imageTimer.setIcon(R.mipmap.item_timer)
        imageTimer.setTitle("定时关闭")
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.menu_item_back -> {
                finish()
            }
            R.id.menu_item_cast -> {
            }
            R.id.menu_item_favorite -> {
            }
            R.id.menu_item_share -> {
            }
            R.id.menu_item_timer -> {
                val intent = Intent(this, PlayerTimer::class.java)
                startActivity(intent)
                finish()
            }
        }
    }


    companion object {
        const val KEY_COURSE_ID = "course_id"

        fun start(context: Context, courseId: String) {
            val intent = Intent(context, PlayerMenu::class.java).apply {
                putExtra(KEY_COURSE_ID, courseId)
            }
            context.startActivity(intent)
        }
    }
}