package com.ss.android.ugc.aweme.compliance.business.agegate;

import X.0Bt;
import X.1Bn;
import X.2GO;
import X.2HN;
import X.2HZ;
import X.2Jy;
import X.2OR;
import X.2Pr;
import X.2aZ;
import X.2cN;
import X.2eU;
import X.34K;
import X.3qV;
import X.3v0;
import X.3v1;
import X.44L;
import X.44T;
import X.44V;
import X.44i;
import X.44n;
import X.7he;
import X.8QU;
import X.C1069Rc9;
import X.C2715S6l;
import X.C2716S6m;
import X.C2727S6x;
import X.C2728S6y;
import X.C2731S7b;
import X.C2732S7c;
import X.C2733S7d;
import X.C2734S7e;
import X.C2737S7h;
import X.C2746S7q;
import X.Crj;
import X.IPC;
import X.IPt;
import X.IPu;
import X.ISm;
import X.JMC;
import X.LnX;
import X.Ls2;
import X.LsC;
import X.M12;
import X.Mk2;
import X.Mk3;
import X.Oca;
import X.PgU;
import X.PhE;
import X.PlI;
import X.R2Q;
import X.S71;
import X.S77;
import X.S79;
import X.S7A;
import X.S7B;
import X.S7C;
import X.S7D;
import X.S7E;
import X.S7F;
import X.S7G;
import X.S7I;
import X.S7L;
import X.S7M;
import X.S7N;
import X.S7O;
import X.S7P;
import X.S7Q;
import X.S7R;
import X.S7S;
import X.S7W;
import X.S9B;
import X.SRR;
import android.os.Bundle;
import android.text.TextWatcher;
import android.view.View;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.compliance.api.a;
import com.ss.android.ugc.aweme.compliance.api.services.agegate.IAgeGateService;
import com.ss.android.ugc.aweme.global.config.settings.pojo.AgeGateSettings;
import com.ss.android.ugc.aweme.global.config.settings.pojo.IESSettingsProxy;
import com.ss.android.ugc.aweme.profile.model.User;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import kotlin.h.b.n;
import kotlin.o.y;
import org.greenrobot.eventbus.ThreadMode;

public final class AgeGateViewModel extends 0Bt implements 2HZ, 2GO {
    public static final long LJIJJLI = 31536000000L;
    public static final C2746S7q LJIL = new C2746S7q((byte) 0);
    public static final Date LJJIIZI = new Date(System.currentTimeMillis() - 31536000000L);
    public static final HashSet<Integer> LJJIJ = 8QU.LIZJ(new Integer[]{3008010, 3008011, 3008009, 3008008, 3008012, 3008020, 3008026, 3008038});
    public static final long LJJIJIIJI = 86400000;
    public boolean LIZ;
    public boolean LIZIZ;
    public 44n LIZJ = new 44n(false, false, (44T) null, (44V) null, false, 31, (2HN) null);
    public S71 LIZLLL;
    public final SimpleDateFormat LJ;
    public int LJFF;
    public int LJI;
    public int LJII;
    public boolean LJIIIIZZ;
    public boolean LJIIIZ;
    public Date LJIIJ;
    public long LJIIJJI;
    public final 1Bn<Boolean> LJIIL;
    public final 1Bn<Boolean> LJIILIIL;
    public final 1Bn<String> LJIILJJIL;
    public final 1Bn<Integer> LJIILL;
    public final 1Bn<C2731S7b> LJIILLIIL;
    public 2cN LJIIZILJ;
    public final TextWatcher LJIJ;
    public final Oca LJIJI;
    public final View.OnClickListener LJIJJ;
    public final Ls2<2Pr> LJJ = new S7G(this);
    public final LsC<String, 2Pr> LJJI = new S7C(this);
    public final DateFormat LJJIFFI;
    public final Crj LJJII;
    public final Crj LJJIII;
    public final Crj LJJIIJ;
    public 2cN LJJIIJZLJL;
    public 2cN LJJIIZ;

    public final IAgeGateService LIZ() {
        return (IAgeGateService) this.LJJII.getValue();
    }

