package com.bytedance.router.fragment;

import X.0AA;
import X.1hK;
import X.2HN;
import X.M12;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.router.OpenResultCallback;
import com.bytedance.router.RouteIntent;
import com.bytedance.router.RouteManager;
import com.bytedance.router.fragment.FragmentNavigationRouteIntent;
import com.bytedance.router.monitor.RouterMonitor;
import java.io.Serializable;
import java.util.ArrayList;
import kotlin.h.b.n;

public final class FragmentRoute {
    public static final Companion Companion = new Companion((2HN) null);
    public final 1hK activity;
    public OpenResultCallback callback;
    public int enterAnim;
    public int exitAnim;
    public Intent extraParams;
    public final Fragment fragment;
    public 0AA fragmentManager;
    public final FragmentNavigationContainer navigationContainer;
    public int popEnterAnim;
    public int popExitAnim;
    public PopOp popOp;
    public PushOp pushOp;
    public PushType pushType;
    public String url;

    static {
        Covode.recordClassIndex(37222);
    }

    public FragmentRoute(1hK r7, FragmentNavigationContainer fragmentNavigationContainer) {
        this(r7, (Fragment) null, fragmentNavigationContainer, 2, (2HN) null);
    }

    public FragmentRoute(FragmentNavigationContainer fragmentNavigationContainer) {
        this((1hK) null, (Fragment) null, fragmentNavigationContainer, 3, (2HN) null);
    }

    public final void commit() {
        commit$default(this, (Boolean) null, 1, (Object) null);
    }

    public final FragmentRoute pop() {
        pop$default(this, (Boolean) null, 1, (Object) null);
        return this;
    }

    public final FragmentRoute popTo(String str) {
        popTo$default(this, str, (String) null, (Boolean) null, 6, (Object) null);
        return this;
    }

    public final FragmentRoute popTo(String str, String str2) {
        popTo$default(this, str, str2, (Boolean) null, 4, (Object) null);
        return this;
    }

    public final FragmentRoute push(String str) {
        push$default(this, str, (String) null, (Integer) null, 6, (Object) null);
        return this;
    }

    public final FragmentRoute push(String str, String str2) {
        push$default(this, str, str2, (Integer) null, 4, (Object) null);
        return this;
    }

    public static final class Companion {
        static {
            Covode.recordClassIndex(37223);
        }

        public Companion() {
        }

        public /* synthetic */ Companion(2HN r1) {
            this();
        }
    }

    public final 1hK getActivity() {
        return this.activity;
    }

    public final FragmentRoute withParam(String str, boolean z) {
        this.extraParams.putExtra(str, z);
        return this;
    }

    public final FragmentRoute withParam(String str, boolean[] zArr) {
        this.extraParams.putExtra(str, zArr);
        return this;
    }

    public final FragmentRoute withParam(String str, byte[] bArr) {
        this.extraParams.putExtra(str, bArr);
        return this;
    }

    public final FragmentRoute withParam(String str, char[] cArr) {
        this.extraParams.putExtra(str, cArr);
        return this;
    }

    public final FragmentRoute withParam(String str, CharSequence charSequence) {
        this.extraParams.putExtra(str, charSequence);
        return this;
    }

    public final FragmentRoute withParam(String str, CharSequence[] charSequenceArr) {
        this.extraParams.putExtra(str, charSequenceArr);
        return this;
    }

    public final FragmentRoute withParam(String str, double[] dArr) {
        this.extraParams.putExtra(str, dArr);
        return this;
    }

    public final FragmentRoute withParam(String str, float[] fArr) {
        this.extraParams.putExtra(str, fArr);
        return this;
    }

    public final FragmentRoute withParam(String str, int[] iArr) {
        this.extraParams.putExtra(str, iArr);
        return this;
    }

    public final FragmentRoute withParam(String str, long[] jArr) {
        this.extraParams.putExtra(str, jArr);
        return this;
    }

    public final FragmentRoute withParam(String str, Parcelable parcelable) {
        this.extraParams.putExtra(str, parcelable);
        return this;
    }

    public final FragmentRoute withParam(String str, Parcelable[] parcelableArr) {
        this.extraParams.putExtra(str, parcelableArr);
        return this;
    }

    public final FragmentRoute withParam(String str, Serializable serializable) {
        this.extraParams.putExtra(str, serializable);
        return this;
    }

    public final FragmentRoute withParam(String str, short s) {
        this.extraParams.putExtra(str, s);
        return this;
    }

    public final FragmentRoute withParam(String str, short[] sArr) {
        this.extraParams.putExtra(str, sArr);
        return this;
    }

    public final FragmentRoute withParam(String str, String str2) {
        this.extraParams.putExtra(str, str2);
        return this;
    }

    public final FragmentRoute withParam(String str, String[] strArr) {
        this.extraParams.putExtra(str, strArr);
        return this;
    }

