package com.sambath.klaklouk_main.screen.report

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.ahmedelsayed.sunmiprinterutill.PrintMe
import com.cocking.fight.screen.dialogfragment.StatementDialogViewModel
import com.cocking.fight.screen.dialogfragment.StatementDialogViewState
import com.google.android.material.button.MaterialButton
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.textview.MaterialTextView
import com.mazenrashed.printooth.Printooth
import com.sambath.klaklouk_main.R
import com.sambath.klaklouk_main.app.App
import com.sambath.klaklouk_main.app.ShareActivity
import com.sambath.klaklouk_main.app.getErrorCode
import com.sambath.klaklouk_main.base.BaseFragment
import com.sambath.klaklouk_main.extension.btnClick
import com.sambath.klaklouk_main.remote.*
import com.sambath.klaklouk_main.screen.main.cflive.statement.report.ReportAdapter
import com.sambath.klaklouk_main.screen.main.cflive.statement.report.Type
import com.sambath.klaklouk_main.util.Const
import com.sambath.klaklouk_main.util.ModelPreferencesManager
import com.sambath.klaklouk_main.util.PrefHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.fragment_statement.*
import timber.log.Timber
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.TimeUnit

class StatementFragment : BaseFragment(R.layout.fragment_statement) {
    private lateinit var adapterDep: ReportAdapter
    private lateinit var adapterWith: ReportAdapter
    private lateinit var adapterTb1: ReportAdapter
    private lateinit var adapterTb2: ReportAdapter
    private lateinit var adapterTb3: ReportAdapter
    private lateinit var rvTabDeposit: RecyclerView
    private lateinit var rvTabWithdraw: RecyclerView
    private lateinit var rvTab1: RecyclerView
    private lateinit var rvTab2: RecyclerView
    private lateinit var rvTab3: RecyclerView
    private lateinit var user: User
    private lateinit var layoutManagerDep: LinearLayoutManager
    private lateinit var layoutManagerWit: LinearLayoutManager
    private lateinit var layoutManager1: LinearLayoutManager
    private lateinit var layoutManager2: LinearLayoutManager
    private lateinit var linTabDeposit: LinearLayoutCompat
    private lateinit var linTabWithdraw: LinearLayoutCompat
    private lateinit var linTab1: LinearLayoutCompat
    private lateinit var linTab2: LinearLayoutCompat
    private lateinit var linTab3: LinearLayoutCompat
    private lateinit var mtxtStatementTurnOver: MaterialTextView
    private lateinit var mtxtStatementWinLose: MaterialTextView
    private lateinit var mtxtStatementStartDate: MaterialTextView
    private lateinit var mtxtStatementEndDate: MaterialTextView
    private lateinit var linStatementDate: LinearLayoutCompat
    private lateinit var mtxtResultStartDate: MaterialTextView
    private lateinit var mtxtResultEndDate: MaterialTextView
    private lateinit var linResultDate: LinearLayoutCompat
    private var statementStartDate: String = ""
    private var statementEndDate: String = ""
    private var resultStartDate: String = ""
    private var resultEndDate: String = ""
    private var depositStartDate: String = ""
    private var depositEndDate: String = ""
    private var withdrawStartDate: String = ""
    private var withdrawEndDate: String = ""