    public final User LIZIZ() {
        return (User) this.LJJIII.getValue();
    }

    public final int LIZJ() {
        return ((Number) this.LJJIIJ.getValue()).intValue();
    }

    public final Map<Integer, Object> getSubscriberEventTypes() {
        HashMap hashMap = new HashMap();
        hashMap.put(459, new C1069Rc9(AgeGateViewModel.class, "onDialogOptionClickEvent", 2Jy.class, ThreadMode.POSTING, 0, false));
        return hashMap;
    }

    @ISm
    public final void onDialogOptionClickEvent(2Jy r1) {
        M12.LIZ(r1);
    }

    public final String LIZLLL() {
        String format;
        Date date = this.LJIIJ;
        if (date == null || (format = this.LJJIFFI.format(date)) == null) {
            return "";
        }
        return format;
    }

    public final String LJ() {
        String format;
        Date date = this.LJIIJ;
        if (date == null || (format = this.LJ.format(date)) == null) {
            return "";
        }
        return format;
    }

    public final void onCleared() {
        AgeGateViewModel.super.onCleared();
        2cN r0 = this.LJJIIJZLJL;
        if (r0 != null) {
            r0.dispose();
        }
        this.LJJIIJZLJL = null;
        2cN r02 = this.LJJIIZ;
        if (r02 != null) {
            r02.dispose();
        }
        this.LJJIIZ = null;
        2cN r03 = this.LJIIZILJ;
        if (r03 != null) {
            r03.dispose();
        }
        this.LJIIZILJ = null;
    }

    public final Date LJFF() {
        try {
            IESSettingsProxy iESSettingsProxy = 2OR.LIZ.LIZIZ;
            n.LIZIZ(iESSettingsProxy, "");
            AgeGateSettings ageGateSettings = iESSettingsProxy.getAgeGateSettings();
            n.LIZIZ(ageGateSettings, "");
            Integer initialDate = ageGateSettings.getInitialDate();
            if (initialDate.intValue() > 0) {
                return new Date(TimeUnit.SECONDS.toMillis((long) initialDate.intValue()));
            }
        } catch (Exception unused) {
        }
        return LJJIIZI;
    }

    public final boolean LJI() {
        if (this.LIZIZ) {
            this.LJIILLIIL.postValue(new S7L(S7W.CONFIRM_ON_QUIT, (Bundle) null));
            return true;
        }
        S71 s71 = this.LIZLLL;
        if (s71 != null) {
            s71.LIZ();
        }
        LIZ().LIZ((String) null);
        this.LJIILLIIL.postValue(new S7M(true));
        return false;
    }

    public final void LJII() {
        int i;
        int i2 = 1;
        this.LJIILIIL.postValue(true);
        2cN r0 = this.LJJIIJZLJL;
        if (r0 != null) {
            r0.dispose();
        }
        long currentTimeMillis = System.currentTimeMillis();
        2eU r5 = AgeGateApi.LIZ;
        String LJ2 = LJ();
        if (this.LIZ) {
            i = 2;
        } else {
            i = 1;
        }
        if (!this.LIZIZ) {
            i2 = 2;
        }
        this.LJJIIJZLJL = r5.LIZ(LJ2, i, i2).LIZIZ(new C2733S7d(this, "/aweme/v3/verification/age/", currentTimeMillis)).LIZ(new C2734S7e(this, "/aweme/v3/verification/age/", currentTimeMillis)).LIZ(Mk2.LIZ(Mk3.LIZ)).LIZ(new S7A(this), new S7F(this));
    }

