package com.player.musicoo.view

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.player.musicoo.R
import com.player.musicoo.activity.MoSearchMoreActivity
import com.player.musicoo.activity.MoSingerMoreSongActivity
import com.player.musicoo.adapter.TowRowListAdapter
import com.player.musicoo.innertube.Innertube

@SuppressLint("ViewConstructor")
class SingerDetailsOtherView(context: Activity, bean: Innertube.SingerDetailsListPage) :
    ModuleView(context) {
    init {
        contentView = inflate(getContext(), R.layout.singer_music_list_layout, this)
        val title = contentView?.findViewById<TextView>(R.id.title)
        title?.text = bean.title
        val moreBtn = contentView?.findViewById<LinearLayout>(R.id.moreBtn)
        moreBtn?.setOnClickListener {
            val intent = Intent(context, MoSingerMoreSongActivity::class.java)
            intent.putExtra(
                MoSingerMoreSongActivity.SINGER_MORE_SONG_BROWSE_ID,
                bean.browseId
            )
            intent.putExtra(MoSingerMoreSongActivity.SINGER_MORE_SONG_PARAMS, bean.params)
            intent.putExtra(MoSingerMoreSongActivity.SINGER_MORE_TYPE, bean.pageType)
            context.startActivity(intent)
        }
        when (bean.pageType) {
            "MUSIC_PAGE_TYPE_ARTIST_DISCOGRAPHY" -> {
                moreBtn?.visibility = VISIBLE
            }

            "MUSIC_PAGE_TYPE_PLAYLIST" -> {
                moreBtn?.visibility = VISIBLE
            }

            else -> {
                moreBtn?.visibility = GONE
            }
        }

        val rv = contentView?.findViewById<RecyclerView>(R.id.rv)

        val adapter = TowRowListAdapter(context, bean.contents?.musicCarouselShelfContentList!!)
        rv?.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
        rv?.adapter = adapter
    }

}