package x6;

import com.fasterxml.jackson.core.JsonPointer;
import com.google.firebase.sessions.settings.RemoteSettings;
import dn.l;
import e7.d;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import kotlin.jvm.internal.g0;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.q;
import kotlin.jvm.internal.t;
import kotlin.text.z;
import sm.c0;
import x6.c;

/* loaded from: classes.dex */
public final class e {

    /* renamed from: c, reason: collision with root package name */
    public static final b f50553c = new b(null);

    /* renamed from: d, reason: collision with root package name */
    private static final e f50554d = new a().a();

    /* renamed from: a, reason: collision with root package name */
    private final List f50555a;

    /* renamed from: b, reason: collision with root package name */
    private final boolean f50556b;

    /* loaded from: classes.dex */
    public static final class b {
        private b() {
        }

        public /* synthetic */ b(k kVar) {
            this();
        }

        /* JADX INFO: Access modifiers changed from: private */
        public final String b(List list, boolean z10) {
            return c(list, z10, new g0() { // from class: x6.e.b.a
                @Override // kotlin.jvm.internal.g0, kn.n
                public Object get(Object obj) {
                    return ((e7.a) obj).c();
                }
            });
        }

        private final String c(List list, boolean z10, l lVar) {
            String m02;
            m02 = c0.m0(list, RemoteSettings.FORWARD_SLASH_STRING, list.isEmpty() ? "" : RemoteSettings.FORWARD_SLASH_STRING, z10 ? RemoteSettings.FORWARD_SLASH_STRING : "", 0, null, lVar, 24, null);
            return m02;
        }
    }

    public /* synthetic */ e(List list, boolean z10, k kVar) {
        this(list, z10);
    }

    public final String a() {
        return f50553c.b(this.f50555a, this.f50556b);
    }

    public final List b() {
        return this.f50555a;
    }

    public final boolean c() {
        return this.f50556b;
    }

