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

import androidx.compose.runtime.MutableState;
import androidx.compose.runtime.SnapshotStateKt__SnapshotStateKt;
import androidx.core.view.MotionEventCompat;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelKt;
import com.sistemasolton.itranvias.home.data.remote.dto.infodto.InfoDto;
import com.sistemasolton.itranvias.home.domain.usecase.ClearStopHistoryUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.GetInfoUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.SaveInfoLocalUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.linesfavorites.DeleteAllFavoriteLinesUseCase;
import com.sistemasolton.itranvias.home.domain.usecase.stopfavorites.DeleteAllStopsFavoriteUseCase;
import kotlin.Metadata;
import kotlin.ResultKt;
import kotlin.Unit;
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.internal.Intrinsics;
import kotlinx.coroutines.BuildersKt__Builders_commonKt;
import kotlinx.coroutines.CoroutineScope;

/* JADX INFO: compiled from: UtilsViewModel.kt */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000@\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\u0005\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0010\u0002\n\u0002\b\u0004\n\u0002\u0010\u000e\n\u0000\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\u0019\u001a\u00020\u001aJ\u0006\u0010\u001b\u001a\u00020\u001aJ\u0006\u0010\u001c\u001a\u00020\u001aJ\u000e\u0010\u001d\u001a\u00020\u001a2\u0006\u0010\u001e\u001a\u00020\u001fR\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\u0011\u0010\n\u001a\u00020\u000b¢\u0006\b\n\u0000\u001a\u0004\b\u000e\u0010\u000fR+\u0010\u0012\u001a\u00020\u00112\u0006\u0010\u0010\u001a\u00020\u00118F@BX\u0086\u008e\u0002¢\u0006\u0012\n\u0004\b\u0017\u0010\u0018\u001a\u0004\b\u0013\u0010\u0014\"\u0004\b\u0015\u0010\u0016¨\u0006 "}, d2 = {"Lcom/sistemasolton/itranvias/home/presentation/utils/UtilsViewModel;", "Landroidx/lifecycle/ViewModel;", "clearStopHistoryUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/ClearStopHistoryUseCase;", "deleteAllFavoriteLinesUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/linesfavorites/DeleteAllFavoriteLinesUseCase;", "deleteAllStopsFavoriteUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/DeleteAllStopsFavoriteUseCase;", "getInfoUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/GetInfoUseCase;", "saveLocalInfo", "Lcom/sistemasolton/itranvias/home/domain/usecase/SaveInfoLocalUseCase;", "<init>", "(Lcom/sistemasolton/itranvias/home/domain/usecase/ClearStopHistoryUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/linesfavorites/DeleteAllFavoriteLinesUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/stopfavorites/DeleteAllStopsFavoriteUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/GetInfoUseCase;Lcom/sistemasolton/itranvias/home/domain/usecase/SaveInfoLocalUseCase;)V", "getSaveLocalInfo", "()Lcom/sistemasolton/itranvias/home/domain/usecase/SaveInfoLocalUseCase;", "<set-?>", "Lcom/sistemasolton/itranvias/home/presentation/utils/UtilsState;", "state", "getState", "()Lcom/sistemasolton/itranvias/home/presentation/utils/UtilsState;", "setState", "(Lcom/sistemasolton/itranvias/home/presentation/utils/UtilsState;)V", "state$delegate", "Landroidx/compose/runtime/MutableState;", "deleteAllFavoriteLines", "", "deleteAllFavoriteStops", "clearStopHistory", "onLanguageChanged", "language", "", "composeApp_release"}, k = 1, mv = {2, 1, 0}, xi = 48)
public final class UtilsViewModel extends ViewModel {
    public static final int $stable = 8;
    private final ClearStopHistoryUseCase clearStopHistoryUseCase;
    private final DeleteAllFavoriteLinesUseCase deleteAllFavoriteLinesUseCase;
    private final DeleteAllStopsFavoriteUseCase deleteAllStopsFavoriteUseCase;
    private final GetInfoUseCase getInfoUseCase;
    private final SaveInfoLocalUseCase saveLocalInfo;

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

    public final SaveInfoLocalUseCase getSaveLocalInfo() {
        return this.saveLocalInfo;
    }

