package androidx.compose.runtime.tooling;

import J4.a;
import S4.j;
import androidx.compose.runtime.ComposerImplKt;
import androidx.compose.runtime.ComposerKt;
import androidx.compose.runtime.MovableContentKt;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import kotlin.jvm.internal.o;
import n2.AbstractC2612c;
import n2.AbstractC2613d;
import x4.AbstractC3250p;
import x4.AbstractC3257w;
import x4.y;
import y4.C3274b;

/* JADX INFO: loaded from: classes.dex */
public final class ComposeStackTraceKt {
    private static final boolean IncludeDebugInfo = false;
    private static final String RuntimePackageHash = "9igjgp";

    public static final void appendGroupKeyStackTrace(StringBuilder sb, ComposeStackTrace composeStackTrace) {
        List<ComposeStackTraceFrame> listFilterInternalFramesByGroupKey = filterInternalFramesByGroupKey(composeStackTrace);
        int size = listFilterInternalFramesByGroupKey.size();
        for (int i6 = 0; i6 < size; i6++) {
            ComposeStackTraceFrame composeStackTraceFrame = listFilterInternalFramesByGroupKey.get(i6);
            sb.append("\tat $$compose.m$");
            sb.append(composeStackTraceFrame.getGroupKey());
            sb.append("(SourceFile:1)");
            sb.append('\n');
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0040 A[PHI: r10
      0x0040: PHI (r10v1 java.lang.String) = (r10v0 java.lang.String), (r10v14 java.lang.String) binds: [B:7:0x002d, B:12:0x0039] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:18:0x0047  */
    /* JADX WARN: Removed duplicated region for block: B:20:0x004c  */
    /* JADX WARN: Removed duplicated region for block: B:26:0x007c  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x00aa  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x00c9  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final void appendSourceInformationStackTrace(StringBuilder sb, ComposeStackTrace composeStackTrace) {
        String sourceFile;
        String str;
        C3274b c3274bK = AbstractC2612c.k();
        List<ComposeStackTraceFrame> frames = composeStackTrace.getFrames();
        o.h(frames, "<this>");
        j jVar = new j(frames);
        int size = jVar.size();
        String str2 = null;
        String str3 = null;
        for (int i6 = 0; i6 < size; i6++) {
            ComposeStackTraceFrame composeStackTraceFrame = (ComposeStackTraceFrame) jVar.get(i6);
            SourceInformation sourceInfo = composeStackTraceFrame.getSourceInfo();
            if (sourceInfo != null) {
                String functionName = sourceInfo.getFunctionName();
                if (functionName != null) {
                    str2 = functionName;
                    sourceFile = sourceInfo.getSourceFile();
                    if (sourceFile == null) {
                        str3 = sourceFile;
                    } else if (str3 == null) {
                        str3 = "<unknown file>";
                    }
                    List<LocationSourceInformation> locations = sourceInfo.getLocations();
                    str = str2 + '(' + str3 + ':' + ((composeStackTraceFrame.getGroupOffset() != null || composeStackTraceFrame.getGroupOffset().intValue() >= locations.size()) ? "<unknown line>" : String.valueOf(locations.get(composeStackTraceFrame.getGroupOffset().intValue()).getLineNumber())) + ')';
                    o.g(str, "toString(...)");
                    if (!sourceInfo.isCall()) {
                    }
                    if (o.c(sourceInfo.getFunctionName(), "rememberCompositionContext") || !o.c(sourceInfo.getPackageHash(), RuntimePackageHash)) {
                        c3274bK.add(str);
                    }
                } else {
                    functionName = sourceInfo.isCall() ? "<lambda>" : null;
                    if (functionName == null) {
                        if (str2 == null) {
                            str2 = "<unknown function>";
                        }
                    }
                    sourceFile = sourceInfo.getSourceFile();
                    if (sourceFile == null) {
                    }
                    List<LocationSourceInformation> locations2 = sourceInfo.getLocations();
                    if (composeStackTraceFrame.getGroupOffset() != null) {
                        str = str2 + '(' + str3 + ':' + ((composeStackTraceFrame.getGroupOffset() != null || composeStackTraceFrame.getGroupOffset().intValue() >= locations2.size()) ? "<unknown line>" : String.valueOf(locations2.get(composeStackTraceFrame.getGroupOffset().intValue()).getLineNumber())) + ')';
                        o.g(str, "toString(...)");
                        if (!sourceInfo.isCall()) {
                        }
                        if (o.c(sourceInfo.getFunctionName(), "rememberCompositionContext")) {
                            c3274bK.add(str);
                        }
                    }
                }
            }
        }
        C3274b c3274bE = AbstractC2612c.e(c3274bK);
        o.h(c3274bE, "<this>");
        j jVar2 = new j(c3274bE);
        int size2 = jVar2.size();
        for (int i7 = 0; i7 < size2; i7++) {
            String str4 = (String) jVar2.get(i7);
            sb.append("\tat ");
            sb.append(str4);
            sb.append('\n');
        }
    }

    public static final void appendStackTrace(StringBuilder sb, ComposeStackTrace composeStackTrace) {
        if (composeStackTrace.getHasSourceInformation()) {
            appendSourceInformationStackTrace(sb, composeStackTrace);
        } else {
            appendGroupKeyStackTrace(sb, composeStackTrace);
        }
    }

    public static final Throwable attachComposeStackTrace(Throwable th, a aVar) {
        tryAttachComposeStackTrace(th, aVar);
        return th;
    }

    public static final List<ComposeStackTraceFrame> filterInternalFramesByGroupKey(ComposeStackTrace composeStackTrace) {
        int[] iArr = {201, ComposerKt.compositionLocalMapKey, ComposerKt.providerMapsKey, ComposerKt.referenceKey, ComposerKt.reuseKey, ComposerImplKt.nodeKey, ComposerKt.defaultsKey, MovableContentKt.movableContentKey, 200};
        int size = composeStackTrace.getFrames().size();
        ArrayList arrayList = new ArrayList();
        int i6 = 0;
        while (i6 < size) {
            int i7 = i6 + 1;
            ComposeStackTraceFrame composeStackTraceFrame = composeStackTrace.getFrames().get(i6);
            if (!AbstractC3250p.u(iArr, composeStackTraceFrame.getGroupKey())) {
                if (composeStackTraceFrame.getGroupKey() == 100) {
                    int i8 = i6 + 2;
                    if (i8 < size && composeStackTrace.getFrames().get(i8).getGroupKey() == 1000) {
                        break;
                    }
                    AbstractC3257w.V(arrayList);
                } else {
                    arrayList.add(composeStackTraceFrame);
                }
            }
            i6 = i7;
        }
        return arrayList;
    }

    public static final boolean tryAttachComposeStackTrace(Throwable th, a aVar) {
        List listR;
        DiagnosticComposeException diagnosticComposeException;
        Object objInvoke;
        o.h(th, "<this>");
        Integer num = F4.a.f1642a;
        boolean z6 = false;
        if (num == null || num.intValue() >= 19) {
            Throwable[] suppressed = th.getSuppressed();
            o.g(suppressed, "getSuppressed(...)");
            listR = AbstractC3250p.r(suppressed);
        } else {
            Method method = E4.a.f1178b;
            listR = (method == null || (objInvoke = method.invoke(th, new Object[0])) == null) ? y.f26065a : AbstractC3250p.r((Throwable[]) objInvoke);
        }
        int size = listR.size();
        for (int i6 = 0; i6 < size; i6++) {
            if (((Throwable) listR.get(i6)) instanceof DiagnosticComposeException) {
                return false;
            }
        }
        try {
            ComposeStackTrace composeStackTrace = (ComposeStackTrace) aVar.invoke();
            if (composeStackTrace != null && !composeStackTrace.getFrames().isEmpty()) {
                z6 = true;
            }
            if (z6) {
                o.e(composeStackTrace);
                diagnosticComposeException = new DiagnosticComposeException(composeStackTrace);
            } else {
                diagnosticComposeException = null;
            }
        } catch (Throwable th2) {
            diagnosticComposeException = th2;
        }
        if (diagnosticComposeException != null) {
            AbstractC2613d.b(th, diagnosticComposeException);
        }
        return z6;
    }
}
