package com.quansu.heifengwuliu.fragment

import android.graphics.Color
import android.graphics.Typeface
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
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.MBFragment
import com.quansu.heifengwuliu.databinding.FragmentWaybillBinding
import com.ysnows.base.base.BRepository
import com.ysnows.base.base.BViewModel

/**
 *Created by shihuiyun
 *on 2020/9/9
 */
class WayBillFragment : MBFragment<BViewModel<BRepository>, FragmentWaybillBinding>() {

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

        titleBar?.tvRight?.text = getString(R.string.filter)

        initTabs()
        initPager()

    }

    private fun initPager() {
        val mPagerAdapter: PagerAdapter = object : FragmentPagerAdapter(childFragmentManager) {
            override fun getItem(position: Int): Fragment {
                return OrderListFragment()
            }

            override fun getCount(): Int {
                return 5
            }
        }
        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.all))
                .build(context())

        val util = builder
                .setText(getText(R.string.to_order_receive))
                .build(context())

        val ongoing = builder
                .setText(getText(R.string.on_going))
                .build(context())

        val canceled = builder
                .setText(getText(R.string.canceled))
                .build(context())

        val completed = builder
                .setText(getText(R.string.completed))
                .build(context())


        binding.tabs
                .addTab(component)
                .addTab(util)
                .addTab(ongoing)
                .addTab(canceled)
                .addTab(completed)
    }


    override fun binding(inflater: LayoutInflater, container: ViewGroup?): FragmentWaybillBinding {
        return FragmentWaybillBinding.inflate(layoutInflater)
    }

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

    override fun backable(): Boolean {
        return false
    }
}