    private var pageDeposit: Int = 1
    private var totalPageDeposit: Int = 1
    private var totalRecordDeposit: Int = 0
    private var isLoadingDeposit: Boolean = false
    private var pageWithdraw: Int = 1
    private var totalPageWithdraw: Int = 1
    private var totalRecordWithdraw: Int = 0
    private var isLoadingWithdraw: Boolean = false
    private var pageOne: Int = 1
    private var totalPageOne: Int = 1
    private var totalRecordOne: Int = 0
    private var isLoadingOne: Boolean = false
    private var pageTwo: Int = 1
    private var totalPageTwo: Int = 1
    private var totalRecordTwo: Int = 0
    private val rowPerPage: Int = 50
    private var isLoadingTwo: Boolean = false
    private var listDeposit: List<ReportDeposit> = arrayListOf()
    private var listWithdraw: List<ReportWithdraw> = arrayListOf()
    private var listOne: List<ReportOne> = arrayListOf()
    private var listTwo: List<ReportTwo> = arrayListOf()
    private val apiService = App.injectApiService()
    private lateinit var currency: String
    private lateinit var sharePref: PrefHelper
    private lateinit var btnClose: MaterialButton
    private lateinit var printMe: PrintMe
    private lateinit var statementDialogViewModel: StatementDialogViewModel
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        sharePref = App.injectPrefHelper()
        user = ModelPreferencesManager.getUser(Const.USER_KEY)!!
        statementDialogViewModel =
            StatementDialogViewModel(App.injectApiService(), App.injectPrefHelper())
        (requireActivity() as ShareActivity).apply {
            user = userShare
        }
        when (user.currencyType) {
            1 -> {//dollar
                currency = "$"
            }
            2 -> {//riel
                currency = "៛"
            }
            3 -> {//baht
                currency = "฿"
            }
        }
        printMe = PrintMe(context)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        (requireActivity() as? ShareActivity)?.apply {
            groupToolbarIcons.isVisible = false
            layCfStatus.isVisible = false
            btnClose = view.findViewById<MaterialButton>(R.id.btn_close)
            btnClose.setOnClickListener {
                it.btnClick().subscribe {
                    onBackPressed()
                }
            }
        }
        tvDepAmount.text = "Amount ($currency)"
        tvWithAmount.text = "Amount ($currency)"
        tvReportAmount.text = "Amount ($currency)"
        tvStatementAmount.text = "Amount ($currency)"
        linTabDeposit = view.findViewById(R.id.lin_tab_deposit)
        linTabWithdraw = view.findViewById(R.id.lin_tab_withdraw)
        linTab1 = view.findViewById(R.id.lin_tab_1)
        linTab2 = view.findViewById(R.id.lin_tab_2)
        linTab3 = view.findViewById(R.id.lin_tab_3)
        rvTabDeposit = view.findViewById(R.id.rv_tb_deposit)
        rvTabWithdraw = view.findViewById(R.id.rv_tb_withdraw)
        rvTab1 = view.findViewById(R.id.rv_tb1)
        rvTab2 = view.findViewById(R.id.rv_tb2)
        rvTab3 = view.findViewById(R.id.rv_tb3)
        mtxtStatementTurnOver = view.findViewById(R.id.mtxt_statement_turnover)
        mtxtStatementWinLose = view.findViewById(R.id.mtxt_statement_winlose)
        mtxtStatementStartDate = view.findViewById(R.id.mtxt_statement_start_date)
        mtxtStatementEndDate = view.findViewById(R.id.mtxt_statement_end_date)
        linStatementDate = view.findViewById(R.id.lin_statement_date)

        mtxtResultStartDate = view.findViewById(R.id.mtxt_result_start_date)
        mtxtResultEndDate = view.findViewById(R.id.mtxt_result_end_date)
        linResultDate = view.findViewById(R.id.lin_result_date)

