package com.ss.android.ugc.aweme.router;

import X.C09852jB;
import X.C27973Tp;
import X.C29913aR;
import X.LeS;
import X.LyV;
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.router.RouteIntent;
import com.bytedance.router.interceptor.IInterceptor;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import kotlin.h.b.n;
import kotlin.o.y;
import kotlin.o.z;

public final class UrlPathParamsInterceptor implements IInterceptor {
    public static final C29913aR LIZ = new C29913aR((byte) 0);
    public final ArrayList<String> LIZIZ = LeS.LIZLLL(new String[]{"aweme://challenge/detail/:id", "aweme://music/detail/:id", "aweme://assmusic/category/:cid", "aweme://music/category/:mc_id", "aweme://user/profile/:uid", "aweme://user/profile/:uid/:room_id/:room_owner_id/:request_id/:user_type", "aweme://user/profile/:uid/:room_id/:room_owner_id/:request_id/:user_type/:enter_from", "aweme://story/detail/:id", "aweme://aweme/detail/:id", "aweme://aweme/detaillist/:id", "aweme://tuwen/detail/:id", "aweme://aweme/zhima/:type", "aweme://stickers/detail/:id", "aweme://user/qna/profile/:to_user_id", "aweme://user/ask/:id", "aweme://qna/detail/:id", "aweme://library/detail/:id"});
    public String LIZJ = "";

    static {
        Covode.recordClassIndex(103834);
    }

    public UrlPathParamsInterceptor() {
    }

    public final boolean matchInterceptRules(RouteIntent routeIntent) {
        String str;
        String str2 = null;
        if (routeIntent != null) {
            str = routeIntent.getUrl();
        } else {
            str = null;
        }
        if (!(str == null || (y.LIZIZ(str, "//", false) && (str = "aweme:".concat(String.valueOf(str))) == null))) {
            str2 = y.LIZ(str, LyV.LIZ.LJIIIIZZ(), "aweme", false);
        }
        Iterator<String> it = this.LIZIZ.iterator();
        while (it.hasNext()) {
            String next = it.next();
            if (C09852jB.LIZ(next, str2)) {
                n.LIZIZ(next, "");
                this.LIZJ = next;
                return true;
            }
        }
        this.LIZJ = "";
        return false;
    }

    public final boolean onInterceptRoute(Context context, RouteIntent routeIntent) {
        Integer num;
        String str;
        String str2;
        Set<String> queryParameterNames;
        String str3;
        Uri uri;
        if (TextUtils.isEmpty(this.LIZJ)) {
            return false;
        }
        List LIZ2 = z.LIZ(this.LIZJ, new String[]{"/:"}, 0, 6);
        if (LIZ2 != null) {
            num = Integer.valueOf(LIZ2.size());
        } else {
            num = null;
        }
        if (num.intValue() > 0) {
            str = (String) LIZ2.get(0);
        } else {
            str = "";
        }
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        C27973Tp r5 = new C27973Tp(str);
        List<String> LIZ3 = C09852jB.LIZ(this.LIZJ);
        if (routeIntent == null || (uri = routeIntent.getUri()) == null) {
            str2 = null;
        } else {
            str2 = uri.toString();
        }
        List<String> LIZ4 = C09852jB.LIZ(str2);
        int size = LIZ3.size();
        for (int i = 1; i < size; i++) {
            if (i < size) {
                String str4 = LIZ3.get(i);
                n.LIZIZ(str4, "");
                Objects.requireNonNull(str4, "null cannot be cast to non-null type java.lang.String");
                String substring = str4.substring(1);
                n.LIZIZ(substring, "");
                r5.LIZ(substring, LIZ4.get(i));
            }
        }
        if (routeIntent != null) {
            Uri uri2 = routeIntent.getUri();
            if (!(uri2 == null || (queryParameterNames = uri2.getQueryParameterNames()) == null)) {
                for (String str5 : queryParameterNames) {
                    if (!TextUtils.isEmpty(str5)) {
                        Uri uri3 = routeIntent.getUri();
                        if (uri3 != null) {
                            str3 = uri3.getQueryParameter(str5);
                        } else {
                            str3 = null;
                        }
                        r5.LIZ(str5, str3);
                    }
                }
            }
            routeIntent.setUrl(r5.LIZ());
        }
        this.LIZJ = "";
        return false;
    }
}
