package com.sixin.module_p.ui.zuzhuang

import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.content.res.Resources
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.base.CommonAdapter
import com.lukouguoji.module_base.interfaces.IOnItemClickListener
import com.lukouguoji.module_base.ktx.addOnItemClickListener
import com.lukouguoji.module_base.ktx.commonAdapter
import com.lukouguoji.module_base.ktx.refresh
import com.lukouguoji.module_base.util.Common
import com.sixin.module_p.R
import com.sixin.module_p.base.BasePdaActivity
import com.sixin.module_p.databinding.ActivityPdaZuZhuangBinding
import com.sixin.module_p.helper.PDAHelper
import com.sixin.module_p.ui.zuzhuang.holder.PdaZuZhuangViewHolder
import dev.DevUtils
import dev.utils.app.HandlerUtils
import me.jessyan.autosize.AutoSizeCompat
import me.jessyan.autosize.internal.CustomAdapt

class PdaZuZhuangActivity :
    BasePdaActivity<ActivityPdaZuZhuangBinding, PdaZuZhuangViewModel>(),
    CustomAdapt {

    override fun layoutId() = R.layout.activity_pda_zu_zhuang

    override fun viewModelClass(): Class<PdaZuZhuangViewModel> {
        return PdaZuZhuangViewModel::class.java
    }

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("国际出港开始组装")
        viewModel.init()
        binding.viewModel = viewModel

        binding.rv.adapter = CommonAdapter(
            requireContext(),
            R.layout.item_pda_zu_zhuang,
            PdaZuZhuangViewHolder::class.java
        )
        viewModel.pageModel.rv = binding.rv

        binding.rv.addOnItemClickListener(object : IOnItemClickListener {
            override fun onItemClick(position: Int, type: Int) {
                Common.secondConfirmDialog(
                    DevUtils.getTopActivity(),
                    "是否确认删除该条信息?"
                ) { dialog ->
                    binding.rv.commonAdapter()!!.removeItem(position)
                    dialog.dismiss()
                    viewModel.computeTotal()
                }
            }
        })
    }

    override fun isBaseOnWidth() = true

    override fun getSizeInDp(): Float = PDAHelper.PDA_WIDTH

    companion object {
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, PdaZuZhuangActivity::class.java)
            context.startActivity(starter)
        }
    }
}