package com.dahe.gldriver.ui.home

import android.graphics.Color
import android.widget.LinearLayout
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemChildClickListener
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.dahe.gldriver.R
import com.dahe.gldriver.adapter.GridItemAdapter
import com.dahe.gldriver.adapter.WaybillAdapter
import com.dahe.gldriver.bean.GridBean
import com.dahe.gldriver.databinding.FragmentHomeBinding
import com.dahe.gldriver.ui.HomeActivity
import com.dahe.gldriver.ui.waybill.activity.WaybillDetailActivity
import com.dahe.glex.bean.WayBillBean
import com.dahe.mylibrary.base.BaseFragment
import com.dahe.mylibrary.callback.RefreshCallBack
import com.dahe.mylibrary.recycleviewswipe.RecycleViewDivider
import com.dahe.mylibrary.utils.ActivityUtils
import com.dahe.mylibrary.utils.ConvertUtils
import com.dahe.mylibrary.utils.ToastUtils
import com.flyco.tablayout.listener.OnTabSelectListener
import okhttp3.internal.wait

/**
 * @ClassName HomeFragment
 * @Author 用户
 * @Date 2023/9/21 10:13
 * @Description TODO
 */
class HomeFragment : BaseFragment<FragmentHomeBinding>(), RefreshCallBack {
    private val gridDatas = mutableListOf(
        GridBean("司机之家", R.drawable.home_driver),
        GridBean("咨询客服", R.drawable.home_ask),
        GridBean("问卷调查", R.drawable.home_que),
        GridBean("知识竞赛", R.drawable.home_know),
    )

    override fun onFragmentVisibleChange(isVisible: Boolean) {
        if (isVisible) {
        }

    }

    override fun onFragmentFirstVisible() {
        initRecy()
        binding.gridView.run {
            adapter = activity?.let { GridItemAdapter(it, gridDatas) }
            setOnItemClickListener { adapterView, view, i, l ->
//                println(i)
            }
        }

        binding.tvMar.isSelected = true

    }


    override fun getRefreshDate(stat: Int, page: Int, count: Int) {

    }

    private fun initRecy() {
        var datas = mutableListOf<WayBillBean>(
            WayBillBean(),
            WayBillBean(),
            WayBillBean(),
            WayBillBean(),
            WayBillBean(),
            WayBillBean(),
            WayBillBean(),
            WayBillBean()
        )
        var adapter = binding.recyclerView.run {
            layoutManager = LinearLayoutManager(mContext, RecyclerView.VERTICAL, false)
            setHasFixedSize(true)
            addItemDecoration(
                RecycleViewDivider(
                    LinearLayout.VERTICAL,
                    ConvertUtils.dp2px(16.0f),
                    Color.TRANSPARENT
                )
            )
            adapter = WaybillAdapter()
            adapter as WaybillAdapter
        }.apply {
            setOnItemClickListener(OnItemClickListener { adapter, view, position ->
                ToastUtils.showToast(mContext,position.toString())
            })
            addChildClickViewIds(R.id.btnOk)
            setOnItemChildClickListener() { adapter, view, position ->
                ActivityUtils.startActivity(mContext,WaybillDetailActivity::class.java)
            }
        }
        adapter.addData(datas)
    }

}