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

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.remote.dto.infodto.InfoDto;
import com.sistemasolton.itranvias.home.domain.usecase.RefreshInfoUseCase;
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: HomeViewModel.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\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0010\u0002\n\u0000\b\u0007\u0018\u00002\u00020\u0001B\u000f\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0004\b\u0004\u0010\u0005J\u0006\u0010\u000f\u001a\u00020\u0010R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R+\u0010\b\u001a\u00020\u00072\u0006\u0010\u0006\u001a\u00020\u00078F@BX\u0086\u008e\u0002¢\u0006\u0012\n\u0004\b\r\u0010\u000e\u001a\u0004\b\t\u0010\n\"\u0004\b\u000b\u0010\f¨\u0006\u0011"}, d2 = {"Lcom/sistemasolton/itranvias/home/presentation/home/HomeViewModel;", "Landroidx/lifecycle/ViewModel;", "refreshInfoUseCase", "Lcom/sistemasolton/itranvias/home/domain/usecase/RefreshInfoUseCase;", "<init>", "(Lcom/sistemasolton/itranvias/home/domain/usecase/RefreshInfoUseCase;)V", "<set-?>", "Lcom/sistemasolton/itranvias/home/presentation/home/HomeState;", "state", "getState", "()Lcom/sistemasolton/itranvias/home/presentation/home/HomeState;", "setState", "(Lcom/sistemasolton/itranvias/home/presentation/home/HomeState;)V", "state$delegate", "Landroidx/compose/runtime/MutableState;", "loadInfo", "", "composeApp_release"}, k = 1, mv = {2, 1, 0}, xi = 48)
public final class HomeViewModel extends ViewModel {
    public static final int $stable = 8;
    private final RefreshInfoUseCase refreshInfoUseCase;

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

    public HomeViewModel(RefreshInfoUseCase refreshInfoUseCase) {
        Intrinsics.checkNotNullParameter(refreshInfoUseCase, "refreshInfoUseCase");
        this.refreshInfoUseCase = refreshInfoUseCase;
        this.state = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(new HomeState(null, false, null, 7, null), null, 2, null);
        loadInfo();
    }

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

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

    /* JADX INFO: renamed from: com.sistemasolton.itranvias.home.presentation.home.HomeViewModel$loadInfo$1, reason: invalid class name */
    /* JADX INFO: compiled from: HomeViewModel.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.home.HomeViewModel$loadInfo$1", f = "HomeViewModel.kt", i = {}, l = {26}, 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 HomeViewModel.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;
            try {
                if (i == 0) {
                    ResultKt.throwOnFailure(obj);
                    HomeViewModel homeViewModel = HomeViewModel.this;
                    homeViewModel.setState(HomeState.copy$default(homeViewModel.getState(), null, true, null, 1, null));
                    this.label = 1;
                    obj = HomeViewModel.this.refreshInfoUseCase.invoke(this);
                    if (obj == coroutine_suspended) {
                        return coroutine_suspended;
                    }
                } else {
                    if (i != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    ResultKt.throwOnFailure(obj);
                }
                InfoDto infoDto = (InfoDto) obj;
                HomeViewModel homeViewModel2 = HomeViewModel.this;
                homeViewModel2.setState(HomeState.copy$default(homeViewModel2.getState(), infoDto, false, null, 4, null));
            } catch (Exception e) {
                System.out.println((Object) ("HomeViewModel loadInfo error: " + e.getMessage()));
                HomeViewModel homeViewModel3 = HomeViewModel.this;
                homeViewModel3.setState(HomeState.copy$default(homeViewModel3.getState(), null, false, e.getMessage(), 1, null));
            }
            return Unit.INSTANCE;
        }
    }

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