package com.sinata.bc_chat.utils;

import android.support.v4.app.Fragment;

import com.alibaba.android.arouter.core.LogisticsCenter;
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bc_chat.bc_base.config.RouteConfig;
import com.sinata.bc_chat.R;
import com.sinata.bc_chat.fragment.Nav1Fragment;
import com.sinata.bc_chat.fragment.Nav2Fragment;

/**
 * author：Created by zhaohaoting on 2019/2/20
 * email：526309416@qq.com
 * desc：
 */
public enum MainTab {

    CHAT(ReminderId.CHAT, "消息", R.drawable.tab_icon_chat, getFragmentClass(RouteConfig.CHAT_FRAGMENT)),

    CONTACT(ReminderId.CONTACT, "联系人", R.drawable.tab_icon_contact, getFragmentClass(RouteConfig.CONTACTS_FRAGMENT)),

    NAV1(ReminderId.NAV1, "百度", R.drawable.tab_icon_score, Nav1Fragment.class),

    NAV2(ReminderId.NAV2, "百度", R.drawable.tab_icon_score, Nav2Fragment.class),

    MINE(ReminderId.MINE, "我的", R.drawable.tab_icon_mine, getFragmentClass(RouteConfig.MINE_FRAGMENT));

    private int reminderId;
    private String resName;
    private int resIcon;
    private Class<?> clz;

    MainTab(int reminderId, String resName, int resIcon, Class<? extends Fragment> clz) {
        this.reminderId = reminderId;
        this.resName = resName;
        this.resIcon = resIcon;
        this.clz = clz;
    }

    public int getReminderId() {
        return reminderId;
    }

    public String getResName() {
        return resName;
    }

    public void setResName(String resName) {
        this.resName = resName;
    }

    public int getResIcon() {
        return resIcon;
    }

    public Class<?> getClz() {
        return clz;
    }

    public static MainTab fromReminderId(int reminderId) {
        for (MainTab value : MainTab.values()) {
            if (value.reminderId == reminderId) {
                return value;
            }
        }
        return null;
    }

    public static Class getFragmentClass(String routerPath) {
        Postcard postcard = ARouter.getInstance().build(routerPath);
        LogisticsCenter.completion(postcard);
        return postcard.getDestination();
    }

}
