package com.soundapp.soundgags.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager
import com.soundapp.soundgags.databinding.FragmentExploreStyleBinding
import com.soundapp.soundgags.ReloadApplication
import com.soundapp.soundgags.setting.HomeTransAdapter
import com.soundapp.soundgags.datame.MainViewModel


class ExploreStyleFragment : Fragment() {
    private lateinit var binding: FragmentExploreStyleBinding
    private lateinit var viewModel: MainViewModel

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentExploreStyleBinding.inflate(inflater, container, false)
        viewModel = ViewModelProvider(requireActivity())[MainViewModel::class.java]
        initView()
        return binding.root
    }

    private fun initView() {
        val adapter = HomeTransAdapter()
        binding.recyclerView.adapter=adapter
        val flexboxLayoutManager = GridLayoutManager(this.requireContext(), 2)

        binding.recyclerView.layoutManager=flexboxLayoutManager

//        viewModel.randomItems.observe(viewLifecycleOwner) { randomItems ->
//            // 更新UI
//            adapter.setList(randomItems)
//        }
//        viewModel.loadRandomItems()
        viewModel.debugDatabase()
        ReloadApplication.familiars?.let { adapter.setList(it) }
    }
}