package com.sistemasolton.itranvias.home.presentation.favorites;

import androidx.compose.runtime.MutableState;
import androidx.compose.runtime.SnapshotStateKt__SnapshotStateKt;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelKt;
import com.sistemasolton.itranvias.home.data.local.entity.LineFavoriteEntity;
import com.sistemasolton.itranvias.home.data.local.entity.StopFavoriteEntity;
import com.sistemasolton.itranvias.home.data.remote.dto.infodto.InfoDto;
import com.sistemasolton.itranvias.home.domain.usecase.AddStopToHistoryUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.GetInfoLocalUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.linesfavorites.GetAllStopsFavoriteUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.stopfavorites.GetAllLinesFavoriteUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.stopfavorites.UpdateStopAliasUseCase;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import kotlin.Metadata;
import kotlin.ResultKt;
import kotlin.Triple;
import kotlin.Unit;
import kotlin.collections.CollectionsKt;
import kotlin.comparisons.ComparisonsKt;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.IntrinsicsKt;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.functions.Function3;
import kotlin.jvm.functions.Function4;
import kotlin.jvm.internal.Intrinsics;
import kotlinx.coroutines.BuildersKt__Builders_commonKt;
import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.flow.FlowCollector;
import kotlinx.coroutines.flow.FlowKt;

/* JADX INFO: compiled from: FavoritesViewModel.kt */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000B\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0004\b\u0007\u0018\u00002\u00020\u0001B/\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007\u0012\u0006\u0010\b\u001a\u00020\t\u0012\u0006\u0010\n\u001a\u00020\u000b¢\u0006\u0004\b\f\u0010\rJ\u0006\u0010\u0017\u001a\u00020\u0018J\u0018\u0010\u0019\u001a\u00020\u00182\u0006\u0010\u001a\u001a\u00020\u001b2\b\u0010\u001c\u001a\u0004\u0018\u00010\u001bJ\u000e\u0010\u001d\u001a\u00020\u00182\u0006\u0010\u001e\u001a\u00020\u001bR\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0007X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\u000bX\u0082\u0004¢\u0006\u0002\n\u0000R+\u0010\u0010\u001a\u00020\u000f2\u0006\u0010\u000e\u001a\u00020\u000f8F@BX\u0086\u008e\u0002¢\u0006\u0012\n\u0004\b\u0015\u0010\u0016\u001a\u0004\b\u0011\u0010\u0012\"\u0004\b\u0013\u0010\u0014¨\u0006\u001f"}, d2 = {"Lcom/sistemasolton/itranvias/home/presentation/favorites/FavoritesViewModel;", "Landroidx/lifecycle/ViewModel;", "addStopToHistoryUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/AddStopToHistoryUseCase;", "updateStopAliasUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/UpdateStopAliasUseCase;", "getLocalInfoUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/GetInfoLocalUseCase;", "getAllStopsFavoriteUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/linesfavorites/GetAllStopsFavoriteUseCase;", "getAllLinesFavoriteUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/GetAllLinesFavoriteUseCase;", "<init>", "(Lcom/sistemasolton/itranvias/home/domain/usecase/AddStopToHistoryUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/UpdateStopAliasUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/GetInfoLocalUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/linesfavorites/GetAllStopsFavoriteUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/GetAllLinesFavoriteUseCase;)V", "<set-?>", "Lcom/sistemasolton/itranvias/home/presentation/favorites/FavoritesState;", "state", "getState", "()Lcom/sistemasolton/itranvias/home/presentation/favorites/FavoritesState;", "setState", "(Lcom/sistemasolton/itranvias/home/presentation/favorites/FavoritesState;)V", "state$delegate", "Landroidx/compose/runtime/MutableState;", "loadFavorites", "", "updateStopAlias", "stopCode", "", "alias", "onStopClicked", "stopId", "composeApp_release"}, k = 1, mv = {2, 1, 0}, xi = 48)
public final class FavoritesViewModel extends ViewModel {
    public static final int $stable = 8;
    private final AddStopToHistoryUseCase addStopToHistoryUseCase;
    private final GetAllLinesFavoriteUseCase getAllLinesFavoriteUseCase;
    private final GetAllStopsFavoriteUseCase getAllStopsFavoriteUseCase;
    private final GetInfoLocalUseCase getLocalInfoUseCase;

