package com.bytedance.router;

import X.2HN;
import X.7he;
import X.Crj;
import X.M12;
import android.content.Context;
import android.os.Bundle;
import com.bytedance.covode.number.Covode;
import com.bytedance.router.MultiRouteIntent;
import java.util.ArrayList;
import kotlin.h.b.n;

public final class SmartRouteSet {
    public static final Companion Companion = new Companion((2HN) null);
    public Bundle animationBundle;
    public OpenResultCallback callback;
    public final Context context;
    public final Crj routes$delegate = 7he.LIZ(SmartRouteSet$routes$2.INSTANCE);

    static {
        Covode.recordClassIndex(37166);
    }

    public static final SmartRouteSet buildRoute(Context context2) {
        return Companion.buildRoute(context2);
    }

    private final ArrayList<RouteIntent> getRoutes() {
        return (ArrayList) this.routes$delegate.getValue();
    }

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

        public Companion() {
        }

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

        public final SmartRouteSet buildRoute(Context context) {
            M12.LIZ(context);
            return new SmartRouteSet(context);
        }
    }

    public final Context getContext() {
        return this.context;
    }

    public final void open() {
        RouteManager.getInstance().openMulti(this.context, buildRouteIntent());
    }

    private final MultiRouteIntent buildRouteIntent() {
        MultiRouteIntent.Builder builder = new MultiRouteIntent.Builder(new MultiRouteIntent(), getRoutes());
        builder.withBundleAnimation(this.animationBundle);
        builder.withCallback(this.callback);
        return builder.build();
    }

    public final SmartRouteSet withBundleAnimation(Bundle bundle) {
        this.animationBundle = bundle;
        return this;
    }

    public final SmartRouteSet withCallBack(OpenResultCallback openResultCallback) {
        this.callback = openResultCallback;
        return this;
    }

    public SmartRouteSet(Context context2) {
        M12.LIZ(context2);
        this.context = context2;
    }

    public final SmartRouteSet addRoute(SmartRoute smartRoute) {
        M12.LIZ(smartRoute);
        RouteIntent buildRouteIntent = smartRoute.buildRouteIntent();
        ArrayList<RouteIntent> routes = getRoutes();
        ArrayList arrayList = new ArrayList();
        for (T next : routes) {
            String url = ((RouteIntent) next).getUrl();
            n.LIZIZ(buildRouteIntent, "");
            if (n.LIZ(url, buildRouteIntent.getUrl())) {
                arrayList.add(next);
            }
        }
        if (arrayList.isEmpty()) {
            n.LIZIZ(buildRouteIntent, "");
            if (buildRouteIntent.getAnimationBundle() != null) {
                throw new IllegalArgumentException("Don't support setAnimationBundle for single Route, Use SmartRouteSet.withBundleAnimation instead".toString());
            } else if (buildRouteIntent.getEnterAnim() == -1 || buildRouteIntent.getExitAnim() == -1) {
                getRoutes().add(buildRouteIntent);
                return this;
            } else {
                throw new IllegalArgumentException("Don't support setAnimation for single Route".toString());
            }
        } else {
            StringBuilder sb = new StringBuilder("Already contains a route with same url: ");
            n.LIZIZ(buildRouteIntent, "");
            sb.append(buildRouteIntent.getUrl());
            throw new IllegalArgumentException(sb.toString().toString());
        }
    }
}
