package com.abbidot.tracker.dialog

import android.app.Activity
import android.view.View
import com.abbidot.tracker.R
import com.abbidot.tracker.base.BaseDialog
import com.abbidot.tracker.databinding.DialogLegalInfoBinding
import com.abbidot.tracker.util.ViewUtil

/**
 *Created  by .yzq on 2023/3/30/030.
 * @link
 * @description:
 */
class PrivacyPolicyDialog(activity: Activity) :
    BaseDialog<DialogLegalInfoBinding>(DialogLegalInfoBinding::inflate, activity) {

    private val mActivity = activity

    override fun initView() {
        setCancelable(false)
        mViewBinding.apply {
            tvDialogLegalInfoPrivacy.setOnClickListener(this@PrivacyPolicyDialog)
            tvDialogLegalInfoTermsOfService.setOnClickListener(this@PrivacyPolicyDialog)
            btnDialogLegalInfoReject.setChangeAlphaWhenPress(true)
            btnDialogLegalInfoReject.setOnClickListener(this@PrivacyPolicyDialog)
        }
    }

    /**
     * 点击同意的回调
     */
    fun agreePrivacyPolicyCallback(onListener: View.OnClickListener) {
        mViewBinding.btnDialogLegalInfoAccept.apply {
            setChangeAlphaWhenPress(true)
            setOnClickListener(onListener)
        }
    }

    /**
     * 是否同意协议
     */
    fun isAgree() = mViewBinding.boxReadAndAccept.isChecked

    override fun onClick(v: View) {
        when (v.id) {
            R.id.tv_dialog_legal_info_privacy -> ViewUtil.instance.goPrivacyPolicy(mActivity)
            R.id.tv_dialog_legal_info_terms_of_service -> ViewUtil.instance.goServiceContract(
                mActivity
            )

            R.id.btn_dialog_legal_info_reject -> {
                dismiss()
                mActivity.finish()
            }
        }
    }
}