package kotlin.text;

import java.util.ArrayList;
import java.util.List;
import kotlin.collections.n;
import sd.l;

/* JADX INFO: loaded from: classes.dex */
public abstract class d extends nb.g {
    public static final l W() {
        return "".length() == 0 ? new l() { // from class: kotlin.text.StringsKt__IndentKt$getIndentFunction$1
            @Override // sd.l
            public final Object invoke(Object obj) {
                String str = (String) obj;
                nb.g.i(str, "line");
                return str;
            }
        } : new l() { // from class: kotlin.text.StringsKt__IndentKt$getIndentFunction$2
            final /* synthetic */ String $indent = "";

            @Override // sd.l
            public final Object invoke(Object obj) {
                String str = (String) obj;
                nb.g.i(str, "line");
                return defpackage.e.o(new StringBuilder(), this.$indent, str);
            }
        };
    }

    public static String X(String str) {
        final String str2 = "    ";
        return kotlin.sequences.j.a1(new kotlin.sequences.d(i.u0(str), new l() { // from class: kotlin.text.StringsKt__IndentKt$prependIndent$1
            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            {
                super(1);
            }

            @Override // sd.l
            public final Object invoke(Object obj) {
                String str3 = (String) obj;
                nb.g.i(str3, "it");
                return h.e0(str3) ? str3.length() < str2.length() ? str2 : str3 : defpackage.e.o(new StringBuilder(), str2, str3);
            }
        }), "\n");
    }

    public static String Y(String str) {
        nb.g.i(str, "<this>");
        if (!(!h.e0("|"))) {
            throw new IllegalArgumentException("marginPrefix must be non-blank string.".toString());
        }
        List listB1 = kotlin.sequences.j.b1(i.u0(str));
        int length = str.length();
        listB1.size();
        l lVarW = W();
        int iB0 = hb.a.b0(listB1);
        ArrayList arrayList = new ArrayList();
        int i10 = 0;
        for (Object obj : listB1) {
            int i11 = i10 + 1;
            String strSubstring = null;
            if (i10 < 0) {
                hb.a.C0();
                throw null;
            }
            String str2 = (String) obj;
            if ((i10 != 0 && i10 != iB0) || !h.e0(str2)) {
                int length2 = str2.length();
                int i12 = 0;
                while (true) {
                    if (i12 >= length2) {
                        i12 = -1;
                        break;
                    }
                    if (!ua.b.C(str2.charAt(i12))) {
                        break;
                    }
                    i12++;
                }
                if (i12 != -1 && h.i0(str2, i12, "|", false)) {
                    strSubstring = str2.substring("|".length() + i12);
                    nb.g.h(strSubstring, "this as java.lang.String).substring(startIndex)");
                }
                if (strSubstring == null || (strSubstring = (String) lVarW.invoke(strSubstring)) == null) {
                    strSubstring = str2;
                }
            }
            if (strSubstring != null) {
                arrayList.add(strSubstring);
            }
            i10 = i11;
        }
        StringBuilder sb = new StringBuilder(length);
        n.h1(arrayList, sb, "\n", "", "", -1, "...", null);
        String string = sb.toString();
        nb.g.h(string, "mapIndexedNotNull { inde…\"\\n\")\n        .toString()");
        return string;
    }
}
