package com.test.basd.smartjunkcleaner.activity.splash

import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.text.SpannableString
import android.text.Spanned
import android.text.style.UnderlineSpan
import androidx.core.view.isVisible
import com.test.basd.smartjunkcleaner.MyApplication
import com.test.basd.smartjunkcleaner.databinding.ActivityLayoutSplashBinding
import com.test.basd.smartjunkcleaner.helps.ConfigHelper
import com.test.basd.smartjunkcleaner.helps.EventHelper

class PrivacyAgreementManager {


    private val binding: ActivityLayoutSplashBinding

    private val context: Activity

    private val listener: onUserPrivacyAggreementListener

    constructor(binding: ActivityLayoutSplashBinding, context: Activity, listener: onUserPrivacyAggreementListener) {
        this.binding = binding
        this.context = context
        this.listener = listener
        initView()
    }


    private fun initView() {


        val spannableString = SpannableString("Privacy Policy")
        spannableString.setSpan(
            UnderlineSpan(),
            0,
            spannableString.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        binding.idTvPrivacyPolicy.text = spannableString

        binding.idTvPrivacyPolicy.setOnClickListener {
            val intent = Intent(
                Intent.ACTION_VIEW,
                Uri.parse("https://sites.google.com/view/smartcleanerjunkcleaner/smart-cleaner-junk-cleaner")
            )
            context.startActivity(intent)
        }

        binding.idTvStart.setOnClickListener {
            binding.idTvStart.isVisible = false
            binding.idLlJindu.isVisible = true
            binding.idLlYinsi.isVisible = false
            ConfigHelper.ifAgreePrivacy = true
            (context.application as MyApplication).initApp()
            EventHelper.event("click_start_to_use")
            EventHelper.event("page_${javaClass.simpleName}")
            listener.onAgreePrivacy()
        }
    }

    interface onUserPrivacyAggreementListener {
        fun onAgreePrivacy()
    }

}