package com.quansu.heifengwuliu.activity

import android.graphics.Color
import android.graphics.Typeface
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.PagerAdapter
import com.qmuiteam.qmui.util.QMUIDisplayHelper
import com.qmuiteam.qmui.widget.tab.QMUITabIndicator
import com.quansu.heifengwuliu.R
import com.quansu.heifengwuliu.base.MBActivity
import com.quansu.heifengwuliu.databinding.ActivityAccountBinding
import com.quansu.heifengwuliu.fragment.AccountAnalysisFragment
import com.quansu.heifengwuliu.fragment.AccountBillFragment
import com.ysnows.base.base.BRepository
import com.ysnows.base.base.BViewModel

class AccountActivity : MBActivity<BViewModel<BRepository>, ActivityAccountBinding>() {

    override fun initView(view: View?) {
        super.initView(view)

        initTabs()
        initPager()
    }

    private fun initPager() {
        val mPagerAdapter: PagerAdapter = object : FragmentPagerAdapter(supportFragmentManager) {
            override fun getItem(position: Int): Fragment {
                return if (position == 1) {
                    AccountAnalysisFragment()
                } else AccountBillFragment()
            }

            override fun getCount(): Int {
                return 2
            }
        }
        binding.pager.adapter = mPagerAdapter
        binding.tabs.setupWithViewPager(binding.pager, false)
    }


    private fun initTabs() {
        binding.tabs.setIndicator(QMUITabIndicator(QMUIDisplayHelper.dp2px(context(), 3), false, true))
        val builder = binding.tabs.tabBuilder()
        builder
                .skinChangeWithTintColor(false)
                .setSelectColor(Color.parseColor("#2E4E71"))
                .setNormalColor(Color.parseColor("#666666"))
                .setTypeface(Typeface.DEFAULT_BOLD, Typeface.DEFAULT_BOLD)
                .setDynamicChangeIconColor(false)
        val component = builder
                .setText(getString(R.string.bill))
                .build(context())
        val util = builder
                .setText(getText(R.string.analysis))
                .build(context())
        binding.tabs
                .addTab(component)
                .addTab(util)
    }


    override fun binding(): ActivityAccountBinding {
        return ActivityAccountBinding.inflate(layoutInflater)
    }


    override fun title(): String? {
        return getString(R.string.my_account)
    }
}