package com.bytedance.lobby.facebook;

import X.0HH;
import X.1hK;
import X.99w;
import X.9As;
import X.C5591M6c;
import X.C5593M6e;
import X.C5613M6y;
import X.C5659M8s;
import X.C5667M9a;
import X.JcY;
import X.M12;
import X.M4U;
import X.M56;
import X.M5M;
import X.M6M;
import X.M6Q;
import X.M70;
import X.M72;
import X.M7B;
import X.M7E;
import X.M7F;
import X.M7H;
import X.M7L;
import X.M7M;
import X.M7N;
import X.M7O;
import X.MA0;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.bytedance.bpea.cert.token.TokenCert;
import com.bytedance.covode.number.Covode;
import com.bytedance.lobby.auth.AuthResult;
import com.bytedance.lobby.internal.LobbyCore;
import com.bytedance.lobby.internal.LobbyViewModel;
import com.facebook.AccessToken;
import org.json.JSONException;
import org.json.JSONObject;

public class FacebookAuth extends FacebookProvider<AuthResult> implements C5667M9a, M7F<M7N> {
    public static final boolean LIZIZ = 99w.LIZ;
    public LobbyViewModel LIZ;
    public JcY LIZLLL;
    public M7L LJ;

    public final void LIZ(int i) {
    }

    static {
        Covode.recordClassIndex(35461);
    }

    public final String LIZIZ() {
        String str;
        if (!M72.LIZ.LIZ()) {
            return null;
        }
        AccessToken LIZ2 = AccessToken.LIZ.LIZ();
        if (LIZ2 == null || (str = LIZ2.LJFF) == null) {
            return "";
        }
        return str;
    }

    public final void LIZJ() {
        C5659M8s m8s = new C5659M8s("facebook", 1);
        m8s.LIZ = false;
        m8s.LIZIZ = new M7B(4, "Facebook login cancelled");
        this.LIZ.LIZIZ(m8s.LIZ());
    }

    public final void LIZ() {
        M7L m7l = this.LJ;
        if (m7l != null) {
            JcY jcY = this.LIZLLL;
            M12.LIZ((Object) jcY);
            M6Q m6q = m7l.LIZ;
            if (m6q != null) {
                C5591M6c LIZ2 = M7H.LIZ(jcY);
                m6q.getLoginManager();
                if (LIZ2 instanceof C5593M6e) {
                    ((C5593M6e) LIZ2).LIZIZ.remove(Integer.valueOf(M56.Login.toRequestCode()));
                } else {
                    throw new M5M("Unexpected CallbackManager, please use the provided Factory.");
                }
            }
            M7L m7l2 = this.LJ;
            M6Q m6q2 = m7l2.LIZ;
            if (m6q2 != null) {
                m6q2.onDetachedFromWindow();
            }
            m7l2.LIZ = null;
            this.LJ = null;
        }
    }

    public FacebookAuth(MA0 ma0) {
        super(LobbyCore.getApplication(), ma0);
    }

    public final void LIZ(M6M m6m) {
        C5659M8s m8s = new C5659M8s("facebook", 1);
        m8s.LIZ = false;
        m8s.LIZIZ = new M7B(m6m);
        this.LIZ.LIZIZ(m8s.LIZ());
    }

    public final /* synthetic */ void LIZ(Object obj) {
        final M7N m7n = (M7N) obj;
        final String str = m7n.LIZ.LIZ.LJFF;
        final Bundle bundle = new Bundle();
        bundle.putStringArray("fb_granted_permissions", (String[]) m7n.LIZ.LIZ.LIZJ.toArray(new String[0]));
        Bundle bundle2 = new Bundle();
        bundle2.putString("fields", "id,name,first_name,middle_name,last_name,token_for_business");
        bundle2.putString("access_token", str);
        C5613M6y m6y = new C5613M6y("me", bundle2, M70.GET);
        m6y.LIZIZ.LIZ((M4U) new M7E(new M7M() {
            static {
                Covode.recordClassIndex(35462);
            }

            public final void LIZ(M7O m7o) {
                String str = "";
                try {
                    String str2 = m7o.LIZ.LIZLLL;
                    if (str2 == null) {
                        str2 = str;
                    }
                    str = new JSONObject(str2).optString("token_for_business");
                } catch (JSONException e) {
                    0HH.LIZ(e);
                }
                C5659M8s m8s = new C5659M8s("facebook", 1);
                m8s.LJ = str;
                m8s.LJII = m7n.LIZ.LIZ.LIZIZ.getTime();
                m8s.LIZLLL = m7n.LIZ.LIZ.LJIIIZ;
                m8s.LJIIIZ = bundle;
                if (TextUtils.isEmpty(str)) {
                    m8s.LIZ = false;
                } else {
                    m8s.LIZ = true;
                    m8s.LJI = str;
                    m8s.LIZ();
                }
                FacebookAuth.this.LIZ.LIZIZ(m8s.LIZ());
            }
        }));
        m6y.LIZIZ.LIZ();
    }

