package com.all.pdfreader.pro.app.ui.act

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.core.text.HtmlCompat
import com.all.pdfreader.pro.app.R
import com.all.pdfreader.pro.app.databinding.ActivityFaqBinding

class FAQActivity : BaseActivity() {
    override val TAG: String = "FAQActivity"

    private lateinit var binding: ActivityFaqBinding
    private var faqAboutApp1IsOpen = true
    private var faqAboutApp2IsOpen = false
    private var faqAboutApp3IsOpen = false
    private var faqFileView1IsOpen = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityFaqBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initView()
    }

    private fun initView() {
        updateViewIsOpen(faqAboutApp1IsOpen, binding.faqAboutApp1DesTv, binding.faqAboutApp1Iv)
        binding.backBtn.setOnClickListener {
            finish()
        }
        binding.faqAboutApp1DesTv.text = HtmlCompat.fromHtml(
            getString(R.string.faq_about_app1_des), HtmlCompat.FROM_HTML_MODE_LEGACY
        )
        binding.faqAboutApp2DesTv.text = HtmlCompat.fromHtml(
            getString(R.string.faq_about_app2_des), HtmlCompat.FROM_HTML_MODE_LEGACY
        )
        binding.faqAboutApp3DesTv.text = HtmlCompat.fromHtml(
            getString(R.string.faq_about_app3_des), HtmlCompat.FROM_HTML_MODE_LEGACY
        )
        binding.faqFileViewing1DscTv.text = HtmlCompat.fromHtml(
            getString(R.string.faq_file_viewing1_des), HtmlCompat.FROM_HTML_MODE_LEGACY
        )

        binding.aboutApp1Btn.setOnClickListener {
            faqAboutApp1IsOpen = !faqAboutApp1IsOpen
            updateViewIsOpen(faqAboutApp1IsOpen, binding.faqAboutApp1DesTv, binding.faqAboutApp1Iv)
        }
        binding.aboutApp2Btn.setOnClickListener {
            faqAboutApp2IsOpen = !faqAboutApp2IsOpen
            updateViewIsOpen(faqAboutApp2IsOpen, binding.faqAboutApp2DesTv, binding.faqAboutApp2Iv)
        }
        binding.aboutApp3Btn.setOnClickListener {
            faqAboutApp3IsOpen = !faqAboutApp3IsOpen
            updateViewIsOpen(faqAboutApp3IsOpen, binding.faqAboutApp3DesTv, binding.faqAboutApp3Iv)
        }
        binding.fileViewing1Btn.setOnClickListener {
            faqFileView1IsOpen = !faqFileView1IsOpen
            updateViewIsOpen(faqFileView1IsOpen,binding.faqFileViewing1DscTv,binding.faqFileViewing1Iv)
        }
    }

    private fun updateViewIsOpen(b: Boolean, textView: TextView, imageView: ImageView) {
        if (b) {
            textView.visibility = View.VISIBLE
            imageView.setImageResource(R.drawable.icon_arrow_up_gray)
        } else {
            textView.visibility = View.GONE
            imageView.setImageResource(R.drawable.icon_arrow_down_gray)
        }
    }
}