package com.app.brush.guitar.ink.icicle

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.app.brush.guitar.ink.App
import com.app.brush.guitar.ink.drama.EphemeralWrapper
import com.app.brush.guitar.ink.databinding.DarkFragmentMainHomeBinding
import com.app.brush.guitar.ink.canvas.CacophonyViewAll
import com.app.brush.guitar.ink.gallery.HomeFluctuate
import com.app.brush.guitar.ink.eraser.CategoryListResonance

class QuixoticHome : Fragment() {


    private lateinit var vb: DarkFragmentMainHomeBinding



    lateinit var viewAllList: MutableList<EphemeralWrapper>
    private lateinit var adapterParent: HomeFluctuate



    companion object {

        @JvmStatic
        fun newInstance() =
            QuixoticHome()
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        vb = DarkFragmentMainHomeBinding.inflate(layoutInflater)
        return vb.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        setTabRecycler()
        setupSearchIcon()
    }

    private fun setupSearchIcon() {
        vb.ivSearch.setOnClickListener {
            startActivity(Intent(requireContext(), com.app.brush.guitar.ink.eraser.SearchTrajectory::class.java))
        }
    }


    private fun setTabRecycler() {
        viewAllList = try {
            App.Companion.list
        } catch (e: kotlin.UninitializedPropertyAccessException) {
            mutableListOf()
        }
        adapterParent = HomeFluctuate(
            requireContext(), viewAllList
        ).apply {
            setClickAction(object : CacophonyViewAll {
                override fun OnClickSeeAll(name: String) {
                    startActivity(Intent(requireContext(),
                        CategoryListResonance::class.java).apply {
                        putExtra(CategoryListResonance.KEY_NAME,name)
                    })

                }

            })
        }
        vb.tabRecycler.run {
            adapter = adapterParent
            layoutManager = LinearLayoutManager(requireContext())
        }
    }




}