package com.atmob.elec_asst.activity;

import android.os.Bundle;
import android.os.Handler;

import androidx.annotation.Nullable;

import com.atmob.elec_asst.base.BaseActivity;
import com.atmob.elec_asst.constants.Constants;
import com.atmob.elec_asst.databinding.ActivitySplashBinding;
import com.atmob.elec_asst.dialog.AgreementDialog;
import com.atmob.elec_asst.utils.SharedPreferencesUtil;


public class SplashActivity extends BaseActivity<ActivitySplashBinding> {


    AgreementDialog agreementDialog;



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        checkPolicy();
    }

    private void checkPolicy() {
        if (SharedPreferencesUtil.getBoolean(Constants.isPolicyGranted,false)) {
            nextStep();
        } else {
            showAgreementDialog();
        }
    }

    private void showAgreementDialog() {
        if (agreementDialog == null) {
            agreementDialog = new AgreementDialog(this);
            agreementDialog.setAgreementAction(new AgreementDialog.AgreementAction() {
                @Override
                public void onAgree() {
                    SharedPreferencesUtil.putBoolean(Constants.isPolicyGranted,true);
                    nextStep();
                }

                @Override
                public void onDisagree() {
                    finishAfterTransition();
                }
            });
        }
        agreementDialog.show();
    }

    private void nextStep(){
        showMain();
    }

    private void showMain() {
        new Handler().postDelayed(this::goMain, 2000);
    }

    private void goMain() {
        MainActivity.start(this);
        finishAfterTransition();
    }

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