package com.casic.br.view.device

import android.content.Context
import android.graphics.Typeface
import android.view.LayoutInflater
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.casic.br.R
import com.casic.br.adapter.TabPagerAdapter
import com.casic.br.extensions.initLayoutImmersionBar
import com.casic.br.fragment.waterheater.ControlPageFragment
import com.casic.br.fragment.waterheater.ServicePageFragment
import com.casic.br.fragment.waterheater.StatusPageFragment
import com.google.android.material.tabs.TabLayout
import com.gyf.immersionbar.ImmersionBar
import com.pengxh.kt.lite.base.KotlinBaseActivity
import com.pengxh.kt.lite.utils.Constant
import kotlinx.android.synthetic.main.activity_water_heater.*
import kotlinx.android.synthetic.main.include_device_title.*
import java.util.*


/**
 * 热水器
 * */
class WaterHeaterActivity : KotlinBaseActivity() {

    private val context: Context = this@WaterHeaterActivity
    private val inflater by lazy { LayoutInflater.from(this) }
    private val deviceSegmentTitle = arrayOf("设备控制", "状态显示", "服务设置")
    private var fragmentPages: ArrayList<Fragment> = ArrayList()

    init {
        fragmentPages.add(ControlPageFragment())
        fragmentPages.add(StatusPageFragment())
        fragmentPages.add(ServicePageFragment())
    }

    override fun initLayoutView(): Int = R.layout.activity_water_heater

    override fun setupTopBarLayout() {
        initLayoutImmersionBar(rootView)
        ImmersionBar.with(this).statusBarDarkFont(true).init()

        leftBackView.setOnClickListener { finish() }
        titleView.text = intent.getStringExtra(Constant.INTENT_PARAM)
    }

    override fun initData() {

    }

    override fun observeRequestState() {

    }

    override fun initEvent() {
        rightOperateView.setOnClickListener {

        }

        deviceViewPager.adapter =
            TabPagerAdapter(fragmentPages, deviceSegmentTitle, supportFragmentManager)
        deviceTabLayout.setupWithViewPager(deviceViewPager)
        deviceTabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: TabLayout.Tab?) {
                val textView = inflater.inflate(R.layout.item_top_tab, null) as TextView
                textView.textSize = 16f
                textView.typeface = Typeface.DEFAULT_BOLD
                textView.text = tab!!.text
                tab.customView = textView
            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {
                tab?.customView = null
            }

            override fun onTabReselected(tab: TabLayout.Tab?) {

            }
        })
    }
}