package com.pan_american.android.ui.resource_management.service_resource

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.pan_american.android.OASystem
import com.pan_american.android.base.BaseFragment
import com.pan_american.android.data.model.common.entity.ServiceResourceListItem
import com.pan_american.android.data.model.common.adapter.ServiceResourceAdapter
import com.pan_american.android.databinding.FragmentServiceResourceListBinding

class ServiceResourceListFragment : BaseFragment<FragmentServiceResourceListBinding>() {

    private var listItem = ArrayList<ServiceResourceListItem>()

    override fun getViewBinding(
        inflater: LayoutInflater, container: ViewGroup?, bundle: Bundle?
    ) = FragmentServiceResourceListBinding.inflate(layoutInflater, container, false)

    override fun onStart() {
        super.onStart()

        initViews()
    }

    override fun initViews() {
        initListItem()

        initList()
    }

    private fun initListItem() {
        listItem.add(
            ServiceResourceListItem(
                "四川省成都市",
                "四川沃赛服饰有限公司",
                "行李推车",
                "18780100243",
                "782440144@qq.com"
            )
        )
        listItem.add(
            ServiceResourceListItem(
                "四川省成都市",
                "四川沃赛服饰有限公司",
                "行李推车",
                "18780100243",
                "782440144@qq.com"
            )
        )
        listItem.add(
            ServiceResourceListItem(
                "四川省成都市",
                "四川沃赛服饰有限公司",
                "行李推车",
                "18780100243",
                "782440144@qq.com"
            )
        )
        listItem.add(
            ServiceResourceListItem(
                "四川省成都市",
                "四川沃赛服饰有限公司",
                "行李推车",
                "18780100243",
                "782440144@qq.com"
            )
        )
        listItem.add(
            ServiceResourceListItem(
                "四川省成都市",
                "四川沃赛服饰有限公司",
                "行李推车",
                "18780100243",
                "782440144@qq.com"
            )
        )
    }

    private fun initList() {
        val layoutManager = LinearLayoutManager(OASystem.context)
        binding.serviceResourceList.layoutManager = layoutManager

        val adapter = ServiceResourceAdapter(listItem)
        binding.serviceResourceList.adapter = adapter

        adapter.onRecyclerViewItemClick =
            object : ServiceResourceAdapter.OnRecyclerViewItemClick<ServiceResourceListItem> {

                override fun onItemClick(position: Int) {
                    val intent = Intent(OASystem.context, AddServiceResourceActivity::class.java)
                    startActivity(intent)
                }

                override fun onItemDelete(position: Int) {
                    showMessage("Clicked Delete Button")
                }
            }

    }
}