package com.app.input.inputaura.kmnhffs

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import com.app.input.inputaura.InputAura
import com.app.input.inputaura.dasda.Shikamaru
import com.app.input.inputaura.bgtng.OnuIg
import com.app.input.inputaura.databinding.RwtsbfBinding
import com.app.input.inputaura.ohbnf.DaBase
import com.app.input.inputaura.ohbnf.OpnYty
import com.app.input.inputaura.onjfsgvfsf.OvfYfd
import kotlinx.coroutines.launch

class OfhTff : Fragment() {
    private lateinit var vb: RwtsbfBinding
    companion object {

        @JvmStatic
        fun newInstance() =
            OfhTff()
    }

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

        init()

        return vb.root
    }


    private fun init() {
        val mainAdapter = OvfYfd(
            requireContext()
        ).apply {
            setRemoveLike(object : OnuIg {
                override fun OnRemoveLike(data: Shikamaru) {
                     lifecycleScope.launch {
                         OpnYty.removeLike(data)
                     }
                }

            })
        }
        vb.likeRecycler.run {
            adapter = mainAdapter
            layoutManager = GridLayoutManager(requireContext(), 2)
        }

        DaBase.Companion.daBase.ThemesDao().queryAllLike().observe(requireActivity()) {
            Log.d(InputAura.Companion.TAG, "---------it=${it?.size}")
            if(it.isNullOrEmpty()){
                vb.likeRecycler.isVisible = false
                vb.emptyTitle.isVisible = true
            }else{
                vb.likeRecycler.isVisible = true
                vb.emptyTitle.isVisible = false
                mainAdapter.setForYouList(it)
            }

        }
    }


}