package com.pan_american.android.ui.resource_management.guide_resource

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

class GuideResourceActivity : BaseActivity<ActivityGuideResourceBinding>() {

    private lateinit var titleBinding: LayoutTitleBinding

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

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

        initTitle()
        initViews()
    }

    override fun initTitle() {
        titleBinding = LayoutTitleBinding.bind(binding.root).apply {
            titleText.text = resources.getString(R.string.guide_resource)

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

                    visibility = View.VISIBLE

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

            backButton.setOnClickListener {
                back()
            }
        }
    }

    override fun initViews() {

        supportFragmentManager.beginTransaction().addToBackStack(null)
            .add(binding.guideResourceContainer.id, GuideResourceSearchFragment()).commit()
    }
}