    public final void LJIIIIZZ() {
        int i;
        int i2 = 1;
        this.LJIILIIL.postValue(true);
        2cN r0 = this.LJJIIZ;
        if (r0 != null) {
            r0.dispose();
        }
        long currentTimeMillis = System.currentTimeMillis();
        String LJ2 = LJ();
        if (this.LIZ) {
            i = 2;
        } else {
            i = 1;
        }
        if (!this.LIZIZ) {
            i2 = 2;
        }
        M12.LIZ(LJ2);
        PgU LIZIZ2 = 2eU.LIZ.calculateAge(LJ2, i, i2).LIZIZ(PhE.LIZIZ(PlI.LIZJ));
        n.LIZIZ(LIZIZ2, "");
        this.LJJIIZ = LIZIZ2.LIZIZ(new C2737S7h(this, "/tiktok/v1/calculate/age/", currentTimeMillis)).LIZ(new C2732S7c(this, "/tiktok/v1/calculate/age/", currentTimeMillis)).LIZ(Mk2.LIZ(Mk3.LIZ)).LIZ(new S7B(this), new S7E(this));
    }

    static {
        Covode.recordClassIndex(60649);
    }

    public AgeGateViewModel() {
        SRR srr = 34K.LIZ;
        n.LIZIZ(srr, "");
        this.LJJIFFI = DateFormat.getDateInstance(1, new Locale(srr.LIZ(LnX.LIZ()), S9B.LIZ()));
        this.LJ = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
        this.LJIIL = new 1Bn<>(false);
        this.LJIILIIL = new 1Bn<>(false);
        this.LJIILJJIL = new 1Bn<>((Object) null);
        this.LJIILL = new 1Bn<>((Object) null);
        this.LJIILLIIL = new 1Bn<>((Object) null);
        this.LJJII = 7he.LIZ(C2727S6x.LIZ);
        this.LJJIII = 7he.LIZ(C2728S6y.LIZ);
        this.LJJIIJ = 7he.LIZ(new S7O(this));
        this.LJIJ = new S7I(this);
        this.LJIJI = new S77(this);
        this.LJIJJ = new S79(this);
    }

    public final void LIZ(String str) {
        if (LIZJ() == R2Q.BLOCKING.getValue()) {
            this.LJIILLIIL.postValue(new S7S(str));
            this.LJIILIIL.postValue(false);
            return;
        }
        LJII();
    }

    public final void LIZ(IPt iPt) {
        int i;
        String str = iPt.LIZLLL;
        if (str == null || y.LIZ(str)) {
            LIZ(iPt.message);
            return;
        }
        this.LJIILIIL.postValue(false);
        1Bn<C2731S7b> r4 = this.LJIILLIIL;
        S7W s7w = S7W.CONFIRM_ON_AGE;
        Bundle bundle = new Bundle();
        String str2 = iPt.LIZJ;
        String str3 = iPt.LIZLLL;
        if (str3 == null) {
            str3 = "";
        }
        List list = iPt.LJFF;
        Integer num = iPt.LIZIZ;
        if (num != null) {
            i = num.intValue();
        } else {
            i = -1;
        }
        IPC ipc = (IPC) IPC.MAP.get(Integer.valueOf(iPt.LJ));
        if (ipc == null) {
            ipc = IPC.HORIZONTAL;
        }
        bundle.putSerializable("age_gate_popup_param_model", new IPu(str2, str3, list, i, ipc));
        r4.postValue(new S7L(s7w, bundle));
    }

