package com.ama.core.architecture.appBase.adapter

import android.content.Context
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView


abstract class AppNavigatorAdapter<T> : CommonNavigatorAdapter() {
    private var dataList: List<T> = emptyList()

    override fun getCount(): Int {
        return dataList.size
    }

    override fun getTitleView(context: Context, index: Int): IPagerTitleView? {
        return getTabView(context, index, dataList[index])
    }

    abstract fun getTabView(context: Context, index: Int, item: T): IPagerTitleView?

    override fun getIndicator(context: Context): IPagerIndicator? = null

    fun submitList(list: List<T>?) {
        if (dataList == list) return
        dataList = list ?: emptyList()
        notifyDataSetChanged()
    }

    fun getItem(index: Int) = if (index < dataList.size) dataList[index] else null
}