package com.atmob.elec_asst.dialog;

import android.content.Context;
import android.graphics.Color;

import androidx.annotation.NonNull;

import com.atmob.elec_asst.R;
import com.atmob.elec_asst.activity.BrowserActivity;
import com.atmob.elec_asst.base.BaseDialog;
import com.atmob.elec_asst.constants.Constants;
import com.atmob.elec_asst.databinding.DialogAgreementBinding;
import com.atmob.elec_asst.utils.SpannableUtil;

@BaseDialog.FullScreen(height = false)
public class AgreementDialog extends BaseDialog<DialogAgreementBinding> {

    private AgreementAction agreementAction;


    public AgreementDialog(@NonNull Context context) {
        super(context, R.style.Theme_Common_Dialog);
        setCancelable(false);
        binding.tvDisAgree.setOnClickListener(v -> {
            if (agreementAction != null) {
                agreementAction.onDisagree();
            }
            dismiss();
        });
        binding.tvAgree.setOnClickListener(v -> {
            if (agreementAction != null) {
                agreementAction.onAgree();
            }
            dismiss();
        });
        SpannableUtil.getAgreementSpannableStringBuilder(binding.tvContent, context.getString(R.string.dialog_agreement_complete_txt),
                new String[]{
                        context.getString(R.string.dialog_agreement_privacy),
                        context.getString(R.string.dialog_agreement_user_agreement)
                }, Color.parseColor("#5E8BFF"), false, v -> {
                    BrowserActivity.start(context, Constants.PRIVACY_POLICY);
                }, v -> {
                    BrowserActivity.start(context, Constants.USER_AGREEMENT);
                });
    }


    public AgreementDialog setAgreementAction(AgreementAction agreementAction) {
        this.agreementAction = agreementAction;
        return this;
    }

    public interface AgreementAction {
        void onAgree();

        void onDisagree();
    }

}