    public final a d() {
        return new a(this);
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || e.class != obj.getClass()) {
            return false;
        }
        e eVar = (e) obj;
        return t.b(this.f50555a, eVar.f50555a) && this.f50556b == eVar.f50556b;
    }

    public int hashCode() {
        return (this.f50555a.hashCode() * 31) + Boolean.hashCode(this.f50556b);
    }

    public String toString() {
        return a();
    }

    private e(List list, boolean z10) {
        this.f50555a = list;
        this.f50556b = z10;
    }

    /* loaded from: classes.dex */
    public static final class a {

        /* renamed from: a, reason: collision with root package name */
        private final List f50557a;

        /* renamed from: b, reason: collision with root package name */
        private final List f50558b;

        /* renamed from: c, reason: collision with root package name */
        private final List f50559c;

        /* renamed from: d, reason: collision with root package name */
        private boolean f50560d;

        /* loaded from: classes.dex */
        /* synthetic */ class b extends q implements l {
            b(Object obj) {
                super(1, obj, e7.b.class, "encodableFromDecoded", "encodableFromDecoded(Ljava/lang/String;)Laws/smithy/kotlin/runtime/text/encoding/Encodable;", 0);
            }

            @Override // dn.l
            /* renamed from: l, reason: merged with bridge method [inline-methods] */
            public final e7.a invoke(String p02) {
                t.g(p02, "p0");
                return ((e7.b) this.receiver).e(p02);
            }
        }

        /* loaded from: classes.dex */
        /* synthetic */ class d extends q implements l {
            d(Object obj) {
                super(1, obj, e7.b.class, "encodableFromEncoded", "encodableFromEncoded(Ljava/lang/String;)Laws/smithy/kotlin/runtime/text/encoding/Encodable;", 0);
            }

            @Override // dn.l
            /* renamed from: l, reason: merged with bridge method [inline-methods] */
            public final e7.a invoke(String p02) {
                t.g(p02, "p0");
                return ((e7.b) this.receiver).f(p02);
            }
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        /* renamed from: x6.e$a$e, reason: collision with other inner class name */
        /* loaded from: classes.dex */
        public /* synthetic */ class C1011e extends q implements l {
            C1011e(Object obj) {
                super(1, obj, e7.b.class, "encodableFromDecoded", "encodableFromDecoded(Ljava/lang/String;)Laws/smithy/kotlin/runtime/text/encoding/Encodable;", 0);
            }

            @Override // dn.l
            /* renamed from: l, reason: merged with bridge method [inline-methods] */
            public final e7.a invoke(String p02) {
                t.g(p02, "p0");
                return ((e7.b) this.receiver).e(p02);
            }
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        /* loaded from: classes.dex */
        public /* synthetic */ class f extends q implements l {
            f(Object obj) {
                super(1, obj, e7.b.class, "encodableFromEncoded", "encodableFromEncoded(Ljava/lang/String;)Laws/smithy/kotlin/runtime/text/encoding/Encodable;", 0);
            }

            @Override // dn.l
            /* renamed from: l, reason: merged with bridge method [inline-methods] */
            public final e7.a invoke(String p02) {
                t.g(p02, "p0");
                return ((e7.b) this.receiver).f(p02);
            }
        }

        /* JADX WARN: Code restructure failed: missing block: B:5:0x000b, code lost:
        
            r0 = sm.c0.V0(r0);
         */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public a(e eVar) {
            List arrayList = (eVar == null || (r0 = eVar.b()) == null || arrayList == null) ? new ArrayList() : arrayList;
            this.f50557a = arrayList;
            C1010a c1010a = new g0() { // from class: x6.e.a.a
                @Override // kotlin.jvm.internal.g0, kn.n
                public Object get(Object obj) {
                    return ((e7.a) obj).b();
                }
            };
            d.a aVar = e7.d.f16822h;
            this.f50558b = q6.b.f(arrayList, c1010a, new b(aVar.e()));
            this.f50559c = q6.b.f(arrayList, new g0() { // from class: x6.e.a.c
                @Override // kotlin.jvm.internal.g0, kn.n
                public Object get(Object obj) {
                    return ((e7.a) obj).c();
                }
            }, new d(aVar.e()));
            this.f50560d = eVar != null ? eVar.c() : false;
        }

        private final void f(String str, l lVar) {
            String x02;
            boolean X;
            List H0;
            this.f50557a.clear();
            if (t.b(str, "")) {
                this.f50560d = false;
                return;
            }
            if (t.b(str, RemoteSettings.FORWARD_SLASH_STRING)) {
                this.f50560d = true;
                return;
            }
            x02 = z.x0(str, RemoteSettings.FORWARD_SLASH_STRING);
            X = z.X(x02, JsonPointer.SEPARATOR, false, 2, null);
            this.f50560d = X;
            if (X) {
                x02 = z.z0(x02, RemoteSettings.FORWARD_SLASH_STRING);
            }
            H0 = z.H0(x02, new char[]{JsonPointer.SEPARATOR}, false, 0, 6, null);
            List list = this.f50557a;
            Iterator it = H0.iterator();
            while (it.hasNext()) {
                list.add(lVar.invoke(it.next()));
            }
        }

        public final e a() {
            List S0;
            S0 = c0.S0(this.f50557a);
            return new e(S0, this.f50560d, null);
        }

        public final void b(e other) {
            t.g(other, "other");
            this.f50557a.clear();
            this.f50557a.addAll(other.b());
            this.f50560d = other.c();
        }

        public final List c() {
            return this.f50557a;
        }

        public final boolean d() {
            return this.f50560d;
        }

        public final void e() {
            ListIterator listIterator = this.f50557a.listIterator();
            while (listIterator.hasNext()) {
                String b10 = ((e7.a) listIterator.next()).b();
                int hashCode = b10.hashCode();
                if (hashCode != 0) {
                    if (hashCode != 46) {
                        if (hashCode == 1472 && b10.equals("..")) {
                            listIterator.remove();
                            if (!listIterator.hasPrevious()) {
                                throw new IllegalStateException("Cannot normalize because \"..\" has no parent".toString());
                            }
                            listIterator.previous();
                            listIterator.remove();
                        }
                    } else if (b10.equals(".")) {
                        listIterator.remove();
                    }
                } else if (b10.equals("")) {
                    listIterator.remove();
                }
            }
            if (this.f50557a.isEmpty()) {
                this.f50560d = true;
            }
        }

        public final void g(String text, x6.c encoding) {
            t.g(text, "text");
            t.g(encoding, "encoding");
            if (encoding.b(c.d.f50551e)) {
                i(text);
            } else {
                h(text);
            }
        }

        public final void h(String decoded) {
            t.g(decoded, "decoded");
            f(decoded, new C1011e(e7.d.f16822h.e()));
        }

        public final void i(String encoded) {
            t.g(encoded, "encoded");
            f(encoded, new f(e7.d.f16822h.e()));
        }

        public final void j(boolean z10) {
            this.f50560d = z10;
        }

        public a() {
            this(null);
        }
    }
}
