package com.pan_american.android.ui.group_management.group_info

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.pan_american.android.OASystem
import com.pan_american.android.R
import com.pan_american.android.base.BaseFragment
import com.pan_american.android.databinding.FragmentGroupInfoRequireBinding

class GroupInfoRequireFragment : BaseFragment<FragmentGroupInfoRequireBinding>() {

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

    override fun onStart() {
        super.onStart()

        initViews()
        initEvents()
    }

    override fun initViews() {

        binding.apply {
            visitPurpose.setText(OASystem.groupOperationRequest.visitPurpose)
            specialDemand.setText(OASystem.groupOperationRequest.specialNeeds)
            officialBusinessDemand.setText(OASystem.groupOperationRequest.officialneeds)
            otherDemand.setText(OASystem.groupOperationRequest.otherNeeds)
            notes.setText(OASystem.groupOperationRequest.remark)
            phoneNumber.setText(OASystem.groupOperationRequest.tellPhone)
            wechat.setText(OASystem.groupOperationRequest.weChatNo)
        }

        if (!OASystem.authorization(OASystem.GROUP_INFORMATION, OASystem.EDIT)) {
            binding.apply {
                visitPurpose.isEnabled(false)
                specialDemand.isEnabled(false)
                officialBusinessDemand.isEnabled(false)
                otherDemand.isEnabled(false)
                notes.isEnabled(false)
                phoneNumber.isEnabled(false)
                wechat.isEnabled(false)

                reset.visibility = View.GONE
            }
        }

    }

    override fun initEvents() {

        binding.reset.setOnClickListener {
            binding.apply {
                visitPurpose.setText("")
                specialDemand.setText("")
                officialBusinessDemand.setText("")
                otherDemand.setText("")
                notes.setText("")
                phoneNumber.setText("")
                wechat.setText("")
            }
        }

        binding.nextPage.setOnClickListener {
            OASystem.groupOperationRequest.apply {
                visitPurpose = binding.visitPurpose.getText()
                specialNeeds = binding.specialDemand.getText()
                officialneeds = binding.officialBusinessDemand.getText()
                otherNeeds = binding.otherDemand.getText()
                remark = binding.notes.getText()
                tellPhone = binding.phoneNumber.getText()
                weChatNo = binding.wechat.getText()
            }

            parentFragmentManager.beginTransaction().setCustomAnimations(
                R.anim.slide_right_in,
                R.anim.slide_left_out,
                R.anim.slide_left_in,
                R.anim.slide_right_out
            ).addToBackStack(null)
                .replace(R.id.add_group_info_container, GroupInfoExaminationFragment()).commit()
        }
    }

}