package com.assimilate.alltrans.viewui

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.assimilate.alltrans.R
import com.assimilate.alltrans.common.Widget
import com.assimilate.alltrans.databinding.ActivitySettingsBinding
import com.google.android.material.bottomsheet.BottomSheetDialog


class SettingsActivity
    : AppCompatActivity() {
    private lateinit var binding: ActivitySettingsBinding
    private lateinit var bottomSheetDialog: BottomSheetDialog

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivitySettingsBinding.inflate(layoutInflater)
        enableEdgeToEdge()
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.root)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }


        initView()
        initClick()
    }

    private fun initView() {
        // 设置 BottomSheetDialog
        bottomSheetDialog = BottomSheetDialog(this)
        bottomSheetDialog.setContentView(R.layout.bottomsheet_rate)
        bottomSheetDialog.dismissWithAnimation = true
        bottomSheetDialog.findViewById<TextView>(R.id.tv_rate_commit)?.setOnClickListener {
            Widget.makeSnackbar(this, getString(R.string.settings_rate_toast))
            bottomSheetDialog.dismiss()
        }

    }

    private fun initClick() {
        binding.ivSetBack.setOnClickListener { onBackPressed() }
        binding.llRate.setOnClickListener {
            bottomSheetDialog.show()

        }
        binding.llFavorite.setOnClickListener {
            val intent = Intent(this, HistoryActivity::class.java)
            intent.putExtra("remove", "remove_history")

            startActivity(intent)
        }

        binding.llPrivacyPolicy.setOnClickListener {
            val url = "https://translark-privacy.mystrikingly.com"
            val intent = Intent(Intent.ACTION_VIEW)
            intent.data = Uri.parse(url)
            startActivity(intent)
        }

    }
}