package com.datarecovery.master.module.backup_helper;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.lifecycle.MutableLiveData;

import com.atmob.app.lib.base.BaseActivity;
import com.datarecovery.master.data.consts.EventId;
import com.datarecovery.master.databinding.ActivityBackupHelperBinding;
import com.datarecovery.master.handler.EventHelper;
import com.datarecovery.master.utils.Maps;

public class BackupHelperActivity extends BaseActivity<ActivityBackupHelperBinding> {

    private static final String EXTRA_FROM_WECHAT = "extra_from_wechat";
    private final MutableLiveData<Boolean> isWechatSelected = new MutableLiveData<>(true);

    public static void start(Context context, boolean fromWechat) {
        Intent intent = new Intent(context, BackupHelperActivity.class);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.putExtra(EXTRA_FROM_WECHAT, fromWechat);
        context.startActivity(intent);
    }

    @Override
    protected boolean shouldImmersion() {
        return true;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding.setIsWechatSelected(isWechatSelected);
        boolean fromWechat = getIntent() != null && getIntent().getBooleanExtra(EXTRA_FROM_WECHAT, false);
        isWechatSelected.setValue(fromWechat);
        initView();
    }

    private void initView() {
        addTopStatusBarHeight(binding.topSpace);
        binding.setOnQQClickListener(v -> {
            this.isWechatSelected.setValue(false);
            EventHelper.report(EventId.EVENT_3001002, Maps.asMap("zone_id", 101));
        });
        binding.setOnWechatClickListener(v -> {
            this.isWechatSelected.setValue(true);
            EventHelper.report(EventId.EVENT_3001002, Maps.asMap("zone_id", 102));
        });
        binding.setOnBtnClickListener(v -> {
            finish();
            EventHelper.report(EventId.EVENT_3001001);
        });
    }

    @Override
    public void onBackPressed() {
        finish();
    }

    @Override
    public void finish() {
        super.finish();
        EventHelper.report(EventId.EVENT_3000003, Maps.asMap("id", 107));
    }
}