        linMainTabDeposit.setOnClickListener {
            bg_select_deposit.visibility = View.VISIBLE
            bg_select_withdraw.visibility = View.INVISIBLE
            bg_select_tab1.visibility = View.INVISIBLE
            bg_select_tab2.visibility = View.INVISIBLE
            bg_select_tab3.visibility = View.INVISIBLE

            linTabDeposit.visibility = View.VISIBLE
            linTabWithdraw.visibility = View.GONE
            linTab1.visibility = View.GONE
            linTab2.visibility = View.GONE
            linTab3.visibility = View.GONE
        }
        linMainTabWithdraw.setOnClickListener {
            bg_select_deposit.visibility = View.INVISIBLE
            bg_select_withdraw.visibility = View.VISIBLE
            bg_select_tab1.visibility = View.INVISIBLE
            bg_select_tab2.visibility = View.INVISIBLE
            bg_select_tab3.visibility = View.INVISIBLE

            linTabDeposit.visibility = View.GONE
            linTabWithdraw.visibility = View.VISIBLE
            linTab1.visibility = View.GONE
            linTab2.visibility = View.GONE
            linTab3.visibility = View.GONE
        }
        linTabMainStatement.setOnClickListener {
            bg_select_deposit.visibility = View.INVISIBLE
            bg_select_withdraw.visibility = View.INVISIBLE
            bg_select_tab1.visibility = View.VISIBLE
            bg_select_tab2.visibility = View.INVISIBLE
            bg_select_tab3.visibility = View.INVISIBLE

            linTabDeposit.visibility = View.GONE
            linTabWithdraw.visibility = View.GONE
            linTab1.visibility = View.VISIBLE
            linTab2.visibility = View.GONE
            linTab3.visibility = View.GONE
        }
        linTabResult.setOnClickListener {
            bg_select_deposit.visibility = View.INVISIBLE
            bg_select_withdraw.visibility = View.INVISIBLE
            bg_select_tab1.visibility = View.INVISIBLE
            bg_select_tab2.visibility = View.VISIBLE
            bg_select_tab3.visibility = View.INVISIBLE

            linTabDeposit.visibility = View.GONE
            linTabWithdraw.visibility = View.GONE
            linTab1.visibility = View.GONE
            linTab2.visibility = View.VISIBLE
            linTab3.visibility = View.GONE
        }
        init()
        exDeposit(ReportBody(rowPerPage, pageDeposit, "", ""))
        exWithdraw(ReportBody(rowPerPage, pageWithdraw, "", ""))
        exOne(ReportBody(rowPerPage, pageOne, "", ""))
        exTwo(ReportBody(rowPerPage, pageTwo, "", ""))