    private final RouteIntent buildRouteIntent() {
        FragmentNavigationContainer fragmentNavigationContainer = this.navigationContainer;
        FragmentNavigationRouteIntent.Builder builder = new FragmentNavigationRouteIntent.Builder();
        builder.withFragmentNavigationContainer(fragmentNavigationContainer);
        builder.withFragmentManager(this.fragmentManager);
        builder.withPushOp(this.pushOp);
        builder.withPopOp(this.popOp);
        builder.withFragment(this.fragment);
        builder.withParam(this.extraParams);
        builder.withCallback(this.callback);
        return builder.build();
    }

    public static Bundle INVOKEVIRTUAL_com_bytedance_router_fragment_FragmentRoute_com_ss_android_ugc_aweme_lancet_IntentLancet_getExtras(Intent intent) {
        try {
            return intent.getExtras();
        } catch (Exception unused) {
            return null;
        }
    }

    public final FragmentRoute withCallback(OpenResultCallback openResultCallback) {
        M12.LIZ(openResultCallback);
        this.callback = openResultCallback;
        return this;
    }

    public final FragmentRoute withFragmentManager(0AA r1) {
        M12.LIZ(r1);
        this.fragmentManager = r1;
        return this;
    }

    public final FragmentRoute withParam(Bundle bundle) {
        this.extraParams.putExtras(bundle);
        return this;
    }

    public final FragmentRoute withPushType(PushType pushType2) {
        if (pushType2 != null) {
            this.pushType = pushType2;
        }
        return this;
    }

    public final FragmentRoute withUrl(String str) {
        M12.LIZ(str);
        this.url = str;
        return this;
    }

    public final FragmentRoute withNavArg(Parcelable parcelable) {
        if (parcelable != null) {
            this.extraParams.putExtra("smart_key_route_arg", parcelable);
        }
        return this;
    }

    public final FragmentRoute pop(Boolean bool) {
        this.popOp = new PopOp((String) null, (String) null, 3, (2HN) null);
        if (bool != null) {
            boolean booleanValue = bool.booleanValue();
            PopOp popOp2 = this.popOp;
            if (popOp2 != null) {
                popOp2.setTryFinishActivity(booleanValue);
            }
        }
        return this;
    }

    public final FragmentRoute withParam(Intent intent) {
        M12.LIZ(intent);
        Intent intent2 = this.extraParams;
        Bundle INVOKEVIRTUAL_com_bytedance_router_fragment_FragmentRoute_com_ss_android_ugc_aweme_lancet_IntentLancet_getExtras = INVOKEVIRTUAL_com_bytedance_router_fragment_FragmentRoute_com_ss_android_ugc_aweme_lancet_IntentLancet_getExtras(intent);
        if (INVOKEVIRTUAL_com_bytedance_router_fragment_FragmentRoute_com_ss_android_ugc_aweme_lancet_IntentLancet_getExtras == null) {
            INVOKEVIRTUAL_com_bytedance_router_fragment_FragmentRoute_com_ss_android_ugc_aweme_lancet_IntentLancet_getExtras = new Bundle();
        }
        intent2.putExtras(INVOKEVIRTUAL_com_bytedance_router_fragment_FragmentRoute_com_ss_android_ugc_aweme_lancet_IntentLancet_getExtras);
        return this;
    }

    private final void processOps(boolean z) {
        PushOp pushOp2 = this.pushOp;
        if (pushOp2 != null) {
            pushOp2.setImmediate(z);
            pushOp2.setPushType(this.pushType);
            pushOp2.setEnterAnim(this.enterAnim);
            pushOp2.setExitAnim(this.exitAnim);
            pushOp2.setPopEnterAnim(this.popEnterAnim);
            pushOp2.setPopExitAnim(this.popExitAnim);
        }
        PopOp popOp2 = this.popOp;
        if (popOp2 != null) {
            popOp2.setImmediate(z);
        }
    }

    public final void commit(Boolean bool) {
        boolean z;
        String str;
        Fragment fragment2;
        if (bool != null) {
            z = bool.booleanValue();
        } else {
            z = false;
        }
        processOps(z);
        PushOp pushOp2 = this.pushOp;
        if (pushOp2 == null || (str = pushOp2.getUrl()) == null) {
            PopOp popOp2 = this.popOp;
            if (popOp2 != null) {
                str = popOp2.getUrl();
            } else {
                str = null;
            }
        }
        if (str == null) {
            str = "";
        }
        RouteIntent buildRouteIntent = buildRouteIntent();
        if (buildRouteIntent != null) {
            buildRouteIntent.setRouteId(RouterMonitor.INSTANCE.startRoute(str));
            Context context = this.activity;
            if (context != null || ((fragment2 = buildRouteIntent.getFragment()) != null && (context = fragment2.getContext()) != null)) {
                n.LIZIZ(context, "");
                RouteManager.getInstance().fragmentNavigation(context, buildRouteIntent);
            }
        }
    }

