package com.adealink.weparty.ui.main.tab

import androidx.annotation.DrawableRes
import androidx.fragment.app.Fragment
import com.adealink.frame.aab.util.getCompatString
import com.adealink.frame.router.Router
import com.adealink.weparty.R
import com.adealink.weparty.commonui.BaseFragment
import com.adealink.weparty.commonui.widget.EmptyFragment
import com.adealink.weparty.module.im.IM
import com.adealink.weparty.module.profile.Profile
import com.adealink.weparty.ui.home.HomeFragment

enum class MainTab(val tab: String, val number: Int) {
    /**
     * 首页
     */
    HOME("home", 0),

    /**
     * 消息
     */
    MESSAGE("message", 1),

    /**
     * 我的
     */
    ME("me", 2);

    companion object {
        @JvmStatic
        fun map(number: Int): MainTab? {
            return entries.find { it.number == number }
        }
    }
}

data class Tab(
    val type: MainTab,
    val name: (() -> String),
    @DrawableRes val icon: Int,
    @DrawableRes val iconSelected: Int,
    val fragmentBuilder: () -> Fragment
)

val HOME_TAB = Tab(
    type = MainTab.HOME,
    name = {
        getCompatString(R.string.common_main_home_tab)
    },
    icon = R.drawable.main_home_ic,
    iconSelected = R.drawable.main_home_select_ic,
    fragmentBuilder = {
        HomeFragment()
    }
)

val MESSAGE_TAB = Tab(
    type = MainTab.MESSAGE,
    name = {
        getCompatString(R.string.common_main_message_tab)
    },
    icon = R.drawable.main_message_ic,
    iconSelected = R.drawable.main_message_select_ic,
    fragmentBuilder = {
        Router.getRouterInstance<BaseFragment>(IM.HomeList.PATH) ?: EmptyFragment()
    }
)

val ME_TAB = Tab(
    type = MainTab.ME,
    name = {
        getCompatString(R.string.common_main_me_tab)
    },
    icon = R.drawable.main_me_ic,
    iconSelected = R.drawable.main_me_select_ic,
    fragmentBuilder = {
        Router.getRouterInstance<BaseFragment>(Profile.Me.PATH) ?: EmptyFragment()
    }
)


val MAIN_TABS = listOf(
    HOME_TAB, MESSAGE_TAB, ME_TAB
)