        rvTab1.addOnScrollListener(object : RecyclerView.OnScrollListener() {
            override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
                val total: Int = adapterTb1.itemCount
                if (!isLoadingOne) {
                    if (total < totalRecordOne) {
//                        Log.d("getReport", "itemCount1 :: " + total)
                        exOne(ReportBody(rowPerPage, pageOne, statementStartDate, statementEndDate))
                    }
                }
                super.onScrolled(recyclerView, dx, dy)
            }
        })
        rvTab2.addOnScrollListener(object : RecyclerView.OnScrollListener() {
            override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
                val visibleItemCount: Int = layoutManager2.childCount
                val pastVisibleItem: Int = layoutManager2.findFirstCompletelyVisibleItemPosition()
                val total: Int = adapterTb2.itemCount
                if (!isLoadingTwo) {
//                    Log.d("getReport", "total :: plus " + total + " :: " + totalRecordTwo)
                    if (total < totalRecordTwo) {
//                        Log.d("getReport", "itemCount2 :: " + total)
                        exTwo(ReportBody(rowPerPage, pageTwo, resultStartDate, resultEndDate))
                    }
                }
                super.onScrolled(recyclerView, dx, dy)
            }
        })
        val now = Calendar.getInstance()
        val statementBuilder = MaterialDatePicker.Builder.dateRangePicker()
        statementBuilder.setSelection(androidx.core.util.Pair(now.timeInMillis, now.timeInMillis))
        val statementPicker = statementBuilder.build()
        linStatementDate.setOnClickListener {
            statementPicker.show(activity?.supportFragmentManager!!, statementPicker.toString())
        }
        statementPicker.addOnPositiveButtonClickListener {
            statementStartDate = getDate(it.first)
            statementEndDate = getDate(it.second)
            listOne = emptyList()
            pageOne = 1
            exOne(ReportBody(rowPerPage, pageOne, statementStartDate, statementEndDate))
            mtxtStatementStartDate.text = statementStartDate
            mtxtStatementEndDate.text = statementEndDate
            Timber.i("The selected date range is ${getDate(it.first)} - ${getDate(it.second)}")
        }
        imgStatementClear.setOnClickListener {
            statementStartDate = ""
            statementEndDate = ""
            mtxtStatementStartDate.text = statementStartDate
            mtxtStatementEndDate.text = statementEndDate
            listOne = emptyList()
            pageOne = 1
            exOne(ReportBody(rowPerPage, pageOne, statementStartDate, statementEndDate))
        }

        val resultBuilder = MaterialDatePicker.Builder.dateRangePicker()
        resultBuilder.setSelection(androidx.core.util.Pair(now.timeInMillis, now.timeInMillis))
        val resultPicker = resultBuilder.build()
        linResultDate.setOnClickListener {
            resultPicker.show(activity?.supportFragmentManager!!, statementPicker.toString())
        }
        resultPicker.addOnPositiveButtonClickListener {
            resultStartDate = getDate(it.first)
            resultEndDate = getDate(it.second)
            listTwo = emptyList()
            pageTwo = 1
            exTwo(ReportBody(rowPerPage, pageTwo, resultStartDate, resultEndDate))
            mtxtResultStartDate.text = resultStartDate
            mtxtResultEndDate.text = resultEndDate
            Timber.i("The selected date range is ${getDate(it.first)} - ${getDate(it.second)}")
        }
        imgResultClear.setOnClickListener {
            resultStartDate = ""
            resultEndDate = ""
            mtxtResultStartDate.text = resultStartDate
            mtxtResultEndDate.text = resultEndDate
            listTwo = emptyList()
            pageTwo = 1
            exTwo(ReportBody(rowPerPage, pageTwo, resultStartDate, resultEndDate))
        }

        val depositBuilder = MaterialDatePicker.Builder.dateRangePicker()
        depositBuilder.setSelection(androidx.core.util.Pair(now.timeInMillis, now.timeInMillis))
        val depositPicker = resultBuilder.build()
        linDepositDate.setOnClickListener {
            depositPicker.show(activity?.supportFragmentManager!!, depositPicker.toString())
        }
        depositPicker.addOnPositiveButtonClickListener {
            depositStartDate = getDate(it.first)
            depositEndDate = getDate(it.second)
            listDeposit = emptyList()
            pageDeposit = 1
            exDeposit(ReportBody(rowPerPage, pageDeposit, depositStartDate, depositEndDate))
            mtxtDepositStartDate.text = depositStartDate
            mtxtDepositEndDate.text = depositEndDate
            Timber.i("The selected date range is ${getDate(it.first)} - ${getDate(it.second)}")
        }
        imgDepositClear.setOnClickListener {
            depositStartDate = ""
            depositEndDate = ""
            mtxtDepositStartDate.text = depositStartDate
            mtxtDepositEndDate.text = depositEndDate
            listDeposit = emptyList()
            pageDeposit = 1
            exDeposit(ReportBody(rowPerPage, pageDeposit, depositStartDate, depositEndDate))
        }

        val withdrawBuilder = MaterialDatePicker.Builder.dateRangePicker()
        withdrawBuilder.setSelection(androidx.core.util.Pair(now.timeInMillis, now.timeInMillis))
        val withdrawPicker = resultBuilder.build()
        linWithdrawDate.setOnClickListener {
            withdrawPicker.show(activity?.supportFragmentManager!!, withdrawPicker.toString())
        }
        withdrawPicker.addOnPositiveButtonClickListener {
            withdrawStartDate = getDate(it.first)
            withdrawEndDate = getDate(it.second)
            listWithdraw = emptyList()
            pageWithdraw = 1
            exWithdraw(ReportBody(rowPerPage, pageWithdraw, withdrawStartDate, withdrawEndDate))
            mtxtWithdrawStartDate.text = withdrawStartDate
            mtxtWithdrawEndDate.text = withdrawEndDate
            Timber.i("The selected date range is ${getDate(it.first)} - ${getDate(it.second)}")
        }
        imgWithdrawClear.setOnClickListener {
            withdrawStartDate = ""
            withdrawEndDate = ""
            mtxtWithdrawStartDate.text = withdrawStartDate
            mtxtWithdrawEndDate.text = withdrawEndDate
            listWithdraw = emptyList()
            pageWithdraw = 1
            exWithdraw(ReportBody(rowPerPage, pageWithdraw, withdrawStartDate, withdrawEndDate))
        }
    }
    private fun getDate(millisecond: Long): String {
        val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.US)
