package com.bytedance.lobby.kakao;

import X.1hK;
import X.99w;
import X.9As;
import X.C5081LuK;
import X.C5083LuM;
import X.C5617M7c;
import X.C5659M8s;
import X.C5667M9a;
import X.C5669M9c;
import X.C5671M9e;
import X.C5672M9f;
import X.C5673M9g;
import X.C5675M9i;
import X.C5676M9j;
import X.M12;
import X.M7B;
import X.M9W;
import X.M9Y;
import X.M9Z;
import X.MA0;
import X.RY6;
import android.content.Intent;
import android.os.Bundle;
import com.bytedance.bpea.cert.token.TokenCert;
import com.bytedance.covode.number.Covode;
import com.bytedance.lobby.auth.AuthResult;
import com.bytedance.lobby.internal.LobbyViewModel;
import com.kakao.auth.AuthService;
import com.kakao.auth.Session;

public class KakaoAuth extends KakaoProvider<AuthResult> implements C5667M9a {
    public static final boolean LIZ = 99w.LIZ;
    public LobbyViewModel LIZIZ;
    public C5675M9i LIZLLL;

    public final void LIZ() {
    }

    static {
        Covode.recordClassIndex(35504);
    }

    public final String LIZIZ() {
        if (!C5617M7c.LIZ()) {
            return null;
        }
        return C5672M9f.LIZ.LIZ();
    }

    public KakaoAuth(MA0 ma0) {
        super(ma0);
    }

    public final void LIZ(int i) {
        if ((i == 2 || i == 3) && C5617M7c.LIZ()) {
            Session.getCurrentSession().close();
        }
    }

    public final void LIZ(M7B m7b) {
        C5659M8s m8s = new C5659M8s(this.LIZJ.LIZIZ, 1);
        m8s.LIZ = false;
        m8s.LIZIZ = m7b;
        this.LIZIZ.LIZIZ(m8s.LIZ());
    }

    public final void LIZIZ(1hK r4, Bundle bundle) {
        if (Session.getCurrentSession().isOpened()) {
            Session.getCurrentSession().close();
            C5659M8s m8s = new C5659M8s(this.LIZJ.LIZIZ, 1);
            m8s.LIZ = true;
            this.LIZIZ.LIZIZ(m8s.LIZ());
        }
    }

    public final void LIZ(1hK r4, Bundle bundle) {
        this.LIZIZ = LobbyViewModel.LIZ(r4);
        if (!J_()) {
            9As.LIZ(this.LIZIZ, this.LIZJ.LIZIZ, 1);
            return;
        }
        AnonymousClass1 r2 = new C5675M9i() {
            static {
                Covode.recordClassIndex(35505);
            }

            public final void LIZ() {
                final C5672M9f m9f = C5672M9f.LIZ;
                if (m9f != null) {
                    AnonymousClass1 r2 = new M9Z<C5676M9j>() {
                        static {
                            Covode.recordClassIndex(35506);
                        }

                        public final void LIZ() {
                            KakaoAuth.this.LIZ(new M7B(-999, "KakaoSDK ApiResponseCallback onNotSignedUp"));
                        }

                        public final void LIZ(C5673M9g m9g) {
                            M7B m7b;
                            KakaoAuth kakaoAuth = KakaoAuth.this;
                            if (m9g != null) {
                                m7b = new M7B(m9g.LIZ.getErrorCode(), m9g.LIZ());
                            } else {
                                m7b = new M7B(3, "KakaoSDK ApiResponseCallback onSessionClosed with no ErrorResult");
                            }
                            kakaoAuth.LIZ(m7b);
                        }

                        public final void LIZIZ(C5673M9g m9g) {
                            M7B m7b;
                            KakaoAuth kakaoAuth = KakaoAuth.this;
                            if (m9g != null) {
                                m7b = new M7B(m9g.LIZ.getErrorCode(), m9g.LIZ());
                            } else {
                                m7b = new M7B(3, "KakaoSDK ApiResponseCallback onFailure with no ErrorResult");
                            }
                            kakaoAuth.LIZ(m7b);
                        }

                        public final void LIZJ(C5673M9g m9g) {
                            M7B m7b;
                            KakaoAuth kakaoAuth = KakaoAuth.this;
                            if (m9g != null) {
                                m7b = new M7B(m9g.LIZ.getErrorCode(), m9g.LIZ());
                            } else {
                                m7b = new M7B(3, "KakaoSDK ApiResponseCallback onFailureForUiThread with no ErrorResult");
                            }
                            kakaoAuth.LIZ(m7b);
                        }

                        public final /* synthetic */ void LIZ(Object obj) {
                            C5676M9j m9j = (C5676M9j) obj;
                            if (m9j == null) {
                                KakaoAuth.this.LIZ(new M7B(3, "KakaoSDK ApiResponseCallback onSuccess called, but AccessTokenInfoResponse is null."));
                                return;
                            }
                            KakaoAuth kakaoAuth = KakaoAuth.this;
                            C5672M9f m9f = m9f;
                            long currentTimeMillis = System.currentTimeMillis() + m9j.LIZ.getExpiresInMillis();
                            C5659M8s m8s = new C5659M8s(kakaoAuth.LIZJ.LIZIZ, 1);
                            m8s.LIZ = true;
                            m8s.LJ = m9f.LIZ();
                            m8s.LJII = currentTimeMillis;
                            m8s.LIZLLL = String.valueOf(m9j.LIZ.getUserId());
                            kakaoAuth.LIZIZ.LIZIZ(m8s.LIZ());
                        }
                    };
                    M12.LIZ((Object) r2);
                    AuthService.getInstance().requestAccessTokenInfo(new M9Y(r2));
                }
            }

            public final void LIZ(C5671M9e m9e) {
                C5659M8s m8s = new C5659M8s(KakaoAuth.this.LIZJ.LIZIZ, 1);
                m8s.LIZ = false;
                M7B m7b = new M7B(m9e);
                m7b.setCancelled(true);
                m8s.LIZIZ = m7b;
                KakaoAuth.this.LIZIZ.LIZIZ(m8s.LIZ());
            }
        };
        this.LIZLLL = r2;
        M12.LIZ((Object) r2);
        Session.getCurrentSession().addCallback(new C5669M9c(r2));
        Session.getCurrentSession().checkAndImplicitOpen();
        C5081LuK luK = C5081LuK.KAKAO_LOGIN_ALL;
        M12.LIZ((Object) luK, (Object) r4);
        Session.getCurrentSession().open(C5083LuM.LIZ(luK), r4);
    }

    public final void LIZ(1hK r5, int i, int i2, Intent intent) {
        if (this.LIZLLL != null) {
            TokenCert with = TokenCert.with("bpea-kakao_androidsdk_2004");
            M12.LIZ((Object) with);
            RY6.LIZ("Kakao", "handleActivityResult", with, new M9W(intent, i, i2));
        }
    }
}
