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

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.pan_american.android.OASystem
import com.pan_american.android.base.BaseActivity
import com.pan_american.android.databinding.ActivityServiceResourceBinding
import com.pan_american.android.databinding.LayoutTitleBinding

class ServiceResourceActivity : BaseActivity<ActivityServiceResourceBinding>() {

    private lateinit var titleBinding: LayoutTitleBinding

    override fun getViewBinding() = ActivityServiceResourceBinding.inflate(layoutInflater)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        initTitle()
        initViews()
    }

    override fun initTitle() {
        titleBinding = LayoutTitleBinding.bind(binding.root).apply {
            titleText.text = "会务活动供应商资源"

            if (OASystem.authorization(OASystem.INVITE_DATA, OASystem.ADD)) {
                addButton.apply {

                    visibility = View.VISIBLE

                    setOnClickListener {
                        val intent = Intent(OASystem.context, AddServiceResourceActivity::class.java)
                        startActivity(intent)
                    }
                }
            }

            backButton.setOnClickListener {
                back()
            }
        }
    }

    override fun initViews() {
        supportFragmentManager.beginTransaction().addToBackStack(null)
            .replace(binding.serviceResourceContainer.id, ServiceResourceSearchFragment()).commit()
    }

}