    public final void LIZIZ(1hK r3, Bundle bundle) {
        9As.LIZ(this.LIZ, this.LIZJ.LIZIZ);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:10:0x003d, code lost:
        if (android.text.TextUtils.isEmpty(r3) != false) goto L_0x003f;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void LIZ(X.1hK r8, android.os.Bundle r9) {
        /*
            r7 = this;
            r0 = 0
            X.0Bx r1 = X.0By.LIZ(r8, r0)
            boolean r0 = X.2GD.LIZ
            if (r0 == 0) goto L_0x000c
            X.0Bs.LIZ(r1, r8)
        L_0x000c:
            java.lang.Class<com.bytedance.lobby.internal.LobbyViewModel> r0 = com.bytedance.lobby.internal.LobbyViewModel.class
            X.0Bt r0 = r1.LIZ(r0)
            com.bytedance.lobby.internal.LobbyViewModel r0 = (com.bytedance.lobby.internal.LobbyViewModel) r0
            r7.LIZ = r0
            boolean r0 = r7.J_()
            r2 = 1
            if (r0 != 0) goto L_0x0025
            com.bytedance.lobby.internal.LobbyViewModel r1 = r7.LIZ
            java.lang.String r0 = "facebook"
            X.9As.LIZ(r1, r0, r2)
            return
        L_0x0025:
            X.M7I r1 = new X.M7I
            X.M6e r0 = new X.M6e
            r0.<init>()
            r1.<init>(r0)
            r7.LIZLLL = r1
            if (r9 == 0) goto L_0x003f
            java.lang.String r0 = "fb_read_permissions"
            java.lang.String r3 = r9.getString(r0)
            boolean r0 = android.text.TextUtils.isEmpty(r3)
            if (r0 == 0) goto L_0x0041
        L_0x003f:
            java.lang.String r3 = "public_profile"
        L_0x0041:
            X.M7L r1 = new X.M7L
            r1.<init>(r8)
            r7.LJ = r1
            java.lang.String[] r2 = new java.lang.String[r2]
            r0 = 0
            r2[r0] = r3
            X.M12.LIZ((java.lang.Object) r2)
            X.M6Q r1 = r1.LIZ
            if (r1 == 0) goto L_0x005b
            java.util.List r0 = X.C4103LeY.LJIIJ(r2)
            r1.setReadPermissions((java.util.List<java.lang.String>) r0)
        L_0x005b:
            X.M7L r1 = r7.LJ
            X.JcY r0 = r7.LIZLLL
            X.M12.LIZ((java.lang.Object) r0, (java.lang.Object) r7)
            X.M6Q r6 = r1.LIZ
            if (r6 == 0) goto L_0x0097
            X.M6c r5 = X.M7H.LIZ(r0)
            X.M7C r4 = new X.M7C
            r4.<init>(r7)
            com.facebook.login.LoginManager r3 = r6.getLoginManager()
            boolean r0 = r5 instanceof X.C5593M6e
            if (r0 == 0) goto L_0x00b2
            r1 = r5
            X.M6e r1 = (X.C5593M6e) r1
            X.M56 r0 = X.M56.Login
            int r0 = r0.toRequestCode()
            X.M5n r2 = new X.M5n
            r2.<init>(r3, r4)
            X.M12.LIZ((java.lang.Object) r2)
            java.util.Map<java.lang.Integer, X.M6g> r1 = r1.LIZIZ
            java.lang.Integer r0 = java.lang.Integer.valueOf(r0)
            r1.put(r0, r2)
            X.M6c r0 = r6.LJFF
            if (r0 != 0) goto L_0x0097
            r6.LJFF = r5
        L_0x0097:
            X.M71 r0 = X.M72.LIZ
            boolean r0 = r0.LIZ()
            if (r0 == 0) goto L_0x00a8
            X.M54 r0 = com.facebook.login.LoginManager.LIZ
            com.facebook.login.LoginManager r0 = r0.LIZ()
            r0.LIZ()
        L_0x00a8:
            X.M7L r0 = r7.LJ
            X.M6Q r0 = r0.LIZ
            if (r0 == 0) goto L_0x00b1
            r0.performClick()
        L_0x00b1:
            return
        L_0x00b2:
            X.M5M r1 = new X.M5M
            java.lang.String r0 = "Unexpected CallbackManager, please use the provided Factory."
            r1.<init>((java.lang.String) r0)
            throw r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.lobby.facebook.FacebookAuth.LIZ(X.1hK, android.os.Bundle):void");
    }

    public final void LIZ(1hK r5, int i, int i2, Intent intent) {
        JcY jcY = this.LIZLLL;
        if (jcY != null) {
            jcY.LIZ(i, i2, intent, TokenCert.with("bpea-facebook_androidsdk_2003"));
            return;
        }
        C5659M8s m8s = new C5659M8s("facebook", 1);
        m8s.LIZ = false;
        m8s.LIZIZ = new M7B(3, "Facebook CallbackManager is null");
        this.LIZ.LIZIZ(m8s.LIZ());
    }
}
