package com.base.appzxhy.ui.main

import androidx.core.view.updatePadding
import androidx.recyclerview.widget.ConcatAdapter
import com.base.appzxhy.base.BaseFragment
import com.base.appzxhy.bean.Benefits
import com.base.appzxhy.bean.BenefitsTask
import com.base.appzxhy.bean.CheckInBean
import com.base.appzxhy.databinding.FragmentRewardsBinding
import com.base.appzxhy.ui.adapter.CheckInAdapter
import com.base.appzxhy.ui.concatAdapter.DailyBenefitsTaskAdapter
import com.base.appzxhy.ui.concatAdapter.NewUserBenefitsAdapter
import com.base.appzxhy.utils.BarUtils


class RewardsFragment : BaseFragment<FragmentRewardsBinding>(FragmentRewardsBinding::inflate) {

    private val concatAdapter: ConcatAdapter = ConcatAdapter()

    override fun initView() {
        super.initView()
        binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
        initCheckInAdapter()
        initBenefitsAdapter()
    }

    private fun initCheckInAdapter() {
        val list = listOf(
            CheckInBean(1, "Today", 10).apply { checked = true },
            CheckInBean(2, "Days2", 10).apply { checked = true },
            CheckInBean(3, "Days3", 10).apply { checked = true },
            CheckInBean(4, "Days4", 20).apply { checked = true },
            CheckInBean(5, "Days5", 25),
            CheckInBean(6, "Days6", 30),
            CheckInBean(7, "Days7", 50),
        )
        val adapter = CheckInAdapter()
        binding.rvDayCheck.adapter = adapter
        adapter.submitList(list)
    }

    private fun initBenefitsAdapter() {
        binding.rvBenefits.adapter = concatAdapter
        concatAdapter.addAdapter(NewUserBenefitsAdapter().apply {
            submitList(
                listOf(
                    Benefits(
                        "New User Benefits", task = listOf(
                            BenefitsTask("Login rewards", 50, false),
                            BenefitsTask("Add 1 series to 「My List」", 30, false),
                            BenefitsTask("Turn on notifications", 30, false),
                            BenefitsTask("Share 1 series with your friend", 30, false),
                        )
                    )
                )
            )
        })
        concatAdapter.addAdapter(DailyBenefitsTaskAdapter().apply {
            submitList(
                listOf(
                    Benefits(
                        "Today's Benefits", task = listOf(
                            BenefitsTask("Earn rewards(0/15)", 6, false),
                            BenefitsTask("Watch ads（0/7）", 10, false),
                            BenefitsTask("Watch 5 minus", 10, false),
                            BenefitsTask("Watch 10 minus", 20, false),
                            BenefitsTask("Watch 15 minus", 30, false),
                            BenefitsTask("Watch 30 minus", 60, false),
                        )
                    )
                )
            )
        })

    }

    override fun initListener() {
        super.initListener()
    }

}