package com.revenuecat.purchases.ui.revenuecatui.customercenter.navigation;

import androidx.compose.runtime.Immutable;
import com.revenuecat.purchases.ui.revenuecatui.customercenter.navigation.CustomerCenterDestination;
import com.revenuecat.purchases.ui.revenuecatui.helpers.Logger;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;
import kotlin.jvm.internal.h;
import kotlin.jvm.internal.o;
import x4.AbstractC3251q;

/* JADX INFO: loaded from: classes3.dex */
@Immutable
public final class CustomerCenterNavigationState {
    public static final int $stable = 0;
    private final Deque<CustomerCenterDestination> backStack;
    private final String managementScreenTitle;
    private final boolean showingActivePurchasesScreen;

    public CustomerCenterNavigationState(boolean z6, String str, Deque<CustomerCenterDestination> backStack) {
        o.h(backStack, "backStack");
        this.showingActivePurchasesScreen = z6;
        this.managementScreenTitle = str;
        this.backStack = backStack;
    }

    private final boolean component1() {
        return this.showingActivePurchasesScreen;
    }

    private final String component2() {
        return this.managementScreenTitle;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static /* synthetic */ CustomerCenterNavigationState copy$default(CustomerCenterNavigationState customerCenterNavigationState, boolean z6, String str, Deque deque, int i6, Object obj) {
        if ((i6 & 1) != 0) {
            z6 = customerCenterNavigationState.showingActivePurchasesScreen;
        }
        if ((i6 & 2) != 0) {
            str = customerCenterNavigationState.managementScreenTitle;
        }
        if ((i6 & 4) != 0) {
            deque = customerCenterNavigationState.backStack;
        }
        return customerCenterNavigationState.copy(z6, str, deque);
    }

    public final Deque<CustomerCenterDestination> component3() {
        return this.backStack;
    }

    public final CustomerCenterNavigationState copy(boolean z6, String str, Deque<CustomerCenterDestination> backStack) {
        o.h(backStack, "backStack");
        return new CustomerCenterNavigationState(z6, str, backStack);
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof CustomerCenterNavigationState)) {
            return false;
        }
        CustomerCenterNavigationState customerCenterNavigationState = (CustomerCenterNavigationState) obj;
        return this.showingActivePurchasesScreen == customerCenterNavigationState.showingActivePurchasesScreen && o.c(this.managementScreenTitle, customerCenterNavigationState.managementScreenTitle) && o.c(this.backStack, customerCenterNavigationState.backStack);
    }

    public final Deque<CustomerCenterDestination> getBackStack() {
        return this.backStack;
    }

    public final boolean getCanNavigateBack() {
        return this.backStack.size() > 1;
    }

    public final CustomerCenterDestination getCurrentDestination() {
        CustomerCenterDestination customerCenterDestinationPeek = this.backStack.peek();
        return customerCenterDestinationPeek == null ? new CustomerCenterDestination.Main(this.showingActivePurchasesScreen, this.managementScreenTitle) : customerCenterDestinationPeek;
    }

    public int hashCode() {
        int iHashCode = Boolean.hashCode(this.showingActivePurchasesScreen) * 31;
        String str = this.managementScreenTitle;
        return this.backStack.hashCode() + ((iHashCode + (str == null ? 0 : str.hashCode())) * 31);
    }

    public final boolean isBackwardTransition(CustomerCenterDestination from, CustomerCenterDestination to) {
        o.h(from, "from");
        o.h(to, "to");
        if ((to instanceof CustomerCenterDestination.Main) && !(from instanceof CustomerCenterDestination.Main)) {
            return true;
        }
        List listC0 = AbstractC3251q.C0(this.backStack);
        int iIndexOf = listC0.indexOf(from);
        int iIndexOf2 = listC0.indexOf(to);
        if (iIndexOf2 != -1 && iIndexOf != -1) {
            return iIndexOf2 > iIndexOf;
        }
        Logger.INSTANCE.e("One of the destinations (" + from + " [" + iIndexOf + "], " + to + " [" + iIndexOf2 + "]) is not in the back stack. Assuming forward transition.");
        return false;
    }

    public final CustomerCenterNavigationState pop() {
        if (!getCanNavigateBack()) {
            return this;
        }
        ArrayDeque arrayDeque = new ArrayDeque(this.backStack);
        arrayDeque.pop();
        return copy$default(this, false, null, arrayDeque, 3, null);
    }

    public final CustomerCenterNavigationState popToMain() {
        ArrayDeque arrayDeque = new ArrayDeque(this.backStack);
        while (!arrayDeque.isEmpty() && !(arrayDeque.peek() instanceof CustomerCenterDestination.Main)) {
            arrayDeque.pop();
        }
        if (!arrayDeque.isEmpty()) {
            return copy$default(this, false, null, arrayDeque, 3, null);
        }
        Logger.INSTANCE.e("Could not find Main destination in the back stack. Returning unchanged state.");
        return this;
    }

    public final CustomerCenterNavigationState push(CustomerCenterDestination destination) {
        o.h(destination, "destination");
        ArrayDeque arrayDeque = new ArrayDeque(this.backStack);
        arrayDeque.push(destination);
        return copy$default(this, false, null, arrayDeque, 3, null);
    }

    public String toString() {
        return "CustomerCenterNavigationState(showingActivePurchasesScreen=" + this.showingActivePurchasesScreen + ", managementScreenTitle=" + this.managementScreenTitle + ", backStack=" + this.backStack + ')';
    }

    public /* synthetic */ CustomerCenterNavigationState(boolean z6, String str, Deque deque, int i6, h hVar) {
        Deque deque2 = deque;
        if ((i6 & 4) != 0) {
            ArrayDeque arrayDeque = new ArrayDeque();
            arrayDeque.push(new CustomerCenterDestination.Main(z6, str));
            deque2 = arrayDeque;
        }
        this(z6, str, deque2);
    }
}