//        val dateString: String = simpleDateFormat.format(millisecond)
        return simpleDateFormat.format(millisecond)
    }
    private fun getReportThree(data: StatementDialogViewState) {
        if (data.reportThreeList != null) {
            progress.isVisible = false
//            Log.d("getReport", "3 :: " + data.reportThreeList!!.size)
            adapterTb3.submitList(data.reportThreeList)
        }
    }

    private fun exOne(reportBetting: ReportBody) {
        Log.d("getReport", "load listOne")
        isLoadingOne = true
        pageOne++
        val disposables = CompositeDisposable()
        disposables.add(
            apiService.getReportOne(reportBetting)
                .timeout(60, TimeUnit.SECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    progress.isVisible = false
                    if (it.resultCode == "1") {
                        mtxtStatementWinLose.text = currencyFormat(it.data.amountWinLose) + "$currency"
                        mtxtStatementTurnOver.text = currencyFormat(it.data.turnOver) + "$currency"
                        totalPageOne = it.data.totalPages
                        totalRecordOne = it.data.totalRows
                        val li: List<ReportOne> = it.data.reports
                        listOne = concatenate(listOne, li)
                        Log.d("getReport", "listOne :: " + listOne.size)
                        adapterTb1.submitList(listOne)
                        isLoadingOne = false
                    } else {
                        isLoadingOne = false
                        val message: String = "ប្រតិបត្តិការមិនជោគជ័យ\n" + it.message.description
                    }
                }, {
                    progress.isVisible = false
                    isLoadingOne = false
                    val message: String = "ប្រតិបត្តិការមិនជោគជ័យ\n" + it.getErrorCode()
                })
        )
    }

    private fun exTwo(reportResult: ReportBody) {
        Log.d("getReport", "load listTwo")
        isLoadingTwo = true
        pageTwo++
        val disposables = CompositeDisposable()
        disposables.add(
            apiService.getReportTwo(reportResult)
                .timeout(60, TimeUnit.SECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    progress.isVisible = false
                    if (it.resultCode == "1") {
                        totalPageTwo = it.data.totalPages
                        totalRecordTwo = it.data.totalRows
                        val li: List<ReportTwo> = it.data.results
                        Log.d("getReport", "listTwo :: " + listTwo.size)
                        listTwo = concatenate(listTwo, li)
                        adapterTb2.submitList(listTwo)
                        isLoadingTwo = false
                    } else {
                        val message: String = "ប្រតិបត្តិការមិនជោគជ័យ\n" + it.message.description
                    }
                }, {
                    progress.isVisible = false
                    val message: String = "ប្រតិបត្តិការមិនជោគជ័យ\n" + it.getErrorCode()
                })
        )
    }

    private fun exDeposit(reportResult: ReportBody) {
        isLoadingDeposit = true
        pageDeposit++
        val disposables = CompositeDisposable()
        disposables.add(
            apiService.getReportDeposit(reportResult)
                .timeout(60, TimeUnit.SECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    progress.isVisible = false
                    if (it.resultCode == "1") {
                        tvDepTurnOver.text = currencyFormat(it.data.totalAmount) + "$currency"
                        totalPageDeposit = it.data.totalPages
                        totalRecordDeposit = it.data.totalRows
                        val li: List<ReportDeposit> = it.data.reports
                        listDeposit = concatenate(listDeposit, li)
                        adapterDep.submitList(listDeposit)
                        isLoadingDeposit = false
                    } else {
                        val message: String = "ប្រតិបត្តិការមិនជោគជ័យ\n" + it.message.description
                    }
                }, {
                    progress.isVisible = false
                    val message: String = "ប្រតិបត្តិការមិនជោគជ័យ\n" + it.getErrorCode()
                })
        )
    }

    private fun exWithdraw(reportResult: ReportBody) {
        isLoadingWithdraw = true
        pageWithdraw++
        val disposables = CompositeDisposable()
        disposables.add(
            apiService.getReportWithdraw(reportResult)
                .timeout(60, TimeUnit.SECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    progress.isVisible = false
                    if (it.resultCode == "1") {
                        tvWithTurnOver.text = currencyFormat(it.data.totalAmount) + "$currency"
                        totalPageWithdraw = it.data.totalPages
                        totalRecordWithdraw = it.data.totalRows
                        val li: List<ReportWithdraw> = it.data.reports
                        listWithdraw = concatenate(listWithdraw, li)
                        adapterWith.submitList(listWithdraw)
                        isLoadingWithdraw = false
                    } else {
                        val message: String = "ប្រតិបត្តិការមិនជោគជ័យ\n" + it.message.description
                    }
                }, {
                    progress.isVisible = false
                    val message: String = "ប្រតិបត្តិការមិនជោគជ័យ\n" + it.getErrorCode()
                })
        )
    }

    fun init() {
        adapterDep = ReportAdapter(Type.DEPOSIT)
        rvTabDeposit.setHasFixedSize(true)
        layoutManagerDep = LinearLayoutManager(context)
        rvTabDeposit.layoutManager = layoutManagerDep
        rvTabDeposit.adapter = adapterDep

        adapterWith = ReportAdapter(Type.DEPOSIT)
        rvTabWithdraw.setHasFixedSize(true)
        layoutManagerWit = LinearLayoutManager(context)
        rvTabWithdraw.layoutManager = layoutManagerWit
        rvTabWithdraw.adapter = adapterWith

        adapterTb1 = ReportAdapter(Type.WIN)
        rvTab1.setHasFixedSize(true)
        layoutManager1 = LinearLayoutManager(context)
        rvTab1.layoutManager = layoutManager1
        rvTab1.adapter = adapterTb1
        adapterTb1.printButtonListener = { reportOne: ReportOne ->
            if(Printooth.hasPairedPrinter()){
                printSBCPrintable(reportOne, user.currencyType, sharePref.getChannelType())
            }else{
                val views = layoutInflater.inflate(R.layout.report_print, null)
                views.findViewById<MaterialTextView>(R.id.title).text = reportOne.betName
                views.findViewById<MaterialTextView>(R.id.channel).text =
                    sharePref.getChannelType().toString()
                views.findViewById<MaterialTextView>(R.id.betId).text =
                    getLastFourChars(reportOne._id, 4)
                views.findViewById<MaterialTextView>(R.id.fightNo).text = reportOne.fightNo.toString()
                views.findViewById<MaterialTextView>(R.id.betType).text = reportOne.betName
                views.findViewById<MaterialTextView>(R.id.date).text = reportOne.date
                views.findViewById<MaterialTextView>(R.id.amount).text = reportOne.amount.toString()
                views.findViewById<MaterialTextView>(R.id.payout).text = reportOne.payout
                views.findViewById<MaterialTextView>(R.id.currencyType).text = currency
                views.findViewById<MaterialTextView>(R.id.result).text = reportOne.resultName
                if (reportOne.cast.isNullOrEmpty()) {
                    views.findViewById<MaterialTextView>(R.id.cast).text = reportOne.amount.toString()
                } else {
                    views.findViewById<MaterialTextView>(R.id.cast).text = reportOne.cast.toString()
                }
                if (reportOne.amountWin.isNullOrEmpty()) {
                    views.findViewById<MaterialTextView>(R.id.amountWin).text = "0"
                } else {
                    views.findViewById<MaterialTextView>(R.id.amountWin).text =
                        reportOne.amountWin.toString()
                }
                views.findViewById<MaterialTextView>(R.id.winLose).text = reportOne.is_win?.let {
                    getWinLose(
                        it
                    )
                }
                printMe.sendViewToPrinter(views)
            }
        }

        adapterTb2 = ReportAdapter(Type.WIN_LOST)
        rvTab2.setHasFixedSize(true)
        layoutManager2 = LinearLayoutManager(context)
        rvTab2.layoutManager = layoutManager2
        rvTab2.adapter = adapterTb2

        adapterTb3 = ReportAdapter(Type.STATEMENT)
        rvTab3.setHasFixedSize(true)
        rvTab3.layoutManager = LinearLayoutManager(context)
        rvTab3.adapter = adapterTb3
    }

    //    private fun getLastFourChars(str: String, n: Int): String {
//                var lastChars = str
//        if (lastChars.length > n) {
//            lastChars = lastChars.substring(lastChars.length - n, lastChars.length)
//        }
//        return lastChars
//    }
    private fun getWinLose(isWin: Boolean): String {
        return if (isWin) {
            "WIN"
        } else {
            "LOSE"
        }
    }

    private fun <T> concatenate(vararg lists: List<T>): List<T> {
        return listOf(*lists).flatten()
    }
}
