package melody.offline.music.activity

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.gyf.immersionbar.ktx.immersionBar
import melody.offline.music.R
import melody.offline.music.databinding.ActivitySettingsBinding
import melody.offline.music.fragment.MoMeFragment
import melody.offline.music.util.PRIVACY_POLICY_URL
import melody.offline.music.util.TERMS_OF_SERVICE_URL
import melody.offline.music.util.openPrivacyPolicy
import melody.offline.music.util.openTermsOfService
import melody.offline.music.util.sendFeedback
import melody.offline.music.util.shareApp
import melody.offline.music.view.RatingDialog

class SettingsActivity : AppCompatActivity() {

    companion object {
        const val FROM_TO_SETTING = "from_to_setting"
    }

    private lateinit var binding: ActivitySettingsBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivitySettingsBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initImmersionBar()
        val from = intent.getSerializableExtra(FROM_TO_SETTING) as Class<*>?
        initView(from)
    }

    private fun initImmersionBar() {
        immersionBar {
            statusBarDarkFont(false)
            statusBarView(binding.view)
        }
    }

    private fun initView(from: Class<*>?) {
        if (from != null && from == MoMeFragment::class.java) {
            binding.bgIv.setImageResource(R.mipmap.settings_bg_img)
        } else {
            binding.bgIv.setImageResource(R.drawable.drw_main_bg)
        }
        binding.backBtn.setOnClickListener {
            finish()
        }
        binding.aboutBtn.setOnClickListener {
            startActivity(Intent(this, AboutActivity::class.java))
        }
        binding.feedbackBtn.setOnClickListener {
            sendFeedback(this, "motaleb3024@gmail.com", getString(R.string.app_name))
        }
        binding.shareBtn.setOnClickListener {
            shareApp(this)
        }
        binding.ppBtn.setOnClickListener {
            openPrivacyPolicy(this, PRIVACY_POLICY_URL)
        }
        binding.tosBtn.setOnClickListener {
            openTermsOfService(this, TERMS_OF_SERVICE_URL)
        }
        binding.rateUsBtn.setOnClickListener {
            val dialog = RatingDialog(this)
            dialog.show()
        }
    }

}