package com.remax.visualnovel.ui.main.actor

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.fragment.app.viewModels
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.dylanc.loadingstateview.BgColorType
import com.remax.visualnovel.app.base.BaseBindingFragment
import com.remax.visualnovel.databinding.FragmentMainActorBinding
import com.remax.visualnovel.databinding.FragmentMainBookBinding
import com.remax.visualnovel.ui.main.book.BookListViewModel
import com.remax.visualnovel.utils.Routers
import com.remax.visualnovel.widget.custom.TagItem
import dagger.hilt.android.AndroidEntryPoint
import kotlin.getValue



@AndroidEntryPoint
@Route(path = Routers.ROUTE_FRAG_ACTORLIST)
class ActorListFragment : BaseBindingFragment<FragmentMainActorBinding>() {

    private val contactViewModel by viewModels<ActorListViewModel>()

    override fun onCreated(bundle: Bundle?) {
        setUI()
    }

    override fun backgroundColorType(): BgColorType {
        return BgColorType.TRANSPARENT
    }

    private fun setUI() {
        initTagLayout()

        with(binding) {
            tagFlowLayout
        }
    }

    private fun initTagLayout() {
        with(binding) {
            // 模拟数据
            val tags = listOf(
                TagItem("1", "Youth"),
                TagItem("2", "Lolita"),
                TagItem("2", "Lolita2"),
                TagItem("3", "Overbearing CEO ABCDEFG Overbearing CEO ABCDEFG Overbearing CEO ABCDEFG"),
                TagItem("3", "ggggggggggg CEO ABCDEFG Overbearing CEO ABCDEFG Overbearing CEO ABCDEFG"),
                TagItem("4", "Uncle"),
                TagItem("5", "Character Status"),
                TagItem("6", "Imouto"),
                TagItem("7", "Fanwork"),
                TagItem("8", "LastLine"),
            )

            tagFlowLayout.setTags(tags)

            tagFlowLayout.setOnTagClickListener { tag ->
                Toast.makeText(context, "Clicked: ${tag.text}", Toast.LENGTH_SHORT).show()
            }

            tagFlowLayout.setOnExpandStateChangeListener { isExpanded ->
                Log.d("TagFlowLayout", "Expand state: $isExpanded")
            }
        }
    }

    companion object {
        fun newInstance(): ActorListFragment {
            return ARouter.getInstance().build(Routers.ROUTE_FRAG_ACTORLIST)
                .navigation() as ActorListFragment
        }
    }

}