package com.pan_american.android.ui.group_invite_official.invite_data

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

class InviteDataActivity : BaseActivity<ActivityInviteDataBinding>() {

    private lateinit var titleBinding: LayoutTitleBinding

    override fun getViewBinding() = ActivityInviteDataBinding.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.invite_data)

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

                    visibility = View.VISIBLE

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

            backButton.setOnClickListener {
                back()
            }
        }
    }

    override fun initViews() {
        supportFragmentManager.beginTransaction().addToBackStack(null)
            .add(binding.inviteDataFragmentContainer.id, InviteDataSearchFragment()).commit()
    }
}