package com.player.musicoo.view

import android.annotation.SuppressLint
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.adapter.SearchResultOtherAdapter
import com.player.musicoo.innertube.Innertube

@SuppressLint("ViewConstructor")
class SearchResultOtherView(context: Context, data: Innertube.SearchDataPage) :
    ModuleView(context) {
    init {
        contentView = inflate(getContext(), R.layout.search_result_other_layout, this)
        val title = contentView?.findViewById<TextView>(R.id.title)
        title?.text = data.title

        val moreBtn = contentView?.findViewById<LinearLayout>(R.id.moreBtn)
        moreBtn?.setOnClickListener {
            val intent = Intent(context, MoSearchMoreActivity::class.java)
            intent.putExtra(MoSearchMoreActivity.SEARCH_MORE_QUERY, data.query)
            intent.putExtra(MoSearchMoreActivity.SEARCH_MORE_PARAMS, data.params)
            context.startActivity(intent)
        }

        val rv = contentView?.findViewById<RecyclerView>(R.id.rv)
        val adapter = SearchResultOtherAdapter(context, data.searchResultList)
        rv?.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
        rv?.adapter = adapter


    }
}