package com.remax.visualnovel.ui.main.history

import android.os.Bundle
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.R
import com.remax.visualnovel.app.base.BaseBindingFragment
import com.remax.visualnovel.databinding.FragmentMainHistoryBinding
import com.remax.visualnovel.ui.main.history.customui.beans.TabItem
import com.remax.visualnovel.utils.Routers
import com.remax.visualnovel.utils.StatusBarUtil3
import dagger.hilt.android.AndroidEntryPoint
import kotlin.getValue



@AndroidEntryPoint
@Route(path = Routers.ROUTE_FRAG_HISTORY)
class HistoryFragment : BaseBindingFragment<FragmentMainHistoryBinding>() {

    private val mViewModel by viewModels<HistoryViewModel>()

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

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

    private fun setUI() {
        with (binding.toolbar) {
            setPadding(paddingLeft, paddingTop + StatusBarUtil3.getStatusBarHeight(context), paddingRight, paddingBottom)
        }

        initTabLayout()
    }

    private fun initTabLayout() {
        with (binding.tabLayout) {
            val tabItems = listOf(
                TabItem("Manga", R.mipmap.history_tab_manga),
                TabItem("Motion Comics", R.mipmap.history_tab_comics),
                TabItem("Character", R.mipmap.history_tab_books)
            )
            setTabItems(tabItems)
            setOnTabSelectedListener { position ->
                switchFragment(position)
            }
            setSelectedTab(0)
        }
    }

    private fun switchFragment(fragmentIndex: Int) {

    }

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

}