package com.zxbw.modulemain.fragment

import android.graphics.Color
import android.view.View
import androidx.core.content.ContextCompat
import com.loper7.tab_expand.ext.buildIndicator
import com.loper7.tab_expand.ext.buildText
import com.loper7.tab_expand.ext.toPx
import com.loper7.tab_expand.indicator.CustomIndicator
import com.loper7.tab_expand.text.BaseText
import com.zxbw.modulemain.R
import com.zxbw.modulemain.contract.ShoppingMallContract
import com.zxbw.modulemain.presenter.ShoppingMallPresenter
import com.zxhl.cms.common.FragmentAdapter
import com.zxhl.cms.common.base.BaseFragment
import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.model.box.TabEntity
import com.zxhl.cms.net.model.qy.CouponsEntity
import com.zxhl.cms.utils.JumpUtils
import kotlinx.android.synthetic.main.fragment_layout_shoppimg_mall.*
import me.jessyan.autosize.utils.ScreenUtils

/**
 * @author (wangXuewei)
 * @datetime 2022-08-05 13:39 GMT+8
 * @detail :
 */
class ShoppingMallFragment : BaseFragment(), ShoppingMallContract.View {
    override fun layoutID(): Int = R.layout.fragment_layout_shoppimg_mall

    private var mPresenter: ShoppingMallPresenter? = null

    override fun init(view: View?) {
        var statusBarHeight = ScreenUtils.getStatusBarHeight()
        if (statusBarHeight <= 0) {
            statusBarHeight = 40;
        }
        id_sys_bar_view.layoutParams.height = statusBarHeight

        mPresenter = ShoppingMallPresenter(this)

        id_ll_search_view.setOnClickListener {
            JumpUtils.SearchJump()
        }
        id_img_kefu.setOnClickListener {
            JumpUtils.UserQuestion()
        }

        val config = SettingPreference.getConfig();
        if (config != null && !config.tabs.isNullOrEmpty()) {
            setTabList(config.tabs!!)
        }
    }

    override fun setTabList(result: List<TabEntity>?) {
        if (result.isNullOrEmpty()) {
            showToast("加载失败，请重试")
            return
        }
        val adapter = FragmentAdapter(childFragmentManager)
        for (i in 0 until (result.size)) {
            val title = result[i].name
            adapter.addFrag(ShopRecommendFragment.newInstance(result[i]), title)
        }
        shop_viewPager?.adapter = adapter
        id_tab_shop?.setupWithViewPager(shop_viewPager)
        id_tab_shop?.overScrollMode = View.OVER_SCROLL_NEVER


        id_tab_shop.buildText<BaseText>()
            .setNormalTextBold(false)
            .setNormalTextSize(20f)
            .setSelectTextSize(22f)
            .setSelectTextBold(true).bind()

    }

    override fun setCouponsList(result: List<CouponsEntity>?) {

    }
}