package com.pan_american.android.ui.financial_module.expense_approval

import android.annotation.SuppressLint
import android.os.Bundle
import android.webkit.JsResult
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
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.ActivityExpenseApprovalBinding
import com.pan_american.android.databinding.LayoutTitleBinding

class ExpenseApprovalActivity : BaseActivity<ActivityExpenseApprovalBinding>() {

    private lateinit var titleBinding: LayoutTitleBinding

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

    @SuppressLint("SetJavaScriptEnabled")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        initTitle()

        binding.expenseApproval.apply {
            webViewClient = WebViewClient().apply {
                settings.apply {
                    javaScriptEnabled = true
                    cacheMode = WebSettings.LOAD_NO_CACHE
                    mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
                }
                loadUrl("http://oa.pan-american-intl.com:4399/#/expenseMobile?uid=${OASystem.userInfo.userId}&portType=2")
            }
        }

        binding.expenseApproval.webChromeClient = object : WebChromeClient() {
            override fun onJsAlert(
                view: WebView?,
                url: String?,
                message: String?,
                result: JsResult?
            ): Boolean {
                return true
            }
        }
    }

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

            backButton.setOnClickListener {
                back()
            }
        }
    }
}