    public final FragmentRoute withParamCharSequenceList(String str, ArrayList<CharSequence> arrayList) {
        this.extraParams.putCharSequenceArrayListExtra(str, arrayList);
        return this;
    }

    public final FragmentRoute withParamIntegerList(String str, ArrayList<Integer> arrayList) {
        this.extraParams.putIntegerArrayListExtra(str, arrayList);
        return this;
    }

    public final FragmentRoute withParamParcelableList(String str, ArrayList<? extends Parcelable> arrayList) {
        this.extraParams.putParcelableArrayListExtra(str, arrayList);
        return this;
    }

    public final FragmentRoute withParamStringList(String str, ArrayList<String> arrayList) {
        this.extraParams.putStringArrayListExtra(str, arrayList);
        return this;
    }

    public final FragmentRoute withParam(String str, byte b) {
        this.extraParams.putExtra(str, b);
        return this;
    }

    public final FragmentRoute withParam(String str, char c) {
        this.extraParams.putExtra(str, c);
        return this;
    }

    public final FragmentRoute withParam(String str, double d) {
        this.extraParams.putExtra(str, d);
        return this;
    }

    public final FragmentRoute withParam(String str, float f) {
        this.extraParams.putExtra(str, f);
        return this;
    }

    public final FragmentRoute withParam(String str, int i) {
        this.extraParams.putExtra(str, i);
        return this;
    }

    public final FragmentRoute withParam(String str, long j) {
        this.extraParams.putExtra(str, j);
        return this;
    }

    public final FragmentRoute withParam(String str, Bundle bundle) {
        this.extraParams.putExtra(str, bundle);
        return this;
    }

    public FragmentRoute(1hK r2, Fragment fragment2, FragmentNavigationContainer fragmentNavigationContainer) {
        M12.LIZ(fragmentNavigationContainer);
        this.activity = r2;
        this.fragment = fragment2;
        this.navigationContainer = fragmentNavigationContainer;
        this.pushType = PushType.REPLACE;
        this.popEnterAnim = -1;
        this.popExitAnim = -1;
        this.enterAnim = -1;
        this.exitAnim = -1;
        this.extraParams = new Intent();
        this.url = "";
    }

    public final FragmentRoute popTo(String str, String str2, Boolean bool) {
        this.popOp = new PopOp(str, str2);
        if (bool != null) {
            boolean booleanValue = bool.booleanValue();
            PopOp popOp2 = this.popOp;
            if (popOp2 != null) {
                popOp2.setPopInclusive(booleanValue);
            }
        }
        return this;
    }

    public final FragmentRoute push(String str, String str2, Integer num) {
        if (str == null) {
            return this;
        }
        this.pushOp = new PushOp(str, str2, num);
        return this;
    }

    public static /* synthetic */ void commit$default(FragmentRoute fragmentRoute, Boolean bool, int i, Object obj) {
        if ((i & 1) != 0) {
            bool = false;
        }
        fragmentRoute.commit(bool);
    }

    public static /* synthetic */ FragmentRoute pop$default(FragmentRoute fragmentRoute, Boolean bool, int i, Object obj) {
        if ((i & 1) != 0) {
            bool = true;
        }
        fragmentRoute.pop(bool);
        return fragmentRoute;
    }

    public final FragmentRoute withAnimation(int i, int i2, int i3, int i4) {
        this.enterAnim = i;
        this.exitAnim = i2;
        this.popEnterAnim = i3;
        this.popExitAnim = i4;
        return this;
    }

    /* JADX INFO: this call moved to the top of the method (can break code semantics) */
    public /* synthetic */ FragmentRoute(1hK r3, Fragment fragment2, FragmentNavigationContainer fragmentNavigationContainer, int i, 2HN r7) {
        this((i & 1) != 0 ? null : r3, (i & 2) != 0 ? null : fragment2, fragmentNavigationContainer);
    }

    public static /* synthetic */ FragmentRoute push$default(FragmentRoute fragmentRoute, String str, String str2, Integer num, int i, Object obj) {
        if ((i & 2) != 0) {
            str2 = null;
        }
        if ((i & 4) != 0) {
            num = null;
        }
        fragmentRoute.push(str, str2, num);
        return fragmentRoute;
    }

    public static /* synthetic */ FragmentRoute popTo$default(FragmentRoute fragmentRoute, String str, String str2, Boolean bool, int i, Object obj) {
        if ((i & 2) != 0) {
            str2 = null;
        }
        if ((i & 4) != 0) {
            bool = false;
        }
        fragmentRoute.popTo(str, str2, bool);
        return fragmentRoute;
    }
}