    public final void LIZ(S7D s7d) {
        int i;
        int value;
        int value2;
        44i.LIZIZ().edit().putBoolean("ftc_age_gate_response_prompt", s7d.is_prompt()).apply();
        Integer ageGatePostAction = s7d.getAgeGatePostAction();
        if (ageGatePostAction != null) {
            i = ageGatePostAction.intValue();
        } else {
            i = 0;
        }
        44i.LIZIZ().edit().putInt("ftc_age_gate_response_mode", i).apply();
        boolean is_prompt = s7d.is_prompt();
        3v0 r1 = 3v1.Companion;
        Integer registerAgeGatePostAction = s7d.getRegisterAgeGatePostAction();
        if (registerAgeGatePostAction != null) {
            value = registerAgeGatePostAction.intValue();
        } else {
            value = 3v1.PASS.getValue();
        }
        3v1 LIZ2 = r1.LIZ(value);
        3v0 r12 = 3v1.Companion;
        Integer ageGatePostAction2 = s7d.getAgeGatePostAction();
        if (ageGatePostAction2 != null) {
            value2 = ageGatePostAction2.intValue();
        } else {
            value2 = 3v1.PASS.getValue();
        }
        44L r2 = new 44L(is_prompt, LIZ2, r12.LIZ(value2));
        Integer registerAgeGatePostAction2 = s7d.getRegisterAgeGatePostAction();
        if (registerAgeGatePostAction2 != null) {
            int intValue = registerAgeGatePostAction2.intValue();
            a.LJIIZILJ().LJI();
            if (intValue == 3v1.PASS.getValue()) {
                C2716S6m.LJFF.LIZ(r2);
                a.LJIIZILJ().LIZ(8);
                LIZ().LIZ(LJ());
                S71 s71 = this.LIZLLL;
                if (s71 != null) {
                    s71.LIZ(r2, this.LJJ, this.LJJI);
                }
            } else if (intValue == 3v1.US_FTC.getValue()) {
                C2716S6m.LJFF.LIZ();
                LIZ().LIZ(LJ());
                this.LJIILLIIL.postValue(new S7P(r2));
            } else {
                C2716S6m.LJFF.LIZ();
                this.LJIILLIIL.postValue(new S7R(s7d.getStatus_msg()));
                return;
            }
        }
        Integer ageGatePostAction3 = s7d.getAgeGatePostAction();
        if (ageGatePostAction3 != null) {
            int intValue2 = ageGatePostAction3.intValue();
            if (intValue2 == 3v1.PASS.getValue()) {
                C2716S6m.LJFF.LIZ(r2);
                a.LJIIZILJ().LIZ(8);
                LIZ().LIZ(LJ());
                S71 s712 = this.LIZLLL;
                if (s712 != null) {
                    s712.LIZ(r2, this.LJJ, this.LJJI);
                }
            } else if (intValue2 == 3v1.US_FTC.getValue()) {
                C2716S6m.LJFF.LIZ();
                LIZ().LIZ(LJ());
                this.LJIILLIIL.postValue(new S7P(r2));
            } else {
                C2716S6m.LJFF.LIZ();
                this.LJIILLIIL.postValue(new S7Q(r2));
            }
        }
    }

    public final void LIZIZ(String str, int i) {
        C2715S6l s6l = C2716S6m.LJFF;
        s6l.LIZ(s6l.LIZIZ(), i, false, (Map<String, String>) s6l.LIZIZ((44L) null));
        if (LJJIJ.contains(Integer.valueOf(i))) {
            if (this.LIZIZ) {
                a.LJIIZILJ().LJI();
            }
            this.LJIILLIIL.postValue(new S7N(str, Integer.valueOf(i)));
            this.LJIIL.postValue(false);
            return;
        }
        this.LJIILLIIL.postValue(new S7S(str));
    }

    public final void LIZ(String str, int i) {
        if (i == 56004) {
            C2716S6m.LJFF.LIZ();
            this.LJIILLIIL.postValue(new S7R(str));
        } else if (LJJIJ.contains(Integer.valueOf(i))) {
            this.LJIILLIIL.postValue(new S7N(str, Integer.valueOf(i)));
            this.LJIIL.postValue(false);
        } else {
            this.LJIILLIIL.postValue(new S7S(str));
        }
    }

    public final void LIZ(String str, long j, int i) {
        2aZ r2 = new 2aZ();
        String str2 = str;
        r2.LIZ("type", str2);
        r2.LIZ("errorCode", Integer.valueOf(i));
        C2716S6m.LJFF.LIZ(0, str2, System.currentTimeMillis() - j, r2.LIZ());
    }

    public final void LIZ(String str, long j, Throwable th) {
        int i;
        C2715S6l s6l = C2716S6m.LJFF;
        long currentTimeMillis = System.currentTimeMillis() - j;
        2aZ r2 = new 2aZ();
        String str2 = str;
        r2.LIZ("type", str2);
        if (th instanceof JMC) {
            i = ((3qV) th).getErrorCode();
        } else {
            i = -1;
        }
        r2.LIZ("errorCode", Integer.valueOf(i));
        s6l.LIZ(1, str2, currentTimeMillis, r2.LIZ());
    }
}
