package com.pan_american.android.ui.resource_management.airplane_three_code

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.ActivityAirplaneThreeCodeBinding
import com.pan_american.android.databinding.LayoutTitleBinding

class AirplaneThreeCodeActivity : BaseActivity<ActivityAirplaneThreeCodeBinding>() {

    private lateinit var titleBinding: LayoutTitleBinding

    override fun getViewBinding() = ActivityAirplaneThreeCodeBinding.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.three_code_resource)

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

                    visibility = View.VISIBLE

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

            backButton.setOnClickListener {
                back()
            }
        }
    }

    override fun initViews() {

        supportFragmentManager.beginTransaction().addToBackStack(null)
            .add(binding.airplaneThreeCodeContainer.id, AirplaneThreeCodeSearchFragment())
            .commit()
    }
}