    public UtilsViewModel(ClearStopHistoryUseCase clearStopHistoryUseCase, DeleteAllFavoriteLinesUseCase deleteAllFavoriteLinesUseCase, DeleteAllStopsFavoriteUseCase deleteAllStopsFavoriteUseCase, GetInfoUseCase getInfoUseCase, SaveInfoLocalUseCase saveLocalInfo) {
        Intrinsics.checkNotNullParameter(clearStopHistoryUseCase, "clearStopHistoryUseCase");
        Intrinsics.checkNotNullParameter(deleteAllFavoriteLinesUseCase, "deleteAllFavoriteLinesUseCase");
        Intrinsics.checkNotNullParameter(deleteAllStopsFavoriteUseCase, "deleteAllStopsFavoriteUseCase");
        Intrinsics.checkNotNullParameter(getInfoUseCase, "getInfoUseCase");
        Intrinsics.checkNotNullParameter(saveLocalInfo, "saveLocalInfo");
        this.clearStopHistoryUseCase = clearStopHistoryUseCase;
        this.deleteAllFavoriteLinesUseCase = deleteAllFavoriteLinesUseCase;
        this.deleteAllStopsFavoriteUseCase = deleteAllStopsFavoriteUseCase;
        this.getInfoUseCase = getInfoUseCase;
        this.saveLocalInfo = saveLocalInfo;
        this.state = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(new UtilsState(false, false, null, null, false, 31, null), null, 2, null);
    }

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

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

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.utils.UtilsViewModel$deleteAllFavoriteLines$1, reason: invalid class name and case insensitive filesystem */
    /* JADX INFO: compiled from: UtilsViewModel.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.utils.UtilsViewModel$deleteAllFavoriteLines$1", f = "UtilsViewModel.kt", i = {}, l = {29}, m = "invokeSuspend", n = {}, s = {})
    static final class C06561 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        int label;

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

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

        @Override // kotlin.jvm.functions.Function2
        public final Object invoke(CoroutineScope coroutineScope, Continuation<? super Unit> continuation) {
            return ((C06561) 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 (UtilsViewModel.this.deleteAllFavoriteLinesUseCase.invoke(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 deleteAllFavoriteLines() {
        BuildersKt__Builders_commonKt.launch$default(ViewModelKt.getViewModelScope(this), null, null, new C06561(null), 3, null);
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.utils.UtilsViewModel$deleteAllFavoriteStops$1, reason: invalid class name and case insensitive filesystem */
    /* JADX INFO: compiled from: UtilsViewModel.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.utils.UtilsViewModel$deleteAllFavoriteStops$1", f = "UtilsViewModel.kt", i = {}, l = {MotionEventCompat.AXIS_GENERIC_4}, m = "invokeSuspend", n = {}, s = {})
    static final class C06571 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        int label;

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

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

        @Override // kotlin.jvm.functions.Function2
        public final Object invoke(CoroutineScope coroutineScope, Continuation<? super Unit> continuation) {
            return ((C06571) 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 (UtilsViewModel.this.deleteAllStopsFavoriteUseCase.invoke(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 deleteAllFavoriteStops() {
        BuildersKt__Builders_commonKt.launch$default(ViewModelKt.getViewModelScope(this), null, null, new C06571(null), 3, null);
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.utils.UtilsViewModel$clearStopHistory$1, reason: invalid class name */
    /* JADX INFO: compiled from: UtilsViewModel.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.utils.UtilsViewModel$clearStopHistory$1", f = "UtilsViewModel.kt", i = {}, l = {40}, 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 UtilsViewModel.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);
                this.label = 1;
                if (UtilsViewModel.this.clearStopHistoryUseCase.invoke(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 clearStopHistory() {
        BuildersKt__Builders_commonKt.launch$default(ViewModelKt.getViewModelScope(this), null, null, new AnonymousClass1(null), 3, null);
    }

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.utils.UtilsViewModel$onLanguageChanged$1, reason: invalid class name and case insensitive filesystem */
    /* JADX INFO: compiled from: UtilsViewModel.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.utils.UtilsViewModel$onLanguageChanged$1", f = "UtilsViewModel.kt", i = {}, l = {50, 53}, m = "invokeSuspend", n = {}, s = {})
    static final class C06581 extends SuspendLambda implements Function2<CoroutineScope, Continuation<? super Unit>, Object> {
        final /* synthetic */ String $language;
        int label;

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

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

        @Override // kotlin.jvm.functions.Function2
        public final Object invoke(CoroutineScope coroutineScope, Continuation<? super Unit> continuation) {
            return ((C06581) 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;
            try {
                try {
                } catch (Exception e) {
                    System.out.println((Object) ("Error al actualizar info: " + e.getMessage()));
                }
                if (i == 0) {
                    ResultKt.throwOnFailure(obj);
                    UtilsViewModel utilsViewModel = UtilsViewModel.this;
                    utilsViewModel.setState(UtilsState.copy$default(utilsViewModel.getState(), false, false, null, null, true, 15, null));
                    this.label = 1;
                    obj = UtilsViewModel.this.getInfoUseCase.invoke(this.$language, this);
                    if (obj == coroutine_suspended) {
                        return coroutine_suspended;
                    }
                } else {
                    if (i != 1) {
                        if (i != 2) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        ResultKt.throwOnFailure(obj);
                        System.out.println((Object) ("Info actualizada y guardada en local para idioma " + this.$language));
                        UtilsViewModel utilsViewModel2 = UtilsViewModel.this;
                        utilsViewModel2.setState(UtilsState.copy$default(utilsViewModel2.getState(), false, false, null, null, false, 15, null));
                        return Unit.INSTANCE;
                    }
                    ResultKt.throwOnFailure(obj);
                }
                SaveInfoLocalUseCase saveLocalInfo = UtilsViewModel.this.getSaveLocalInfo();
                this.label = 2;
                if (saveLocalInfo.invoke((InfoDto) obj, this) == coroutine_suspended) {
                    return coroutine_suspended;
                }
                System.out.println((Object) ("Info actualizada y guardada en local para idioma " + this.$language));
                UtilsViewModel utilsViewModel22 = UtilsViewModel.this;
                utilsViewModel22.setState(UtilsState.copy$default(utilsViewModel22.getState(), false, false, null, null, false, 15, null));
                return Unit.INSTANCE;
            } catch (Throwable th) {
                UtilsViewModel utilsViewModel3 = UtilsViewModel.this;
                utilsViewModel3.setState(UtilsState.copy$default(utilsViewModel3.getState(), false, false, null, null, false, 15, null));
                throw th;
            }
        }
    }

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