package androidx.compose.runtime;

import androidx.compose.runtime.internal.StabilityInferred;
import java.util.ArrayList;

/* JADX INFO: loaded from: classes.dex */
@StabilityInferred(parameters = 0)
public final class GroupSourceInformation {
    public static final int $stable = 8;
    private boolean closed;
    private int dataEndOffset;
    private final int dataStartOffset;
    private ArrayList<Object> groups;
    private final int key;
    private String sourceInformation;

    public GroupSourceInformation(int i6, String str, int i7) {
        this.key = i6;
        this.sourceInformation = str;
        this.dataStartOffset = i7;
    }

    private final void add(Object obj) {
        ArrayList<Object> arrayList = this.groups;
        if (arrayList == null) {
            arrayList = new ArrayList<>();
        }
        this.groups = arrayList;
        arrayList.add(obj);
    }

    private final boolean hasAnchor(Anchor anchor) {
        ArrayList<Object> arrayList = this.groups;
        if (arrayList != null) {
            int size = arrayList.size();
            for (int i6 = 0; i6 < size; i6++) {
                Object obj = arrayList.get(i6);
                if (kotlin.jvm.internal.o.c(obj, anchor)) {
                    return true;
                }
                if ((obj instanceof GroupSourceInformation) && ((GroupSourceInformation) obj).hasAnchor(anchor)) {
                    return true;
                }
            }
        }
        return false;
    }

    private final GroupSourceInformation openInformation() {
        Object obj;
        GroupSourceInformation groupSourceInformationOpenInformation;
        ArrayList<Object> arrayList = this.groups;
        if (arrayList != null) {
            for (int size = arrayList.size() - 1; size >= 0; size--) {
                obj = arrayList.get(size);
                if ((obj instanceof GroupSourceInformation) && !((GroupSourceInformation) obj).closed) {
                    break;
                }
            }
            obj = null;
        } else {
            obj = null;
        }
        GroupSourceInformation groupSourceInformation = obj instanceof GroupSourceInformation ? (GroupSourceInformation) obj : null;
        return (groupSourceInformation == null || (groupSourceInformationOpenInformation = groupSourceInformation.openInformation()) == null) ? this : groupSourceInformationOpenInformation;
    }

    public final void addGroupAfter(SlotWriter slotWriter, int i6, int i7) {
        Anchor anchorTryAnchor$runtime;
        ArrayList<Object> arrayList = this.groups;
        if (arrayList == null) {
            arrayList = new ArrayList<>();
            this.groups = arrayList;
        }
        int i8 = 0;
        if (i6 >= 0 && (anchorTryAnchor$runtime = slotWriter.tryAnchor$runtime(i6)) != null) {
            int size = arrayList.size();
            while (true) {
                if (i8 >= size) {
                    i8 = -1;
                    break;
                }
                Object obj = arrayList.get(i8);
                if (kotlin.jvm.internal.o.c(obj, anchorTryAnchor$runtime) || ((obj instanceof GroupSourceInformation) && ((GroupSourceInformation) obj).hasAnchor(anchorTryAnchor$runtime))) {
                    break;
                } else {
                    i8++;
                }
            }
        }
        arrayList.add(i8, slotWriter.anchor(i7));
    }

    public final void close(int i6) {
        this.closed = true;
        this.dataEndOffset = i6;
    }

    public final void endGrouplessCall(int i6) {
        openInformation().close(i6);
    }

    public final boolean getClosed() {
        return this.closed;
    }

    public final int getDataEndOffset() {
        return this.dataEndOffset;
    }

    public final int getDataStartOffset() {
        return this.dataStartOffset;
    }

    public final ArrayList<Object> getGroups() {
        return this.groups;
    }

    public final int getKey() {
        return this.key;
    }

    public final String getSourceInformation() {
        return this.sourceInformation;
    }

    public final boolean removeAnchor(Anchor anchor) {
        ArrayList<Object> arrayList = this.groups;
        if (arrayList != null) {
            for (int size = arrayList.size() - 1; size >= 0; size--) {
                Object obj = arrayList.get(size);
                if (obj instanceof Anchor) {
                    if (kotlin.jvm.internal.o.c(obj, anchor)) {
                        arrayList.remove(size);
                    }
                } else if ((obj instanceof GroupSourceInformation) && !((GroupSourceInformation) obj).removeAnchor(anchor)) {
                    arrayList.remove(size);
                }
            }
            if (arrayList.isEmpty()) {
                this.groups = null;
                return false;
            }
        }
        return true;
    }

    public final void reportGroup(SlotWriter slotWriter, int i6) {
        openInformation().add(slotWriter.anchor(i6));
    }

    public final void setClosed(boolean z6) {
        this.closed = z6;
    }

    public final void setDataEndOffset(int i6) {
        this.dataEndOffset = i6;
    }

    public final void setGroups(ArrayList<Object> arrayList) {
        this.groups = arrayList;
    }

    public final void setSourceInformation(String str) {
        this.sourceInformation = str;
    }

    public final void startGrouplessCall(int i6, String str, int i7) {
        openInformation().add(new GroupSourceInformation(i6, str, i7));
    }

    public final void reportGroup(SlotTable slotTable, int i6) {
        openInformation().add(slotTable.anchor(i6));
    }
}