    /* JADX INFO: renamed from: state$delegate, reason: from kotlin metadata */
    private final MutableState state;
    private final UpdateStopAliasUseCase updateStopAliasUseCase;

    public FavoritesViewModel(AddStopToHistoryUseCase addStopToHistoryUseCase, UpdateStopAliasUseCase updateStopAliasUseCase, GetInfoLocalUseCase getLocalInfoUseCase, GetAllStopsFavoriteUseCase getAllStopsFavoriteUseCase, GetAllLinesFavoriteUseCase getAllLinesFavoriteUseCase) {
        Intrinsics.checkNotNullParameter(addStopToHistoryUseCase, "addStopToHistoryUseCase");
        Intrinsics.checkNotNullParameter(updateStopAliasUseCase, "updateStopAliasUseCase");
        Intrinsics.checkNotNullParameter(getLocalInfoUseCase, "getLocalInfoUseCase");
        Intrinsics.checkNotNullParameter(getAllStopsFavoriteUseCase, "getAllStopsFavoriteUseCase");
        Intrinsics.checkNotNullParameter(getAllLinesFavoriteUseCase, "getAllLinesFavoriteUseCase");
        this.addStopToHistoryUseCase = addStopToHistoryUseCase;
        this.updateStopAliasUseCase = updateStopAliasUseCase;
        this.getLocalInfoUseCase = getLocalInfoUseCase;
        this.getAllStopsFavoriteUseCase = getAllStopsFavoriteUseCase;
        this.getAllLinesFavoriteUseCase = getAllLinesFavoriteUseCase;
        this.state = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(new FavoritesState(false, false, null, null, null, null, 63, null), null, 2, null);
        loadFavorites();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void setState(FavoritesState favoritesState) {
        this.state.setValue(favoritesState);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final FavoritesState getState() {
        return (FavoritesState) this.state.getValue();
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$loadFavorites$1, reason: invalid class name */
    /* JADX INFO: compiled from: FavoritesViewModel.kt */
    @Metadata(d1 = {"\u0000\n\n\u0000\n\u0002\u0010\u0002\n\u0002\u0018\u0002\u0010\u0000\u001a\u00020\u0001*\u00020\u0002H\n"}, d2 = {"<anonymous>", "", "Lkotlinx/coroutines/CoroutineScope;"}, k = 3, mv = {2, 1, 0}, xi = 48)
    @DebugMetadata(c = "com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$loadFavorites$1", f = "FavoritesViewModel.kt", i = {}, l = {55}, m = "invokeSuspend", n = {}, s = {})
    static final class AnonymousClass1 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        int label;

        AnonymousClass1(Continuation<? super AnonymousClass1> continuation) {
            super(2, continuation);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<Unit> create(Object obj, Continuation<?> continuation) {
            return FavoritesViewModel.this.new AnonymousClass1(continuation);
        }

        @Override // kotlin.jvm.functions.Function2
        public final Object invoke(CoroutineScope coroutineScope, Continuation<? super Unit> continuation) {
            return ((AnonymousClass1) create(coroutineScope, continuation)).invokeSuspend(Unit.INSTANCE);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) throws Throwable {
            Object coroutine_suspended = IntrinsicsKt.getCOROUTINE_SUSPENDED();
            int i = this.label;
            if (i == 0) {
                ResultKt.throwOnFailure(obj);
                FavoritesViewModel favoritesViewModel = FavoritesViewModel.this;
                favoritesViewModel.setState(FavoritesState.copy$default(favoritesViewModel.getState(), true, false, null, null, null, null, 56, null));
                this.label = 1;
                if (FlowKt.collectLatest(FlowKt.m9919catch(FlowKt.combine(FavoritesViewModel.this.getLocalInfoUseCase.invoke(), FavoritesViewModel.this.getAllStopsFavoriteUseCase.invoke(), FavoritesViewModel.this.getAllLinesFavoriteUseCase.invoke(), new C01121(null)), new AnonymousClass2(FavoritesViewModel.this, null)), new AnonymousClass3(FavoritesViewModel.this, null), this) == coroutine_suspended) {
                    return coroutine_suspended;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                ResultKt.throwOnFailure(obj);
            }
            return Unit.INSTANCE;
        }

        /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$loadFavorites$1$1, reason: invalid class name and collision with other inner class name */
        /* JADX INFO: compiled from: FavoritesViewModel.kt */
        @Metadata(d1 = {"\u0000\u001a\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\u0010\u0000\u001a\"\u0012\u0006\u0012\u0004\u0018\u00010\u0002\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00040\u0003\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00050\u00030\u00012\b\u0010\u0006\u001a\u0004\u0018\u00010\u00022\f\u0010\u0007\u001a\b\u0012\u0004\u0012\u00020\u00040\u00032\f\u0010\b\u001a\b\u0012\u0004\u0012\u00020\u00050\u0003H\n"}, d2 = {"<anonymous>", "Lkotlin/Triple;", "Lcom/sistemasolton/itranvias/home/data/remote/dto/infodto/InfoDto;", "", "Lcom/sistemasolton/itranvias/home/data/local/entity/StopFavoriteEntity;", "Lcom/sistemasolton/itranvias/home/data/local/entity/LineFavoriteEntity;", "infoDto", "stopsFavorites", "linesFavorites"}, k = 3, mv = {2, 1, 0}, xi = 48)
        @DebugMetadata(c = "com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$loadFavorites$1$1", f = "FavoritesViewModel.kt", i = {}, l = {}, m = "invokeSuspend", n = {}, s = {})
        static final class C01121 extends SuspendLambda implements Function4<InfoDto, List<? extends StopFavoriteEntity>, List<? extends LineFavoriteEntity>, Continuation<? super Triple<? extends InfoDto, ? extends List<? extends StopFavoriteEntity>, ? extends List<? extends LineFavoriteEntity>>>, Object> {
            /* synthetic */ Object L$0;
            /* synthetic */ Object L$1;
            /* synthetic */ Object L$2;
            int label;

            C01121(Continuation<? super C01121> continuation) {
                super(4, continuation);
            }

            /* JADX INFO: renamed from: invoke, reason: avoid collision after fix types in other method */
            public final Object invoke2(InfoDto infoDto, List<StopFavoriteEntity> list, List<LineFavoriteEntity> list2, Continuation<? super Triple<InfoDto, ? extends List<StopFavoriteEntity>, ? extends List<LineFavoriteEntity>>> continuation) {
                C01121 c01121 = new C01121(continuation);
                c01121.L$0 = infoDto;
                c01121.L$1 = list;
                c01121.L$2 = list2;
                return c01121.invokeSuspend(Unit.INSTANCE);
            }

            @Override // kotlin.jvm.functions.Function4
            public /* bridge */ /* synthetic */ Object invoke(InfoDto infoDto, List<? extends StopFavoriteEntity> list, List<? extends LineFavoriteEntity> list2, Continuation<? super Triple<? extends InfoDto, ? extends List<? extends StopFavoriteEntity>, ? extends List<? extends LineFavoriteEntity>>> continuation) {
                return invoke2(infoDto, (List<StopFavoriteEntity>) list, (List<LineFavoriteEntity>) list2, (Continuation<? super Triple<InfoDto, ? extends List<StopFavoriteEntity>, ? extends List<LineFavoriteEntity>>>) continuation);
            }

            @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
            public final Object invokeSuspend(Object obj) throws Throwable {
                IntrinsicsKt.getCOROUTINE_SUSPENDED();
                if (this.label != 0) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                ResultKt.throwOnFailure(obj);
                return new Triple((InfoDto) this.L$0, (List) this.L$1, (List) this.L$2);
            }
        }

        /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$loadFavorites$1$2, reason: invalid class name */
        /* JADX INFO: compiled from: FavoritesViewModel.kt */
        @Metadata(d1 = {"\u0000$\n\u0000\n\u0002\u0010\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0003\u0010\u0000\u001a\u00020\u0001*(\u0012$\u0012\"\u0012\u0006\u0012\u0004\u0018\u00010\u0004\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00060\u0005\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00070\u00050\u00030\u00022\u0006\u0010\b\u001a\u00020\tH\n"}, d2 = {"<anonymous>", "", "Lkotlinx/coroutines/flow/FlowCollector;", "Lkotlin/Triple;", "Lcom/sistemasolton/itranvias/home/data/remote/dto/infodto/InfoDto;", "", "Lcom/sistemasolton/itranvias/home/data/local/entity/StopFavoriteEntity;", "Lcom/sistemasolton/itranvias/home/data/local/entity/LineFavoriteEntity;", "e", ""}, k = 3, mv = {2, 1, 0}, xi = 48)
        @DebugMetadata(c = "com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$loadFavorites$1$2", f = "FavoritesViewModel.kt", i = {}, l = {}, m = "invokeSuspend", n = {}, s = {})
        static final class AnonymousClass2 extends SuspendLambda implements Function3<FlowCollector<? super Triple<? extends InfoDto, ? extends List<? extends StopFavoriteEntity>, ? extends List<? extends LineFavoriteEntity>>>, Throwable, Continuation<? super Unit>, Object> {
            /* synthetic */ Object L$0;
            int label;
            final /* synthetic */ FavoritesViewModel this$0;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            AnonymousClass2(FavoritesViewModel favoritesViewModel, Continuation<? super AnonymousClass2> continuation) {
                super(3, continuation);
                this.this$0 = favoritesViewModel;
            }

            @Override // kotlin.jvm.functions.Function3
            public /* bridge */ /* synthetic */ Object invoke(FlowCollector<? super Triple<? extends InfoDto, ? extends List<? extends StopFavoriteEntity>, ? extends List<? extends LineFavoriteEntity>>> flowCollector, Throwable th, Continuation<? super Unit> continuation) {
                return invoke2((FlowCollector<? super Triple<InfoDto, ? extends List<StopFavoriteEntity>, ? extends List<LineFavoriteEntity>>>) flowCollector, th, continuation);
            }

            /* JADX INFO: renamed from: invoke, reason: avoid collision after fix types in other method */
            public final Object invoke2(FlowCollector<? super Triple<InfoDto, ? extends List<StopFavoriteEntity>, ? extends List<LineFavoriteEntity>>> flowCollector, Throwable th, Continuation<? super Unit> continuation) {
                AnonymousClass2 anonymousClass2 = new AnonymousClass2(this.this$0, continuation);
                anonymousClass2.L$0 = th;
                return anonymousClass2.invokeSuspend(Unit.INSTANCE);
            }

            @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
            public final Object invokeSuspend(Object obj) throws Throwable {
                IntrinsicsKt.getCOROUTINE_SUSPENDED();
                if (this.label != 0) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                ResultKt.throwOnFailure(obj);
                Throwable th = (Throwable) this.L$0;
                FavoritesViewModel favoritesViewModel = this.this$0;
                FavoritesState state = favoritesViewModel.getState();
                String message = th.getMessage();
                if (message == null) {
                    message = "Error desconocido";
                }
                favoritesViewModel.setState(FavoritesState.copy$default(state, false, true, message, null, null, null, 56, null));
                return Unit.INSTANCE;
            }
        }

        /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$loadFavorites$1$3, reason: invalid class name */
        /* JADX INFO: compiled from: FavoritesViewModel.kt */
        @Metadata(d1 = {"\u0000\u001c\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\u0018\u0002\u0010\u0000\u001a\u00020\u00012&\u0010\u0002\u001a\"\u0012\u0006\u0012\u0004\u0018\u00010\u0004\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00060\u0005\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00070\u00050\u0003H\n"}, d2 = {"<anonymous>", "", "<destruct>", "Lkotlin/Triple;", "Lcom/sistemasolton/itranvias/home/data/remote/dto/infodto/InfoDto;", "", "Lcom/sistemasolton/itranvias/home/data/local/entity/StopFavoriteEntity;", "Lcom/sistemasolton/itranvias/home/data/local/entity/LineFavoriteEntity;"}, k = 3, mv = {2, 1, 0}, xi = 48)
        @DebugMetadata(c = "com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$loadFavorites$1$3", f = "FavoritesViewModel.kt", i = {}, l = {}, m = "invokeSuspend", n = {}, s = {})
        static final class AnonymousClass3 extends SuspendLambda implements Function2<Triple<? extends InfoDto, ? extends List<? extends StopFavoriteEntity>, ? extends List<? extends LineFavoriteEntity>>, Continuation<? super Unit>, Object> {
            /* synthetic */ Object L$0;
            int label;
            final /* synthetic */ FavoritesViewModel this$0;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            AnonymousClass3(FavoritesViewModel favoritesViewModel, Continuation<? super AnonymousClass3> continuation) {
                super(2, continuation);
                this.this$0 = favoritesViewModel;
            }

            @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
            public final Continuation<Unit> create(Object obj, Continuation<?> continuation) {
                AnonymousClass3 anonymousClass3 = new AnonymousClass3(this.this$0, continuation);
                anonymousClass3.L$0 = obj;
                return anonymousClass3;
            }

            @Override // kotlin.jvm.functions.Function2
            public /* bridge */ /* synthetic */ Object invoke(Triple<? extends InfoDto, ? extends List<? extends StopFavoriteEntity>, ? extends List<? extends LineFavoriteEntity>> triple, Continuation<? super Unit> continuation) {
                return invoke2((Triple<InfoDto, ? extends List<StopFavoriteEntity>, ? extends List<LineFavoriteEntity>>) triple, continuation);
            }

            /* JADX INFO: renamed from: invoke, reason: avoid collision after fix types in other method */
            public final Object invoke2(Triple<InfoDto, ? extends List<StopFavoriteEntity>, ? extends List<LineFavoriteEntity>> triple, Continuation<? super Unit> continuation) {
                return ((AnonymousClass3) create(triple, continuation)).invokeSuspend(Unit.INSTANCE);
            }

            @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
            public final Object invokeSuspend(Object obj) throws Throwable {
                IntrinsicsKt.getCOROUTINE_SUSPENDED();
                if (this.label != 0) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                ResultKt.throwOnFailure(obj);
                Triple triple = (Triple) this.L$0;
                InfoDto infoDto = (InfoDto) triple.component1();
                List list = (List) triple.component2();
                List list2 = (List) triple.component3();
                List<StopFavoriteEntity> stopsFavorites = this.this$0.getState().getStopsFavorites();
                ArrayList arrayList = new ArrayList(CollectionsKt.collectionSizeOrDefault(stopsFavorites, 10));
                Iterator<T> it = stopsFavorites.iterator();
                while (it.hasNext()) {
                    arrayList.add(((StopFavoriteEntity) it.next()).getStopCode());
                }
                final ArrayList arrayList2 = arrayList;
                List listSortedWith = CollectionsKt.sortedWith(list, new Comparator() { // from class: com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$loadFavorites$1$3$invokeSuspend$$inlined$compareBy$1
                    /* JADX WARN: Multi-variable type inference failed */
                    @Override // java.util.Comparator
                    public final int compare(T t, T t2) {
                        return ComparisonsKt.compareValues(Integer.valueOf(arrayList2.indexOf(((StopFavoriteEntity) t).getStopCode())), Integer.valueOf(arrayList2.indexOf(((StopFavoriteEntity) t2).getStopCode())));
                    }
                });
                FavoritesViewModel favoritesViewModel = this.this$0;
                FavoritesState state = favoritesViewModel.getState();
                List list3 = list2;
                ArrayList arrayList3 = new ArrayList(CollectionsKt.collectionSizeOrDefault(list3, 10));
                Iterator it2 = list3.iterator();
                while (it2.hasNext()) {
                    arrayList3.add(((LineFavoriteEntity) it2.next()).getLineCode());
                }
                favoritesViewModel.setState(FavoritesState.copy$default(state, false, false, null, infoDto, listSortedWith, arrayList3, 4, null));
                return Unit.INSTANCE;
            }
        }
    }

    public final void loadFavorites() {
        BuildersKt__Builders_commonKt.launch$default(ViewModelKt.getViewModelScope(this), null, null, new AnonymousClass1(null), 3, null);
    }

    public final void updateStopAlias(String stopCode, String alias) {
        Intrinsics.checkNotNullParameter(stopCode, "stopCode");
        FavoritesState state = getState();
        List<StopFavoriteEntity> stopsFavorites = getState().getStopsFavorites();
        ArrayList arrayList = new ArrayList(CollectionsKt.collectionSizeOrDefault(stopsFavorites, 10));
        for (StopFavoriteEntity stopFavoriteEntityCopy$default : stopsFavorites) {
            if (Intrinsics.areEqual(stopFavoriteEntityCopy$default.getStopCode(), stopCode)) {
                stopFavoriteEntityCopy$default = StopFavoriteEntity.copy$default(stopFavoriteEntityCopy$default, null, alias, 1, null);
            }
            arrayList.add(stopFavoriteEntityCopy$default);
        }
        setState(FavoritesState.copy$default(state, false, false, null, null, arrayList, null, 47, null));
        BuildersKt__Builders_commonKt.launch$default(ViewModelKt.getViewModelScope(this), null, null, new AnonymousClass2(stopCode, alias, null), 3, null);
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$updateStopAlias$2, reason: invalid class name */
    /* JADX INFO: compiled from: FavoritesViewModel.kt */
    @Metadata(d1 = {"\u0000\n\n\u0000\n\u0002\u0010\u0002\n\u0002\u0018\u0002\u0010\u0000\u001a\u00020\u0001*\u00020\u0002H\n"}, d2 = {"<anonymous>", "", "Lkotlinx/coroutines/CoroutineScope;"}, k = 3, mv = {2, 1, 0}, xi = 48)
    @DebugMetadata(c = "com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$updateStopAlias$2", f = "FavoritesViewModel.kt", i = {}, l = {78}, m = "invokeSuspend", n = {}, s = {})
    static final class AnonymousClass2 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        final /* synthetic */ String $alias;
        final /* synthetic */ String $stopCode;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        AnonymousClass2(String str, String str2, Continuation<? super AnonymousClass2> continuation) {
            super(2, continuation);
            this.$stopCode = str;
            this.$alias = str2;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<Unit> create(Object obj, Continuation<?> continuation) {
            return FavoritesViewModel.this.new AnonymousClass2(this.$stopCode, this.$alias, continuation);
        }

        @Override // kotlin.jvm.functions.Function2
        public final Object invoke(CoroutineScope coroutineScope, Continuation<? super Unit> continuation) {
            return ((AnonymousClass2) create(coroutineScope, continuation)).invokeSuspend(Unit.INSTANCE);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) throws Throwable {
            Object coroutine_suspended = IntrinsicsKt.getCOROUTINE_SUSPENDED();
            int i = this.label;
            if (i == 0) {
                ResultKt.throwOnFailure(obj);
                this.label = 1;
                if (FavoritesViewModel.this.updateStopAliasUseCase.invoke(this.$stopCode, this.$alias, this) == coroutine_suspended) {
                    return coroutine_suspended;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                ResultKt.throwOnFailure(obj);
            }
            return Unit.INSTANCE;
        }
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$onStopClicked$1, reason: invalid class name and case insensitive filesystem */
    /* JADX INFO: compiled from: FavoritesViewModel.kt */
    @Metadata(d1 = {"\u0000\n\n\u0000\n\u0002\u0010\u0002\n\u0002\u0018\u0002\u0010\u0000\u001a\u00020\u0001*\u00020\u0002H\n"}, d2 = {"<anonymous>", "", "Lkotlinx/coroutines/CoroutineScope;"}, k = 3, mv = {2, 1, 0}, xi = 48)
    @DebugMetadata(c = "com.sistemasolton.itranvias.home.presentation.favorites.FavoritesViewModel$onStopClicked$1", f = "FavoritesViewModel.kt", i = {}, l = {84}, m = "invokeSuspend", n = {}, s = {})
    static final class C06431 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        final /* synthetic */ String $stopId;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        C06431(String str, Continuation<? super C06431> continuation) {
            super(2, continuation);
            this.$stopId = str;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation<Unit> create(Object obj, Continuation<?> continuation) {
            return FavoritesViewModel.this.new C06431(this.$stopId, continuation);
        }

        @Override // kotlin.jvm.functions.Function2
        public final Object invoke(CoroutineScope coroutineScope, Continuation<? super Unit> continuation) {
            return ((C06431) create(coroutineScope, continuation)).invokeSuspend(Unit.INSTANCE);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) throws Throwable {
            Object coroutine_suspended = IntrinsicsKt.getCOROUTINE_SUSPENDED();
            int i = this.label;
            if (i == 0) {
                ResultKt.throwOnFailure(obj);
                this.label = 1;
                if (FavoritesViewModel.this.addStopToHistoryUseCase.invoke(this.$stopId, this) == coroutine_suspended) {
                    return coroutine_suspended;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                ResultKt.throwOnFailure(obj);
            }
            return Unit.INSTANCE;
        }
    }

    public final void onStopClicked(String stopId) {
        Intrinsics.checkNotNullParameter(stopId, "stopId");
        BuildersKt__Builders_commonKt.launch$default(ViewModelKt.getViewModelScope(this), null, null, new C06431(stopId, null), 3, null);
    }
}